Skip to content

Commit

Permalink
Fix #144
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Nov 27, 2023
1 parent 7bc44b7 commit ff624e5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions shaderc-sys/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,33 @@ fn check_vulkan_sdk_version(path: &Path) -> Result<(), Box<dyn std::error::Error
Ok(())
}

fn host_target() -> 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(|l| l.starts_with("host: "))
.map(|l| l.strip_prefix("host: ").unwrap())
.unwrap_or_else(|| panic!("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();
Expand Down

0 comments on commit ff624e5

Please sign in to comment.