Skip to content

Commit fbe9fbd

Browse files
committed
Fix building with MSYS2-MinGW hdf5.
1 parent a6adcf1 commit fbe9fbd

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

hdf5-sys/build.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Version {
2929
}
3030

3131
pub fn parse(s: &str) -> Option<Self> {
32-
let re = Regex::new(r"^(1)\.(8|10|12|13)\.(\d\d?)(_\d+)?(-patch\d+)?$").ok()?;
32+
let re = Regex::new(r"^(1)\.(8|10|12|13|14)\.(\d\d?)(_\d+)?(-patch\d+)?$").ok()?;
3333
let captures = re.captures(s)?;
3434
Some(Self {
3535
major: captures.get(1).and_then(|c| c.as_str().parse::<u8>().ok())?,
@@ -73,6 +73,13 @@ fn is_root_dir<P: AsRef<Path>>(path: P) -> bool {
7373
is_inc_dir(path.as_ref().join("include"))
7474
}
7575

76+
#[allow(dead_code)]
77+
fn is_msvc() -> bool {
78+
// `cfg!(target = "msvc")` will report wrong value when using
79+
// MSVC toolchain targeting GNU.
80+
std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "msvc"
81+
}
82+
7683
#[derive(Clone, Debug)]
7784
struct RuntimeError(String);
7885

@@ -115,7 +122,7 @@ fn get_runtime_version_single<P: AsRef<Path>>(path: P) -> Result<Version, Box<dy
115122

116123
fn validate_runtime_version(config: &Config) {
117124
println!("Looking for HDF5 library binary...");
118-
let libfiles = &["libhdf5.dylib", "libhdf5.so", "hdf5.dll"];
125+
let libfiles = &["libhdf5.dylib", "libhdf5.so", "hdf5.dll", "libhdf5-0.dll"];
119126
let mut link_paths = config.link_paths.clone();
120127
if cfg!(all(unix, not(target_os = "macos"))) {
121128
if let Some(ldv) = run_command("ld", &["--verbose"]) {
@@ -451,7 +458,7 @@ mod windows {
451458

452459
pub fn find_hdf5_via_winreg(config: &mut LibrarySearcher) {
453460
// Official HDF5 binaries on Windows are built for MSVC toolchain only.
454-
if config.inc_dir.is_some() || !cfg!(target_env = "msvc") {
461+
if config.inc_dir.is_some() || !is_msvc() {
455462
return;
456463
}
457464
// Check the list of installed programs, see if there's HDF5 anywhere;
@@ -492,7 +499,7 @@ impl LibrarySearcher {
492499
config.user_provided_dir = true;
493500
config.inc_dir = Some(root.join("include"));
494501
}
495-
if cfg!(target_env = "msvc") {
502+
if is_msvc() {
496503
// in order to allow HDF5_DIR to be pointed to a conda environment, we have
497504
// to support MSVC as a special case (where the root is in $PREFIX/Library)
498505
if let Some(ref inc_dir) = config.inc_dir {
@@ -560,9 +567,7 @@ impl LibrarySearcher {
560567
if link_paths.is_empty() {
561568
if let Some(root_dir) = inc_dir.parent() {
562569
link_paths.push(root_dir.join("lib"));
563-
if cfg!(target_env = "msvc") {
564-
link_paths.push(root_dir.join("bin"));
565-
}
570+
link_paths.push(root_dir.join("bin"));
566571
}
567572
}
568573
let header = Header::parse(inc_dir);
@@ -594,7 +599,7 @@ impl Config {
594599
println!("cargo:rerun-if-env-changed=HDF5_DIR");
595600
println!("cargo:rerun-if-env-changed=HDF5_VERSION");
596601

597-
if cfg!(target_env = "msvc") {
602+
if is_msvc() {
598603
println!("cargo:msvc_dll_indirection=1");
599604
}
600605
println!("cargo:include={}", self.inc_dir.to_str().unwrap());

0 commit comments

Comments
 (0)