cargo_build_script does not set MACOSX_DEPLOYMENT_TARGET for cc-rs

Open
#4,431 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
42/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
build-system

Research direction

Find the cargo_build_script action and the existing apple_deployment_target_env use in rustc actions. Check how C compile args and the action environment are assembled, then reproduce with a build script using cc-rs and an Apple toolchain configured with macos_minimum_os=26.0. Done when the deployment target variable is present in the build script environment and the C object uses the requested minimum OS version.

Written by the indexing model from the issue text.

Description

needs-triage

cargo_build_script populates CFLAGS and CXXFLAGS from the cc toolchain, so the Apple -target arm64-apple-macosx26.0 (or -m<os>-version-min=) flag reaches the build script. cc-rs does not read the deployment target from those variables. It reads MACOSX_DEPLOYMENT_TARGET (and IPHONEOS_DEPLOYMENT_TARGET and siblings), and falls back to its own default when they are unset.

The result is a C object built by a build script (for example with cc::Build) that carries a different minimum OS version than the rest of the build. The linker then warns about the mismatch, or the object is built for an older target than the toolchain asked for.

#4149 and #4282 fixed this for rustc actions by deriving the variable from the link args with apple_deployment_target_env. Build script actions were not covered.

To reproduce: build a cargo_build_script that uses cc-rs with an Apple cc toolchain configured with macos_minimum_os=26.0, and print MACOSX_DEPLOYMENT_TARGET from build.rs. It is unset.

The fix is to call apple_deployment_target_env on the C compile args in cargo_build_script and add the result to the action env. I will send a PR.

Assisted by Claude.

Dominant language
Starlark
Stars
857
Forks
701
Avg merge
4d 7h
Merged PRs (30d)
46

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_rust

All issues in bazelbuild/rules_rust

Similar issues

More Build System issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.