Skip to content

Commit d1d903f

Browse files
committed
Link against clang runtime on static builds on macOS
On OSX we need to link against the clang runtime, which is hidden in some non-default path. We can get the path from `clang --print-search-dirs`. Kudos to @ehuss for finding that workaround. Fixes #279.
1 parent 20162df commit d1d903f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

curl-sys/build.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ fn main() {
4747
.status();
4848
}
4949

50+
if target.contains("apple") {
51+
// On OSX we need to link against the clang runtime, which is hidden in some non-default
52+
// path.
53+
println!("cargo:rustc-link-lib=clang_rt.osx");
54+
println!("cargo:rustc-link-search={}", macos_link_search_path());
55+
}
56+
5057
let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap());
5158
let include = dst.join("include");
5259
let build = dst.join("build");
@@ -467,3 +474,23 @@ fn curl_config_reports_http2() -> bool {
467474

468475
return true;
469476
}
477+
478+
fn macos_link_search_path() -> String {
479+
let output = Command::new("clang").arg("--print-search-dirs").output().unwrap();
480+
if !output.status.success() {
481+
panic!("Can't get search paths from clang");
482+
}
483+
484+
let stdout = String::from_utf8_lossy(&output.stdout);
485+
if !stdout.contains("libraries: ") {
486+
}
487+
488+
for line in stdout.lines() {
489+
if line.contains("libraries: =") {
490+
let path = line.split('=').skip(1).next().unwrap();
491+
return format!("{}/lib/darwin", path);
492+
}
493+
}
494+
495+
panic!("clang is missing search paths");
496+
}

0 commit comments

Comments
 (0)