Skip to content

Commit 87f860f

Browse files
authored
Set macOS min OS when passed (#65)
Mojo (really LLVM) defaults to the current major OS version if no min OS version is passed with the triple. In this case if the linker has a minimum OS version flag it warns (and potentially produces invalid binaries). This makes sure we're using the correct version for both cases.
1 parent 6ede244 commit 87f860f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mojo/toolchain.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def _mojo_toolchain_impl(ctx):
1616
else:
1717
copts.append("--target-accelerator=NONE")
1818

19+
is_macos = ctx.target_platform_has_constraint(ctx.attr._macos_constraint[platform_common.ConstraintValueInfo])
20+
if is_macos:
21+
min_os = ctx.fragments.cpp.minimum_os_version() or ctx.fragments.apple.macos_minimum_os_flag
22+
if min_os:
23+
copts.append("--target-triple=arm64-apple-macosx{}".format(min_os))
24+
1925
return [
2026
platform_common.ToolchainInfo(
2127
mojo_toolchain_info = MojoToolchainInfo(
@@ -62,11 +68,15 @@ mojo_toolchain = rule(
6268
cfg = "target",
6369
doc = "Implicit dependencies that every target should depend on, providing either CcInfo, or MojoInfo.",
6470
),
71+
"_macos_constraint": attr.label(
72+
default = Label("@platforms//os:macos"),
73+
),
6574
},
6675
doc = """\
6776
Defines the Mojo compiler toolchain.
6877
""",
6978
toolchains = [
7079
config_common.toolchain_type("//:gpu_toolchain_type", mandatory = False),
7180
],
81+
fragments = ["cpp", "apple"],
7282
)

0 commit comments

Comments
 (0)