Skip to content

Commit

Permalink
Merge pull request #180 from amyspark/fix-msvc-to-mingw-compilation
Browse files Browse the repository at this point in the history
Fix package detection and build when cross-compiling from MSVC to GNU
  • Loading branch information
a1ien authored Mar 5, 2024
2 parents 145c12c + 307a315 commit 29694b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion libusb1-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
35 changes: 17 additions & 18 deletions libusb1-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +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) => {
if pkg_config::probe_library("libusb-1.0").is_ok() {
true
} else {
println!("Can't find libusb pkg: {:?}", e);
false
}
}
}
}

fn get_macos_major_version() -> Option<usize> {
if !cfg!(target_os = "macos") {
return None;
Expand All @@ -49,8 +34,21 @@ fn get_macos_major_version() -> Option<usize> {
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) => {
if pkg_config::probe_library("libusb-1.0").is_ok() {
true
} else {
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)
Expand Down Expand Up @@ -175,8 +173,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"));
Expand Down

0 comments on commit 29694b9

Please sign in to comment.