From e29382e9c51b14a925b57fdedda1e2b2eb8026f0 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 17 Oct 2025 10:01:10 -0700 Subject: [PATCH] Set macOS min OS when passed 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. --- mojo/toolchain.bzl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mojo/toolchain.bzl b/mojo/toolchain.bzl index 2214cb7..a89fc4b 100644 --- a/mojo/toolchain.bzl +++ b/mojo/toolchain.bzl @@ -16,6 +16,12 @@ def _mojo_toolchain_impl(ctx): else: copts.append("--target-accelerator=NONE") + is_macos = ctx.target_platform_has_constraint(ctx.attr._macos_constraint[platform_common.ConstraintValueInfo]) + if is_macos: + min_os = ctx.fragments.cpp.minimum_os_version() or ctx.fragments.apple.macos_minimum_os_flag + if min_os: + copts.append("--target-triple=arm64-apple-macosx{}".format(min_os)) + return [ platform_common.ToolchainInfo( mojo_toolchain_info = MojoToolchainInfo( @@ -62,6 +68,9 @@ mojo_toolchain = rule( cfg = "target", doc = "Implicit dependencies that every target should depend on, providing either CcInfo, or MojoInfo.", ), + "_macos_constraint": attr.label( + default = Label("@platforms//os:macos"), + ), }, doc = """\ Defines the Mojo compiler toolchain. @@ -69,4 +78,5 @@ Defines the Mojo compiler toolchain. toolchains = [ config_common.toolchain_type("//:gpu_toolchain_type", mandatory = False), ], + fragments = ["cpp", "apple"], )