Skip to content

Commit 20cca1a

Browse files
hugwijstmulimoen
authored andcommitted
Support static cross-compilation from Unix to Windows.
Use wine to run HDF5 configuration programs.
1 parent f82006a commit 20cca1a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

hdf5-src/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ fn main() {
5757
}
5858
}
5959

60-
let debug_postfix = if cfg!(target_os = "windows") { "_D" } else { "_debug" };
60+
let targeting_windows = env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows";
61+
let debug_postfix = if targeting_windows { "_D" } else { "_debug" };
6162

6263
if feature_enabled("HL") {
6364
cfg.define("HDF5_BUILD_HL_LIB", "ON");
@@ -71,6 +72,13 @@ fn main() {
7172
println!("cargo:hl_library={}", hdf5_hl_lib);
7273
}
7374

75+
if cfg!(unix) && targeting_windows {
76+
let wine_exec =
77+
if env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "x86_64" { "wine64" } else { "wine" };
78+
// when cross-compiling to windows, use Wine to run code generation programs
79+
cfg.define("CMAKE_CROSSCOMPILING_EMULATOR", wine_exec);
80+
}
81+
7482
let dst = cfg.build();
7583
println!("cargo:root={}", dst.display());
7684

0 commit comments

Comments
 (0)