Skip to content

Commit

Permalink
Only use --print-sysroot with GNU like compilers
Browse files Browse the repository at this point in the history
Also add support for specifying sysroot using `TARGET_SYSROOT` env var
  • Loading branch information
messense committed Jan 3, 2022
1 parent 2aabf32 commit 69d9459
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl BuildContext {
}
})?;
let external_libs = if should_repair && !self.editable {
let sysroot = get_sysroot_path(&self.target)?;
let sysroot = get_sysroot_path(&self.target).unwrap_or_else(|_| PathBuf::from("/"));
find_external_libs(&artifact, &policy, sysroot).with_context(|| {
if let Some(platform_tag) = platform_tag {
format!("Error repairing wheel for {} compliance", platform_tag)
Expand Down Expand Up @@ -707,10 +707,13 @@ fn relpath(to: &Path, from: &Path) -> PathBuf {
/// Get sysroot path from target C compiler
///
/// Currently only gcc is supported, clang doesn't have a `--print-sysroot` option
/// TODO: allow specify sysroot from environment variable?
fn get_sysroot_path(target: &Target) -> Result<PathBuf> {
use crate::target::get_host_target;

if let Some(sysroot) = std::env::var_os("TARGET_SYSROOT") {
return Ok(PathBuf::from(sysroot));
}

let host_triple = get_host_target()?;
let target_triple = target.target_triple();
if host_triple != target_triple {
Expand All @@ -725,6 +728,10 @@ fn get_sysroot_path(target: &Target) -> Result<PathBuf> {
let compiler = build
.try_get_compiler()
.with_context(|| format!("Failed to get compiler for {}", target_triple))?;
// Only GNU like compilers support `--print-sysroot`
if !compiler.is_like_gnu() {
return Ok(PathBuf::from("/"));
}
let path = compiler.path();
let out = Command::new(path)
.arg("--print-sysroot")
Expand Down

0 comments on commit 69d9459

Please sign in to comment.