bazelbuild / bazelbuild/rules_rust
Apple Rust link actions pass conflicting deployment targets to clang
- Dominant language
- Starlark
- Stars
- 843
- Forks
- 651
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 15
Description
rules_rust forwards Apple C++ toolchain linker args to rustc, including clang targets like:
```
-C link-arg=-target
-C link-arg=arm64-apple-macosx26.0
```
When developing on macOS, these linker arguments commonly come from the Xcode toolchain created by `apple_support`. With `apple_support`, the minimum deployment version defaults to whatever the installed SDK version is.
That target argument encodes the Apple deployment target for clang. However, rustc does its own minimum deployment target detection. This is mediated through the `MACOSX_DEPLOYMENT_TARGET` env variable. If `MACOSX_DEPLOYMENT_TARGET ` is unset, rustc uses its built-in default and injects its own `-mmacosx-version-min` (which defaults to 11.0.0 on arm64)
Source: https://doc.rust-lang.org/nightly/rustc/platform-support/apple-darwin.html#deployment-target
This can make clang receive conflicting deployment targets, for example:
```
-mmacosx-version-min=11.0.0
-target arm64-apple-macosx26.0
```
With Rust 1.97 surfacing linker stderr, this issue is now more visible, with the following warning printed for every rust target:
```bash
warning: linker stderr: clang: overriding '-mmacosx-version-min=11.0.0' option with '-target arm64-apple-macosx26.5' [-Woverriding-option]
|
= note: `#[warn(linker_messages)]` on by default
```
I believe rules_rust should continue to forward linker arguments from the C++ toolchain, but should also pass `MACOSX_DEPLOYMENT_TARGET` to `rustc` when compiling for macOS targets. Similar behavior should be done for other Apple platforms as well (e.g. `IPHONEOS_DEPLOYMENT_TARGET`).
Contributor guide
Research direction
No specific files or tests are named. Start by tracing how rules_rust forwards Apple C++ linker arguments and constructs rustc invocations, then inspect the existing Apple toolchain environment handling; done means Apple builds pass the matching deployment target to rustc without conflicting clang target warnings, including macOS and other Apple platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100