Fallback to unknown vendor with vendored target triples#55368
Fallback to unknown vendor with vendored target triples#55368zachreizner wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @japaric |
|
Ping from triage @japaric: This PR requires your review. |
|
r? @dtolnay David has volunteered to take a look at this. |
When a target triple is searched for, only exact matches with be returned. This change will fallback to an "unknown" vendor in the target triple if one with the specific vendor can not be found.
| return Ok(t) | ||
| }, | ||
| )+ | ||
| _ => Err(format!("Unable to find target: {}", target)) |
There was a problem hiding this comment.
I believe this would break anyone currently successfully using a non-unknown vendor with their own JSON target file. The code before would use their JSON file. The new code would prefer the corresponding builtin target with unknown vendor while ignoring their JSON file.
rust/src/librustc_target/spec/mod.rs
Lines 1101 to 1122 in cc4999e
I think the fallback to unknown would be more appropriate if applies only after an exact match JSON file has not been found.
| } | ||
| let mut triple: Vec<&str> = target.splitn(3, '-').collect(); | ||
| if triple.len() >= 3 { | ||
| if triple[1] != "unknown" { |
There was a problem hiding this comment.
I would write this as:
if triple.len() >= 3 && triple[1] != "unknown" {| let mut triple: Vec<&str> = target.splitn(3, '-').collect(); | ||
| if triple.len() >= 3 { | ||
| if triple[1] != "unknown" { | ||
| triple[1] = "unknown"; |
There was a problem hiding this comment.
Please add an explanation of what triple[1] represents and why this fallback makes sense. Right now it requires reading the PR description and linked issue to understand what is going on. For example just from the code it isn't clear why there wouldn't also be a fallback for triple[2] being unknown.
| if triple.len() >= 3 { | ||
| if triple[1] != "unknown" { | ||
| triple[1] = "unknown"; | ||
| return load_specific(&triple.join("-")) |
There was a problem hiding this comment.
Please add a test. Possibly as simple as:
#[test]
fn test_load_specific() {
let cros_target = load_specific("x86_64-cros-linux-gnu").unwrap();
assert_eq!(cros_target.llvm_target, "x86_64-unknown-linux-gnu");
}|
Ping from triage @zachreizner: It looks like some changes have been requested to this PR. |
|
I've been talking it over with an expert in the murky field of target triples and I'm not sure the solution I've started in this PR is the best way forward. It's a band-aid solution that isn't quite right, but happens to work. The proper solution would be to replicate the behavior from |
When a target triple is searched for, only exact matches with be
returned. This change will fallback to an "unknown" vendor in the
target triple if one with the specific vendor can not be found.
This helps with #41402.