Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not link native library when cross compiling for docs #145

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading