From 48fa26e89cf97161570a0f5c32e1ce4cfa873aaa Mon Sep 17 00:00:00 2001 From: Tim Balsfulland Date: Tue, 16 Jul 2024 14:40:46 +0200 Subject: [PATCH] fix cross-compiling static loader The build script used the `cfg!` macro to check the target os, but the "target" in a build script is actually the host. Use the `CARGO_CFG_TARGET_OS` environment variable instead. Issue #42 [has been worked around](https://github.com/KhronosGroup/OpenXR-SDK-Source/pull/198), and then [fixed upstream](https://github.com/KhronosGroup/OpenXR-SDK-Source/pull/239), so the additional flag on windows is no longer necessary. Linking the filesystem library is also done correctly upstream now: https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/main/src/cmake/StdFilesystemFlags.cmake --- sys/build.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sys/build.rs b/sys/build.rs index 2139f8fa..3c90cce1 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -16,13 +16,13 @@ fn main() { ); println!("cargo:rustc-link-lib=static=openxr_loader"); - if cfg!(any(target_os = "macos", target_os = "freebsd")) { + let target_os = std::env::var_os("CARGO_CFG_TARGET_OS") + .expect("missing CARGO_CFG_TARGET_OS environment variable"); + + if target_os == "macos" || target_os == "freebsd" { println!("cargo:rustc-link-lib=c++"); - } else if cfg!(target_os = "windows") { - println!("cargo:rustc-link-lib=pathcch"); - } else { + } else if target_os != "windows" { println!("cargo:rustc-link-lib=stdc++"); - println!("cargo:rustc-link-lib=stdc++fs"); } } #[cfg(all(not(feature = "static"), feature = "linked"))]