From f87d74f8ef1da4dc8d6f1e7b8c043e73d7fdb749 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Mon, 9 Jan 2023 00:11:12 -0800 Subject: [PATCH] Detect statically linked musl using the crt-static target feature, not target_vendor=alpine --- build.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 0383556..29556f8 100644 --- a/build.rs +++ b/build.rs @@ -11,11 +11,15 @@ fn main() { match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() { "linux" => { - // statically link libunwind if compiling for musl, dynamically link otherwise + // statically link libunwind if statically linking musl (e.g. the + // `crt-static` target feature is present), dynamically link + // otherwise if env::var("CARGO_FEATURE_UNWIND").is_ok() { println!("cargo:rustc-cfg=use_libunwind"); if env::var("CARGO_CFG_TARGET_ENV").unwrap() == "musl" - && env::var("CARGO_CFG_TARGET_VENDOR").unwrap() != "alpine" + && !env::var("CARGO_CFG_TARGET_FEATURE") + .unwrap_or_default() + .contains("crt-static") { println!("cargo:rustc-link-search=native=/usr/local/lib");