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

Bootstrap: Check validity of --target and --host triples before starting a build #123546

Merged
merged 1 commit into from
Apr 28, 2024
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: 29 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::ffi::{OsStr, OsString};
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use walkdir::WalkDir;

use crate::builder::Kind;
use crate::core::config::Target;
Expand Down Expand Up @@ -177,6 +178,34 @@ than building it.
continue;
}

// Check if there exists a built-in target in the list of supported targets.
let mut has_target = false;
let target_str = target.to_string();

let supported_target_list =
output(Command::new(&build.config.initial_rustc).args(["--print", "target-list"]));
Copy link
Member

@bjorn3 bjorn3 Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said on the associated issue, asking the bootstrap compiler is not correct when bootstrap doesn't know about a target yet, but the in-tree rustc does. You have to check if the target is listed in compiler/rustc_target/src/spec/mod.rs.

Edit: Missed that this was already discussed in #123546 (comment).


has_target |= supported_target_list.contains(&target_str);

// If not, check for a valid file location that may have been specified
// by the user for the custom target.
if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
let mut target_os_str = OsString::from(&target_str);
target_os_str.push(".json");
// Recursively traverse through nested directories.
let walker = WalkDir::new(custom_target_path).into_iter();
for entry in walker.filter_map(|e| e.ok()) {
has_target |= entry.file_name() == target_os_str;
Rajveer100 marked this conversation as resolved.
Show resolved Hide resolved
}
}

if !has_target && !["A", "B", "C"].contains(&target_str.as_str()) {
panic!(
"No such target exists in the target list,
specify a correct location of the JSON specification file for custom targets!"
);
}

if !build.config.dry_run() {
cmd_finder.must_have(build.cc(*target));
if let Some(ar) = build.ar(*target) {
Expand Down
Loading