Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix package detection and build when cross-compiling from MSVC to GNU #180

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading