Skip to content

Commit

Permalink
use host defaults for can_run target triple
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Oct 27, 2021
1 parent 26aa469 commit cabb3e6
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,25 @@ impl TargetTriple {
// Otherwise we need to parse things
let partial_self = PartialTargetTriple::new(&self.0)
.ok_or_else(|| anyhow!(format!("Unable to parse target triple: {}", self.0)))?;
let partial_other = PartialTargetTriple::new(&other.0)
let mut partial_other = PartialTargetTriple::new(&other.0)
.ok_or_else(|| anyhow!(format!("Unable to parse target triple: {}", other.0)))?;
// First obvious check is OS, if that doesn't match then we know it
// can't run unless an OS isn't specified
let ret = if partial_self.os != partial_other.os && partial_other.os.is_some() {

// Default to host for missing target triple values
if partial_other.arch.is_none() {
partial_other.arch = partial_self.clone().arch;
}
if partial_other.os.is_none() {
partial_other.os = partial_self.clone().os;
}
if partial_other.env.is_none() {
partial_other.env = partial_self.clone().env;
}

// Check if the other triple with host defaults applied matches
let ret = if partial_self == partial_other {
true
} else if partial_self.os != partial_other.os {
// Then check OS, if that doesn't match there's no chance
false
} else if partial_self.os.as_deref() == Some("pc-windows") {
// Windows is a special case here, we know we can run 32bit on 64bit
Expand All @@ -336,8 +350,8 @@ impl TargetTriple {
|| (partial_self.arch.as_deref() == Some("x86_64")
&& partial_other.arch.as_deref() == Some("i686"))
} else {
// For other OSes, for now, we assume other toolchains won't run if an OS is specified
partial_other.os.is_none()
// For other OSes, for now, we assume other toolchains won't run
false
};
Ok(ret)
}
Expand Down

0 comments on commit cabb3e6

Please sign in to comment.