File tree 1 file changed +14
-0
lines changed
1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: env;
1
2
use std:: io;
3
+ use std:: path:: Path ;
2
4
use std:: process:: Command ;
3
5
use crate :: spec:: { LinkArgs , LinkerFlavor , TargetOptions } ;
4
6
@@ -27,6 +29,18 @@ impl Arch {
27
29
}
28
30
29
31
pub fn get_sdk_root ( sdk_name : & str ) -> Result < String , String > {
32
+ // Following what clang does
33
+ // (https://github.com/llvm/llvm-project/blob/
34
+ // 296a80102a9b72c3eda80558fb78a3ed8849b341/clang/lib/Driver/ToolChains/Darwin.cpp#L1661-L1678)
35
+ // to allow the SDK path to be set. (For clang, xcrun sets
36
+ // SDKROOT; for rustc, the user or build system can set it, or we
37
+ // can fall back to checking for xcrun on PATH.)
38
+ if let Some ( sdkroot) = env:: var ( "SDKROOT" ) . ok ( ) {
39
+ let sdkroot_path = Path :: new ( & sdkroot) ;
40
+ if sdkroot_path. is_absolute ( ) && sdkroot_path != Path :: new ( "/" ) && sdkroot_path. exists ( ) {
41
+ return Ok ( sdkroot) ;
42
+ }
43
+ }
30
44
let res = Command :: new ( "xcrun" )
31
45
. arg ( "--show-sdk-path" )
32
46
. arg ( "-sdk" )
You can’t perform that action at this time.
0 commit comments