File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: env;
12use std:: io;
3+ use std:: path:: Path ;
24use std:: process:: Command ;
35use crate :: spec:: { LinkArgs , LinkerFlavor , TargetOptions } ;
46
@@ -27,6 +29,18 @@ impl Arch {
2729}
2830
2931pub 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+ }
3044 let res = Command :: new ( "xcrun" )
3145 . arg ( "--show-sdk-path" )
3246 . arg ( "-sdk" )
You can’t perform that action at this time.
0 commit comments