Repository navigation
cargo_build_script: set the Apple deployment target for cc-rs - #4434
Open
TrapsterDK wants to merge 1 commit into
Open
TrapsterDK wants to merge 1 commit into
TrapsterDK wants to merge 1 commit into
Conversation
cc-rs reads MACOSX_DEPLOYMENT_TARGET and its per-OS siblings, not CFLAGS. Derive them from the C compile args, as rustc actions already do from the link args. As for rustc, a value set through --action_env is kept, and the toolchain's env and build_script_env still override the derived one. Assisted-by: Claude
TrapsterDK
force-pushed
the
cargo-build-script-apple-deployment-target
branch
from
November 18, 2026 12:30
3ace926 to
fdfd065
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#4282 made rustc actions set
MACOSX_DEPLOYMENT_TARGET(and the iOS, tvOS, watchOS and visionOS variables) from the deployment target in the cc_toolchain's link args.cargo_build_scriptstill doesn't set them. cc-rs does not read the deployment target fromCFLAGS. It reads these environment variables, and when they are unset it falls back to its own default. So a C dependency built by a build script can target a different OS version than the toolchain, even thoughCFLAGScarries the right-target/-m<os>-version-min=.Fix
cargo_build_scriptrunsapple_deployment_target_envon the cc_toolchain's C compile args and sets the resulting variable for the build script. The helper is the one rustc actions already use. The version comes from the last-target/--target=Apple triple and falls back to-m<os>-version-min=. When both are present the triple wins, as in clang.use_default_shell_envcase that only build scripts have:envandbuild_script_envoverride the derived value.--action_env=VAR=valueis kept, but only whenuse_default_shell_envis on. With it off,--action_envnever reaches the action, so the derived value is still set.--action_env=VARwith no value is not visible at analysis time, so the derived value overrides it.apple_deployment_target_envdocstring to cover compile args, and theuse_cc_toolchainsetting docs to list the*_DEPLOYMENT_TARGETvariables. Also removed a stale comment saying cc-rs takes the deployment target fromCFLAGS.Tests
New analysis tests in
cargo/tests/cargo_build_script/cc_args_and_env, underapple_deployment_target_test:-targettriple, and iOS-mios-version-min=.-targetcombined with-mmacosx-version-min=, in both orders. The triple wins.--action_env=MACOSX_DEPLOYMENT_TARGET=...is kept.use_default_shell_env = Falseplus--action_env, the derived value is set.build_script_envoverrides the derived value.bazel test //cargo/tests/cargo_build_script/cc_args_and_env/... //test/unit/apple_deployment_target/...: 51 tests pass. The--action_envtests fail if thedefault_shell_envcheck or itsuse_default_shell_envguard is removed.Assisted by Claude.