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 b964a59
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions shaderc-sys/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,32 @@ 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_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();
Expand Down

0 comments on commit b964a59

Please sign in to comment.