From 31a058fcc2ac68128acb83772d78aa3d60ae5757 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Wed, 21 Aug 2019 16:19:34 -0700 Subject: [PATCH 1/2] 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. --- curl-sys/build.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/curl-sys/build.rs b/curl-sys/build.rs index 4ced5df243..cd2b070cb5 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -47,6 +47,17 @@ fn main() { .status(); } + if target.contains("apple") { + // On (older) OSX we need to link against the clang runtime, + // which is hidden in some non-default path. + // + // More details at https://github.com/alexcrichton/curl-rust/issues/279. + if let Some(path) = macos_link_search_path() { + println!("cargo:rustc-link-lib=clang_rt.osx"); + println!("cargo:rustc-link-search={}", path); + } + } + let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap()); let include = dst.join("include"); let build = dst.join("build"); @@ -480,3 +491,22 @@ fn curl_config_reports_http2() -> bool { return true; } + +fn macos_link_search_path() -> Option { + let output = Command::new("clang").arg("--print-search-dirs").output().ok()?; + if !output.status.success() { + println!("failed to run 'clang --print-search-dirs', continuing without a link search path"); + return None; + } + + let stdout = String::from_utf8_lossy(&output.stdout); + for line in stdout.lines() { + if line.contains("libraries: =") { + let path = line.split('=').skip(1).next()?; + return Some(format!("{}/lib/darwin", path)); + } + } + + println!("failed to determine link search path, continuing without it"); + None +} From c6206ee2966818e5c7791f2af5fb51ad0632f50e Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Thu, 9 Jan 2020 14:37:36 +0100 Subject: [PATCH 2/2] Fix formatting --- curl-sys/build.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/curl-sys/build.rs b/curl-sys/build.rs index cd2b070cb5..6f89d7a6c8 100644 --- a/curl-sys/build.rs +++ b/curl-sys/build.rs @@ -493,9 +493,14 @@ fn curl_config_reports_http2() -> bool { } fn macos_link_search_path() -> Option { - let output = Command::new("clang").arg("--print-search-dirs").output().ok()?; + let output = Command::new("clang") + .arg("--print-search-dirs") + .output() + .ok()?; if !output.status.success() { - println!("failed to run 'clang --print-search-dirs', continuing without a link search path"); + println!( + "failed to run 'clang --print-search-dirs', continuing without a link search path" + ); return None; }