Skip to content

Commit

Permalink
allow specifying rustc when generating target information (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- authored Feb 4, 2025
1 parent 29431fa commit 4990d4b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
23 changes: 15 additions & 8 deletions dev-tools/gen-target-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>()
.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
Expand Down
16 changes: 8 additions & 8 deletions dev-tools/gen-target-info/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> 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());

Expand Down

0 comments on commit 4990d4b

Please sign in to comment.