Set the Apple deployment target for rustc from the linker args - #4282
Conversation
An Apple cc_toolchain passes its deployment target to clang inside the `-target` triple, e.g. `arm64-apple-macosx26.0`, which rules_rust forwards to rustc as link args. rustc does not read those: it takes the deployment target from `MACOSX_DEPLOYMENT_TARGET` (or the per-OS sibling) and otherwise falls back to its own default, which it passes to the linker as `-mmacosx-version-min=11.0.0`. clang sees both, and since Rust 1.97 surfaces linker stderr every link prints `overriding '-mmacosx-version-min=11.0.0' option with '-target ...'`. Derive the variable from the forwarded link args and set it in the Rustc action's environment: `-target`/`--target=` triples for macos, ios (including simulator and Mac Catalyst), tvos, watchos and xros/visionos, or `-m<os>-version-min=` when no triple carries a version. The link args are still forwarded unchanged, and a value the user sets through `--action_env`, `rustc_env` or the toolchain's `env` is kept. Fixes bazelbuild#4149 Assisted-by: Claude
The Apple cc_toolchain from apple_support appends its own `-target` triple after the user's link flags, so on a macOS host the last triple in the Rustc action's link args is the toolchain's, not the one these tests pass through `--linkopt`. The derived `MACOSX_DEPLOYMENT_TARGET` then carries the toolchain's minimum OS rather than `26.0`, and the test that expects no variable at all sees one. Both would fail on every macOS CI task. Mark those two tests incompatible with macOS, as the other unit tests do for host-specific cases. The precedence tests and the parser unit test hold on every host and keep running everywhere. Assisted-by: Claude
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
signed |
|
@drakeo338 Looks like some of the tests need to be constrained to Apple platforms |
bazel coverage builds a test's dependencies, so the binaries analysed under an Apple -target linkopt were linked by gcc on Linux and failed. The tests now read the Rustc actions through a small wrapper rule that applies the link settings as a transition and forwards only the actions, with empty instrumented files so coverage does not walk into the binary. Assisted-by: Claude
|
Thanks! Fixed in 98e0081. The failure was |
Fixes #4149.
Following keith's suggestion on the issue: when the link args carry an Apple
-targettriple with an OS version, rustc links now get the matching*_DEPLOYMENT_TARGETenv var, so rustc's-m<os>-version-minagrees with the triple and clang stops warning. A value from--action_env,rustc_envor the toolchain'senvstill wins, and non-Apple targets are untouched.Tests: a unit test for the triple parser, plus analysis tests for the linkopt case and the precedence rules. The two linkopt tests skip on macOS, because apple_support's toolchain appends its own
-targetafter user linkopts there, so the last triple is the toolchain's. I'd be glad to swap that for a macOS-specific assertion if you prefer.Verified locally on Linux with bazelisk: 20 passed, 2 unrelated skips. I don't have a Mac, so macOS coverage comes from CI.