Skip to content

Commit 9a6a240

Browse files
Ahajhakeith
andauthored
Make mojo_binary / mojo_test compile action support path mapping (#95)
Continuing from #37, testing + working on compiler changes to make this work. --------- Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
1 parent 5886fb5 commit 9a6a240

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

mojo/extensions.bzl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ load("//mojo:mojo_host_platform.bzl", "mojo_host_platform")
44
load("//mojo/private:mojo_gpu_toolchains_repository.bzl", "mojo_gpu_toolchains_repository")
55

66
_PLATFORMS = ["linux_aarch64", "linux_x86_64", "macos_arm64"]
7-
_DEFAULT_VERSION = "1.0.0b2.dev2026060706"
7+
_DEFAULT_VERSION = "1.0.0b3.dev2026061206"
88
_KNOWN_SHAS = {
9-
"1.0.0b2.dev2026060706": {
10-
"linux_aarch64": "ff57b49bb38eb832302a72d4f4c2f2c7553bf559ee5de2798daafb57a37877e8",
11-
"linux_x86_64": "e28b4b663cce73416507f957b54d2b4c96a7bd3f42bbe41ec74e8c0b6f93444c",
12-
"macos_arm64": "45261916bb30cfe16d2bd04bcfcf3ded8dca0934ec33b559316891a5217588e6",
13-
"mojo_compiler_mojo_libs": "4452a8ad98634178c0cae20799a41e385a306159f94b409955ac95e052dd9e55",
14-
},
15-
"1.0.0b2.dev2026051806": {
16-
"linux_aarch64": "224c4c1590debdff509bde74ead2da7b3eef2bc052380627e824072fe18bef05",
17-
"linux_x86_64": "7775e0386cb564cfd09f34c74209b80fc5a5d43b5ac20e36e638032e0f0cd63a",
18-
"macos_arm64": "5effdfe6fa9962802bba236baa15541584d7c27e3224d304d39d00912113fe58",
19-
"mojo_compiler_mojo_libs": "63e7bcbca2f311d6aba0c90cdd3c1152d153ee3f0f65ccc5c4f06f61b84c06e4",
9+
"1.0.0b3.dev2026061206": {
10+
"linux_aarch64": "061042c815d945c8e403a13c5317d6dbd9ceef5a0ef84422ae6b6da0a2f0fe59",
11+
"linux_x86_64": "b7f569472b02a35f40c8ea96ea51dac73b6c6c085e23c08ecf3613276df4f7dd",
12+
"macos_arm64": "bc4106c6013994b4eb246702832c7bc6967c4f6eeaa911eccf75d2dff26d7a3a",
13+
"mojo_compiler_mojo_libs": "1c99770a8a14804f810e6a2a12f1fd5b8d5c783301b38b74c785bc421ac334b9",
2014
},
2115
}
2216
_PLATFORM_MAPPINGS = {

mojo/private/mojo_binary_test.bzl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ def _find_main(name, srcs, main):
9090

9191
fail("Multiple Mojo files provided, but no main file specified. Please set 'main = \"foo.mojo\"' to disambiguate.")
9292

93+
def _format_include(arg):
94+
return ["-I", arg.dirname]
95+
96+
def _format_path(arg):
97+
return [arg.path]
98+
9399
def _mojo_binary_test_implementation(ctx, *, shared_library = False):
94100
cc_toolchain = find_cpp_toolchain(ctx)
95101
mojo_toolchain = ctx.exec_groups["mojo_compile"].toolchains["//:toolchain_type"].mojo_toolchain_info
@@ -103,18 +109,19 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
103109
args.add("build")
104110
args.add("-strip-file-prefix=.")
105111
args.add("--emit", "object")
106-
args.add("-o", object_file.path)
112+
args.add("-o", object_file)
113+
args.add("--lld-path", mojo_toolchain.lld)
107114

108115
main = _find_main(ctx.label.name, ctx.files.srcs, ctx.file.main)
109-
args.add(main.path)
116+
args.add(main)
110117
root_directory = main.dirname
111118
for file in ctx.files.srcs:
112119
if not file.dirname.startswith(root_directory):
113-
args.add("-I", file.dirname)
120+
args.add_all([file], map_each = _format_include)
114121

115122
all_deps = ctx.attr.deps + mojo_toolchain.implicit_deps + ([ctx.attr._link_extra_lib] if ctx.attr._link_extra_lib else [])
116-
import_paths, transitive_mojodeps = collect_mojoinfo(all_deps)
117-
args.add_all(import_paths, before_each = "-I")
123+
_, transitive_mojodeps = collect_mojoinfo(all_deps)
124+
args.add_all(transitive_mojodeps, map_each = _format_include)
118125

119126
# NOTE: Argument order:
120127
# 1. Basic functional arguments
@@ -154,13 +161,16 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
154161
"MODULAR_CRASH_REPORTING_ENABLED": "false",
155162
"MODULAR_MOJO_MAX_COMPILERRT_PATH": "/dev/null", # Make sure this fails if accessed
156163
"MODULAR_MOJO_MAX_LINKER_DRIVER": "/dev/null", # Make sure this fails if accessed
157-
"MODULAR_MOJO_MAX_LLD_PATH": mojo_toolchain.lld.path,
164+
"MODULAR_MOJO_MAX_LLD_PATH": "/dev/null", # Make sure this fails if accessed
158165
"PATH": "/dev/null", # Avoid using the host's PATH
159166
"TEST_TMPDIR": ".",
160167
} | build_env,
161168
use_default_shell_env = True,
162169
exec_group = "mojo_compile",
163170
toolchain = "//:toolchain_type",
171+
execution_requirements = {
172+
"supports-path-mapping": "1",
173+
},
164174
)
165175

166176
feature_configuration = cc_common.configure_features(

tests/shared_library.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@export
2-
def foo() -> Int:
2+
def foo() abi("C") -> Int:
33
return 42

0 commit comments

Comments
 (0)