Skip to content

Commit dd050e9

Browse files
Build - Remove use of cfg! and instead inspect TARGET (to work properly in cross-compilation) (#374)
1 parent 9862ca8 commit dd050e9

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

build.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@ fn main() {
1919
// target_arch is not working? OS FAMILY and ARCH variables were empty too
2020
// I think the cross-compilation is broken. We could take these from the environment,
2121
// since the build script seems to have a different target_arch than the destination.
22-
let target = env::var("TARGET").unwrap_or("".to_string());
22+
let target = env::var("TARGET").expect("cargo should have set $TARGET");
2323
if target != "wasm32-unknown-unknown"
24-
&& cfg!(not(any(
25-
target_os = "macos",
26-
target_os = "windows",
27-
target_os = "redox",
28-
target_arch = "wasm32", // this is ignored. Why?
29-
)))
24+
&& !target.contains("-macos")
25+
&& !target.contains("-windows")
26+
&& !target.contains("-redox")
27+
&& !target.starts_with("wasm32-") // this is ignored. Why?
3028
&& cfg!(not(any(feature = "wayland", feature = "x11")))
3129
{
3230
panic!("At least one of the x11 or wayland features must be enabled");
3331
}
3432

35-
let env = env::var("TARGET").unwrap();
36-
if env.contains("darwin") {
33+
if target.contains("darwin") {
3734
cc::Build::new()
3835
.flag("-mmacosx-version-min=10.10")
3936
.file("src/native/macosx/MacMiniFB.m")
@@ -42,7 +39,7 @@ fn main() {
4239
.compile("libminifb_native.a");
4340
println!("cargo:rustc-link-lib=framework=Metal");
4441
println!("cargo:rustc-link-lib=framework=MetalKit");
45-
} else if !env.contains("windows") && !env.contains("wasm32") {
42+
} else if !target.contains("windows") && !target.contains("wasm32") {
4643
// build scalar on non-windows and non-mac
4744
cc::Build::new()
4845
.file("src/native/posix/scalar.c")

0 commit comments

Comments
 (0)