-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
The environment variables MACOSX_DEPLOYMENT_TARGET, IPHONEOS_DEPLOYMENT_TARGET, TVOS_DEPLOYMENT_TARGET and WATCHOS_DEPLOYMENT_TARGET are standard environment variables on Apple targets, and are used by compilers to get the desired minimum supported operating system version.
When not specified, compilers usually choose some default. The default that rustc chooses can be retrieved with rustc --target x86_64-apple-darwin --print deployment-target, and e.g. the cc crate has support for detecting this, and passing it on to a C compiler.
The problem(s) is that:
- This kind of logic that
cchas, has to be implemented by everybuild.rsscript that wants to call an external compiler. - Spawning a new
rustcprocess to determine this is inefficient (although probably negligible). - It is not really discoverable for users. (IMO the most important)
Proposed Solution
Cargo always sets these in build scripts when building for the relevant Apple targets.
That is, it sets MACOSX_DEPLOYMENT_TARGET when building for macOS, IPHONEOS_DEPLOYMENT_TARGET when building for iOS, and so on.
As an example, as an author of a build.rs script, I would like to be able to do the following (once a version of Cargo that supports this is in my MSRV):
if std::env::var("TARGET").unwrap() == "x86_64-apple-darwin" {
// Note that I'm allowed to `unwrap` here because Cargo always sets it for this target.
let deployment_target = std::env::var("MACOSX_DEPLOYMENT_TARGET").unwrap();
// ...
}(Note: In contrast to all other environment variables that Cargo sets for build scripts, these are explicitly target dependent).
Notes
CC @BlackHoleFox whom implemented the rustc --print deployment-target flag.
I'd volunteer to do the implementation work if this feature is desired?