-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: locate sdkroot required since big sur
- Loading branch information
1 parent
72dd828
commit 58ff15c
Showing
5 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use once_cell::sync::OnceCell; | ||
use std::{ | ||
env, io, | ||
path::{Path, PathBuf}, | ||
process::Command, | ||
}; | ||
|
||
/// Finds the Apple SDK root directory by checking the `SDKROOT` environment variable or running | ||
/// `xcrun --show-sdk-path`. The result is cached so multiple calls to this function should be | ||
/// fast. | ||
pub fn get_apple_sdk_root() -> Result<&'static Path, String> { | ||
static SDK_PATH: OnceCell<PathBuf> = OnceCell::new(); | ||
|
||
SDK_PATH | ||
.get_or_try_init(|| { | ||
if let Ok(sdkroot) = env::var("SDKROOT") { | ||
return Ok(PathBuf::from(sdkroot)); | ||
} | ||
|
||
let res = Command::new("xcrun") | ||
.arg("--show-sdk-path") | ||
.output() | ||
.and_then(|output| { | ||
if output.status.success() { | ||
Ok(String::from_utf8(output.stdout).unwrap()) | ||
} else { | ||
let error = String::from_utf8(output.stderr); | ||
let error = format!("process exit with error: {}", error.unwrap()); | ||
Err(io::Error::new(io::ErrorKind::Other, &error[..])) | ||
} | ||
}); | ||
|
||
match res { | ||
Ok(output) => Ok(PathBuf::from(output.trim())), | ||
Err(e) => Err(format!("failed to get SDK path: {}", e)), | ||
} | ||
}) | ||
.map(AsRef::as_ref) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ mod test; | |
|
||
pub mod value; | ||
|
||
mod apple; | ||
pub(crate) mod intrinsics; | ||
mod linker; | ||
mod module_group; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters