From b964a59249c193389dd73ac630cb58d98896f43b Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Mon, 27 Nov 2023 06:15:12 +0100 Subject: [PATCH] Fix #144 --- shaderc-sys/build/build.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/shaderc-sys/build/build.rs b/shaderc-sys/build/build.rs index 70b506e..acd8934 100644 --- a/shaderc-sys/build/build.rs +++ b/shaderc-sys/build/build.rs @@ -157,13 +157,32 @@ fn check_vulkan_sdk_version(path: &Path) -> Result<(), Box String { + let output = std::process::Command::new("rustc") + .arg("-vV") + .output() + .expect("failed to invoke rustc"); + + std::str::from_utf8(&output.stdout) + .expect("rustc didn't return valid UTF-8") + .lines() + .find_map(|l| l.strip_prefix("host: ")) + .expect("failed to query rustc for the host target triple") + .to_owned() +} + fn main() { - // Don't attempt to build shaderc native library on docs.rs + // Don't attempt to build shaderc native library on docs.rs when cross-compiling. if env::var("DOCS_RS").is_ok() { - println!( - "cargo:warning=shaderc: docs.rs detected, will not attempt to link against shaderc" - ); - return; + let is_cross_compiling = env::var("TARGET").unwrap() != host_target(); + + if is_cross_compiling { + println!( + "cargo:warning=shaderc: docs.rs cross-compilation detected, will not attempt to \ + link against shaderc", + ); + return; + } } let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();