From 03e6048dc950bd42feca8d1d51acc61969bf74de Mon Sep 17 00:00:00 2001 From: Chris Nixon Date: Tue, 30 Mar 2021 22:31:52 +0100 Subject: [PATCH 1/2] Check compile target at runtime in build --- build/Cargo.toml | 3 --- build/src/lib.rs | 17 ++++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/build/Cargo.toml b/build/Cargo.toml index 3978f7cc..997ae113 100644 --- a/build/Cargo.toml +++ b/build/Cargo.toml @@ -10,7 +10,4 @@ repository = "https://github.com/napi-rs/napi-rs" version = "1.0.1" [dependencies] -cfg-if = "1" - -[target.'cfg(windows)'.dependencies] ureq = "2" diff --git a/build/src/lib.rs b/build/src/lib.rs index b3d387a0..72046f9d 100644 --- a/build/src/lib.rs +++ b/build/src/lib.rs @@ -1,11 +1,10 @@ -cfg_if::cfg_if! { - if #[cfg(windows)] { - mod windows; - pub use windows::setup; - } else if #[cfg(target_os = "macos")] { - mod macos; - pub use macos::setup; - } else { - pub fn setup() { } +mod macos; +mod windows; + +pub fn setup() { + match std::env::var("CARGO_CFG_TARGET_OS").as_deref() { + Ok("macos") => macos::setup(), + Ok("windows") => windows::setup(), + _ => {} } } From 74e6cf2916a15909203760da456beb7c0d7c13f0 Mon Sep 17 00:00:00 2001 From: Chris Nixon Date: Thu, 1 Apr 2021 23:32:01 +0100 Subject: [PATCH 2/2] Don't try to use ureq on musl targets --- build/Cargo.toml | 3 +++ build/src/lib.rs | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/build/Cargo.toml b/build/Cargo.toml index 997ae113..c0d0c837 100644 --- a/build/Cargo.toml +++ b/build/Cargo.toml @@ -10,4 +10,7 @@ repository = "https://github.com/napi-rs/napi-rs" version = "1.0.1" [dependencies] +cfg-if = "1" + +[target.'cfg(not(target_env = "musl"))'.dependencies] ureq = "2" diff --git a/build/src/lib.rs b/build/src/lib.rs index 72046f9d..7a4e51b1 100644 --- a/build/src/lib.rs +++ b/build/src/lib.rs @@ -1,10 +1,23 @@ mod macos; -mod windows; + +cfg_if::cfg_if! { + if #[cfg(not(target_env = "musl"))] { + mod windows; + } +} pub fn setup() { match std::env::var("CARGO_CFG_TARGET_OS").as_deref() { Ok("macos") => macos::setup(), - Ok("windows") => windows::setup(), + Ok("windows") => { + cfg_if::cfg_if! { + if #[cfg(not(target_env = "musl"))] { + windows::setup() + } else { + eprintln!("Cross compiling to windows-msvc is not supported from *-musl hosts") + } + } + } _ => {} } }