use --print=all-target-specs-json for stage1+

This commit is contained in:
Pietro Albini 2023-03-09 17:14:25 +01:00
parent 0e6d2053b4
commit c075691b82
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E

View File

@ -9,9 +9,9 @@
use crate::util::{add_dylib_path, PathBufExt};
use lazycell::LazyCell;
use std::collections::HashSet;
use test::{ColorConfig, OutputFormat};
use serde::de::{Deserialize, Deserializer, Error as _};
use std::collections::{HashMap, HashSet};
use test::{ColorConfig, OutputFormat};
macro_rules! string_enum {
($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
@ -410,8 +410,17 @@ pub struct TargetCfgs {
impl TargetCfgs {
fn new(config: &Config) -> TargetCfgs {
// Gather list of all targets
let targets = rustc_output(config, &["--print=target-list"]);
let targets: HashMap<String, TargetCfg> = if config.stage_id.starts_with("stage0-") {
// #[cfg(bootstrap)]
// Needed only for one cycle, remove during the bootstrap bump.
Self::collect_all_slow(config)
} else {
serde_json::from_str(&rustc_output(
config,
&["--print=all-target-specs-json", "-Zunstable-options"],
))
.unwrap()
};
let mut current = None;
let mut all_targets = HashSet::new();
@ -422,9 +431,7 @@ fn new(config: &Config) -> TargetCfgs {
let mut all_families = HashSet::new();
let mut all_pointer_widths = HashSet::new();
for target in targets.trim().lines() {
let cfg = TargetCfg::new(config, target);
for (target, cfg) in targets.into_iter() {
all_archs.insert(cfg.arch.clone());
all_oses.insert(cfg.os.clone());
all_envs.insert(cfg.env.clone());
@ -451,6 +458,25 @@ fn new(config: &Config) -> TargetCfgs {
all_pointer_widths,
}
}
// #[cfg(bootstrap)]
// Needed only for one cycle, remove during the bootstrap bump.
fn collect_all_slow(config: &Config) -> HashMap<String, TargetCfg> {
let mut result = HashMap::new();
for target in rustc_output(config, &["--print=target-list"]).trim().lines() {
let json = rustc_output(
config,
&["--print=target-spec-json", "-Zunstable-options", "--target", target],
);
match serde_json::from_str(&json) {
Ok(res) => {
result.insert(target.into(), res);
}
Err(err) => panic!("failed to parse target spec for {target}: {err}"),
}
}
result
}
}
#[derive(Clone, Debug, serde::Deserialize)]
@ -481,19 +507,6 @@ pub enum Endian {
Big,
}
impl TargetCfg {
fn new(config: &Config, target: &str) -> TargetCfg {
let json = rustc_output(
config,
&["--print=target-spec-json", "-Zunstable-options", "--target", target],
);
match serde_json::from_str(&json) {
Ok(res) => res,
Err(err) => panic!("failed to parse target spec for {target}: {err}"),
}
}
}
fn rustc_output(config: &Config, args: &[&str]) -> String {
let mut command = Command::new(&config.rustc_path);
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));