diff --git a/libusb1-sys/Cargo.toml b/libusb1-sys/Cargo.toml index 519accf..2612e78 100644 --- a/libusb1-sys/Cargo.toml +++ b/libusb1-sys/Cargo.toml @@ -39,7 +39,7 @@ vendored = [] [dependencies] libc = "0.2" -[target.'cfg(target_env = "msvc")'.build-dependencies] +[target.'cfg(target_os = "windows")'.build-dependencies] vcpkg = "0.2" [build-dependencies] diff --git a/libusb1-sys/build.rs b/libusb1-sys/build.rs index ede5219..22139fd 100644 --- a/libusb1-sys/build.rs +++ b/libusb1-sys/build.rs @@ -19,17 +19,6 @@ pub fn link_framework(name: &str) { println!("cargo:rustc-link-lib=framework={}", name); } -#[cfg(target_env = "msvc")] -fn find_libusb_pkg(_statik: bool) -> bool { - match vcpkg::Config::new().find_package("libusb") { - Ok(_) => true, - Err(e) => { - println!("Can't find libusb pkg: {:?}", e); - false - } - } -} - fn get_macos_major_version() -> Option { if !cfg!(target_os = "macos") { return None; @@ -45,8 +34,17 @@ fn get_macos_major_version() -> Option { Some(major) } -#[cfg(not(target_env = "msvc"))] fn find_libusb_pkg(statik: bool) -> bool { + if std::env::var("CARGO_CFG_TARGET_ENV") == Ok("msvc".into()) { + #[cfg(target_os = "windows")] + return match vcpkg::Config::new().find_package("libusb") { + Ok(_) => true, + Err(e) => { + println!("Can't find libusb pkg: {:?}", e); + false + } + }; + } // https://github.com/rust-lang/rust/issues/96943 let needs_rustc_issue_96943_workaround: bool = get_macos_major_version() .map(|major| major >= 11) @@ -171,8 +169,9 @@ fn make_source() { } if std::env::var("CARGO_CFG_TARGET_OS") == Ok("windows".into()) { - #[cfg(target_env = "msvc")] - base_config.flag("/source-charset:utf-8"); + if std::env::var("CARGO_CFG_TARGET_ENV") == Ok("msvc".into()) { + base_config.flag("/source-charset:utf-8"); + } base_config.warnings(false); base_config.define("OS_WINDOWS", Some("1"));