Skip to content

Commit dd5b6a2

Browse files
authored
Allow compiling and linking to be done on separate platforms (#53)
Because of OS cross compile limitations in mojo (see previous commits), compile actions must be pinned to the target OS. Because the mojo toolchain was set on the top level rule, all resolved toolchains were pinned to the target OS, which meant linking could not be cross compiled. This removes that restriction using exec_groups to free up macOS CPU time when cross compiling.
1 parent 1537051 commit dd5b6a2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mojo/private/mojo_binary_test.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ then be used in copts with the $(location) function.
4444
}
4545

4646
_TOOLCHAINS = use_cpp_toolchain() + [
47-
"//:toolchain_type",
4847
_PYTHON_TOOLCHAIN_TYPE,
4948
]
5049

50+
_EXEC_GROUPS = {
51+
"compile": exec_group(toolchains = ["//:toolchain_type"]),
52+
}
53+
5154
def _find_main(name, srcs, main):
5255
"""Finds the main source file from the list of srcs and the main attribute."""
5356
if main:
@@ -75,7 +78,7 @@ def _find_main(name, srcs, main):
7578

7679
def _mojo_binary_test_implementation(ctx, *, shared_library = False):
7780
cc_toolchain = find_cpp_toolchain(ctx)
78-
mojo_toolchain = ctx.toolchains["//:toolchain_type"].mojo_toolchain_info
81+
mojo_toolchain = ctx.exec_groups["compile"].toolchains["//:toolchain_type"].mojo_toolchain_info
7982
py_toolchain = ctx.toolchains[_PYTHON_TOOLCHAIN_TYPE]
8083

8184
object_file = ctx.actions.declare_file(ctx.label.name + ".lo")
@@ -130,6 +133,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
130133
"TEST_TMPDIR": ".",
131134
},
132135
use_default_shell_env = True,
136+
exec_group = "compile",
133137
toolchain = "//:toolchain_type",
134138
)
135139

@@ -266,6 +270,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
266270
mojo_binary = rule(
267271
implementation = lambda ctx: _mojo_binary_test_implementation(ctx),
268272
attrs = _ATTRS,
273+
exec_groups = _EXEC_GROUPS,
269274
toolchains = _TOOLCHAINS,
270275
fragments = ["cpp"],
271276
executable = True,
@@ -274,6 +279,7 @@ mojo_binary = rule(
274279
mojo_test = rule(
275280
implementation = lambda ctx: _mojo_binary_test_implementation(ctx),
276281
attrs = _ATTRS,
282+
exec_groups = _EXEC_GROUPS,
277283
toolchains = _TOOLCHAINS,
278284
fragments = ["cpp"],
279285
test = True,
@@ -287,6 +293,7 @@ mojo_shared_library = rule(
287293
doc = "The name of the shared library to be created.",
288294
),
289295
},
296+
exec_groups = _EXEC_GROUPS,
290297
toolchains = _TOOLCHAINS,
291298
fragments = ["cpp"],
292299
)

0 commit comments

Comments
 (0)