diff --git a/dev-tools/gen-target-info/src/main.rs b/dev-tools/gen-target-info/src/main.rs index aafe9992a..383d2920d 100644 --- a/dev-tools/gen-target-info/src/main.rs +++ b/dev-tools/gen-target-info/src/main.rs @@ -84,15 +84,22 @@ fn generate_target_mapping(f: &mut File, target_specs: &RustcTargetSpecs) -> std fn main() { // Primarily use information from nightly. - let mut target_specs = get_target_specs_from_json(); + let mut target_specs = get_target_specs_from_json(std::env::var("RUSTC").ok()); // Next, read from MSRV to support old, removed targets. - for target_triple in get_targets_msrv().lines() { - let target_triple = target_triple.unwrap(); - let target_triple = target_triple.trim(); - target_specs - .0 - .entry(target_triple.to_string()) - .or_insert_with(|| get_target_spec_from_msrv(target_triple)); + if std::env::var("CC_RS_MSRV") + .unwrap_or("1".to_string()) + .parse::() + .unwrap() + != 0 + { + for target_triple in get_targets_msrv().lines() { + let target_triple = target_triple.unwrap(); + let target_triple = target_triple.trim(); + target_specs + .0 + .entry(target_triple.to_string()) + .or_insert_with(|| get_target_spec_from_msrv(target_triple)); + } } // Open file to write to diff --git a/dev-tools/gen-target-info/src/read.rs b/dev-tools/gen-target-info/src/read.rs index c5c81f504..4e61b2e98 100644 --- a/dev-tools/gen-target-info/src/read.rs +++ b/dev-tools/gen-target-info/src/read.rs @@ -40,14 +40,14 @@ pub fn get_target_spec_from_msrv(target: &str) -> TargetSpec { serde_json::from_slice(&stdout).unwrap() } -pub fn get_target_specs_from_json() -> RustcTargetSpecs { - let mut cmd = process::Command::new("rustc"); - cmd.args([ - "+nightly", - "-Zunstable-options", - "--print", - "all-target-specs-json", - ]); +pub fn get_target_specs_from_json(rustc: Option) -> RustcTargetSpecs { + let mut cmd = process::Command::new(rustc.clone().unwrap_or("rustc".into())); + + if rustc.is_none() { + cmd.arg("+nightly"); + } + + cmd.args(["-Zunstable-options", "--print", "all-target-specs-json"]); cmd.stdout(process::Stdio::piped()); cmd.stderr(process::Stdio::inherit());