@@ -443,8 +443,41 @@ fn compiler_rt_for_profiler(builder: &Builder<'_>) -> PathBuf {
443
443
/// Configure cargo to compile the standard library, adding appropriate env vars
444
444
/// and such.
445
445
pub fn std_cargo ( builder : & Builder < ' _ > , target : TargetSelection , stage : u32 , cargo : & mut Cargo ) {
446
- if let Some ( target) = env:: var_os ( "MACOSX_STD_DEPLOYMENT_TARGET" ) {
447
- cargo. env ( "MACOSX_DEPLOYMENT_TARGET" , target) ;
446
+ // rustc already ensures that it builds with the minimum deployment
447
+ // target, so ideally we shouldn't need to do anything here.
448
+ //
449
+ // However, `cc` currently defaults to a higher version for backwards
450
+ // compatibility, which means that compiler-rt, which is built via
451
+ // compiler-builtins' build script, gets built with a higher deployment
452
+ // target. This in turn causes warnings while linking, and is generally
453
+ // a compatibility hazard.
454
+ //
455
+ // So, at least until https://github.com/rust-lang/cc-rs/issues/1171, or
456
+ // perhaps https://github.com/rust-lang/cargo/issues/13115 is resolved, we
457
+ // explicitly set the deployment target environment variables to avoid
458
+ // this issue.
459
+ //
460
+ // This place also serves as an extension point if we ever wanted to raise
461
+ // rustc's default deployment target while keeping the prebuilt `std` at
462
+ // a lower version, so it's kinda nice to have in any case.
463
+ if target. contains ( "apple" ) && !builder. config . dry_run ( ) {
464
+ // Query rustc for the deployment target, and the associated env var.
465
+ // The env var is one of the standard `*_DEPLOYMENT_TARGET` vars, i.e.
466
+ // `MACOSX_DEPLOYMENT_TARGET`, `IPHONEOS_DEPLOYMENT_TARGET`, etc.
467
+ let mut cmd = command ( builder. rustc ( cargo. compiler ( ) ) ) ;
468
+ cmd. arg ( "--target" ) . arg ( target. rustc_target_arg ( ) ) ;
469
+ cmd. arg ( "--print=deployment-target" ) ;
470
+ let output = cmd. run_capture_stdout ( builder) . stdout ( ) ;
471
+
472
+ let ( env_var, value) = output. split_once ( '=' ) . unwrap ( ) ;
473
+ // Unconditionally set the env var (if it was set in the environment
474
+ // already, rustc should've picked that up).
475
+ cargo. env ( env_var. trim ( ) , value. trim ( ) ) ;
476
+
477
+ // Allow CI to override the deployment target for `std`.
478
+ if let Some ( target) = env:: var_os ( "MACOSX_STD_DEPLOYMENT_TARGET" ) {
479
+ cargo. env ( "MACOSX_DEPLOYMENT_TARGET" , target) ;
480
+ }
448
481
}
449
482
450
483
// Paths needed by `library/profiler_builtins/build.rs`.
0 commit comments