@@ -2515,7 +2515,8 @@ impl Build {
2515
2515
ArchSpec :: Catalyst ( _) => "macosx" . to_owned ( ) ,
2516
2516
} ;
2517
2517
2518
- if !is_mac {
2518
+ // AppleClang sometimes requires sysroot even for darwin
2519
+ if cmd. is_xctoolchain_clang ( ) || !target. ends_with ( "-darwin" ) {
2519
2520
self . print ( & format_args ! ( "Detecting {:?} SDK path for {}" , os, sdk) ) ;
2520
2521
let sdk_path = if let Some ( sdkroot) = env:: var_os ( "SDKROOT" ) {
2521
2522
sdkroot
@@ -2525,7 +2526,10 @@ impl Build {
2525
2526
2526
2527
cmd. args . push ( "-isysroot" . into ( ) ) ;
2527
2528
cmd. args . push ( sdk_path) ;
2528
- // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2529
+ }
2530
+
2531
+ // TODO: Remove this once Apple stops accepting apps built with Xcode 13
2532
+ if !is_mac {
2529
2533
cmd. args . push ( "-fembed-bitcode" . into ( ) ) ;
2530
2534
}
2531
2535
@@ -3382,19 +3386,6 @@ impl Build {
3382
3386
let target = self . get_target ( ) ?;
3383
3387
let host = self . get_host ( ) ?;
3384
3388
if host. contains ( "apple-darwin" ) && target. contains ( "apple-darwin" ) {
3385
- // If, for example, `cargo` runs during the build of an XCode project, then `SDKROOT` environment variable
3386
- // would represent the current target, and this is the problem for us, if we want to compile something
3387
- // for the host, when host != target.
3388
- // We can not just remove `SDKROOT`, because, again, for example, XCode add to PATH
3389
- // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
3390
- // and `cc` from this path can not find system include files, like `pthread.h`, if `SDKROOT`
3391
- // is not set
3392
- if let Ok ( sdkroot) = env:: var ( "SDKROOT" ) {
3393
- if !sdkroot. contains ( "MacOSX" ) {
3394
- let macos_sdk = self . apple_sdk_root ( "macosx" ) ?;
3395
- cmd. env ( "SDKROOT" , macos_sdk) ;
3396
- }
3397
- }
3398
3389
// Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at
3399
3390
// "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
3400
3391
// although this is apparently ignored when using the linker at "/usr/bin/ld".
@@ -3718,6 +3709,17 @@ impl Tool {
3718
3709
self . family == ToolFamily :: Clang
3719
3710
}
3720
3711
3712
+ /// Whether the tool is AppleClang under .xctoolchain
3713
+ #[ cfg( target_vendor = "apple" ) ]
3714
+ fn is_xctoolchain_clang ( & self ) -> bool {
3715
+ let path = self . path . to_string_lossy ( ) ;
3716
+ path. contains ( ".xctoolchain/" )
3717
+ }
3718
+ #[ cfg( not( target_vendor = "apple" ) ) ]
3719
+ fn is_xctoolchain_clang ( & self ) -> bool {
3720
+ false
3721
+ }
3722
+
3721
3723
/// Whether the tool is MSVC-like.
3722
3724
pub fn is_like_msvc ( & self ) -> bool {
3723
3725
match self . family {
0 commit comments