Skip to content

Commit deea52e

Browse files
committed
chore: query xcrun on MacOS
1 parent b09c21a commit deea52e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

build.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,21 @@ fn main() {
3131
lean_dir.join("lib/lean")
3232
};
3333

34-
if !cfg!(feature = "static") {
34+
// To find libc++ on macOS, We must find the path to XCode, which apple enjoys
35+
// changing each macOS release.
36+
// Thus, we do this in a robust fashion by querying `xcrun`.
37+
if cfg!(target_os = "macos") {
38+
let xcrun_output = Command::new("xcrun")
39+
.args(["--show-sdk-path"])
40+
.output()
41+
.expect("failed to execute `xcrun --show-sdk-path`, which is used to find the location of MacOS platform libraries. Please ensure that XCode is installed.");
42+
let libcpp_path = PathBuf::from(String::from_utf8(xcrun_output.stdout)
43+
.expect("Path returned by `xcrun --show-sdk-path` is invalid UTF-8. This must never happen.").trim())
44+
.join("usr/lib");
45+
println!("cargo:rustc-link-search={}", libcpp_path.display());
46+
}
47+
48+
if cfg!(feature = "static") {
3549
// Step 2: check libleanshared.so/libleanshared.dylib/libleanshared.dll is actually there, just for cleaner error messages
3650
let mut shared_lib = lib_dir.clone();
3751
let exists = if cfg!(target_os = "windows") {

0 commit comments

Comments
 (0)