-
Notifications
You must be signed in to change notification settings - Fork 14k
Use rustc target metadata for build-manifest target lists #148983
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,7 @@ tar = "0.4.29" | |
| sha2 = "0.10.1" | ||
| rayon = "1.5.1" | ||
| hex = "0.4.2" | ||
|
|
||
| [build-dependencies] | ||
| serde = "1" | ||
| serde_json = "1" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use std::fmt::Write; | ||
| use std::path::PathBuf; | ||
| use std::process::{Command, Stdio}; | ||
|
|
||
| #[derive(Default, Debug)] | ||
| pub(crate) struct RustcTargets { | ||
| /// Targets with host tool artifacts. | ||
| pub(crate) hosts: Vec<String>, | ||
|
|
||
| /// All targets we distribute some artifacts for (superset of `hosts`). | ||
| pub(crate) targets: Vec<String>, | ||
| } | ||
|
|
||
| fn collect_rustc_targets() -> RustcTargets { | ||
| let rustc_path = std::env::var("RUSTC").expect("RUSTC set"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this using the stage1 compiler rather than the bootstrap compiler? Doesn't bootstrap use the bootstrap compiler when building build scripts and proc macros for the host? I believe it checks for the presence of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I definitely see differences when editing the in-tree sources so I don't think that's the case? E.g., the diff above would be different if it was using the bootstrap compiler, it wouldn't reflect rustc_target changes made here. I'll try to poke at bootstrap to see whether there's something possibly broken there in a different local configuration or something though.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, we only do that in Mode::Std: https://github.com/Mark-Simulacrum/rust/blob/7ee4357dd16d3b2170bfa7bbebfb51af08d31577/src/bootstrap/src/core/builder/cargo.rs#L1069 So this shouldn't be an issue here.
Kobzol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let output = Command::new(&rustc_path) | ||
| .arg("--print=all-target-specs-json") | ||
| .env("RUSTC_BOOTSTRAP", "1") | ||
| .arg("-Zunstable-options") | ||
| .stderr(Stdio::inherit()) | ||
| .output() | ||
| .unwrap(); | ||
| assert!(output.status.success()); | ||
| let json: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap(); | ||
|
|
||
| let mut rustc_targets = RustcTargets::default(); | ||
| for (target, json) in json.as_object().unwrap().iter() { | ||
| let Some(tier) = json["metadata"]["tier"].as_u64() else { | ||
| eprintln!("skipping {target}: no tier in metadata"); | ||
| continue; | ||
| }; | ||
| let host_tools: Option<bool> = | ||
| serde_json::from_value(json["metadata"]["host_tools"].clone()).unwrap(); | ||
|
|
||
| if !(tier == 1 || tier == 2) { | ||
| eprintln!("ignoring {target}: tier {tier} insufficient for target to be in manifest"); | ||
| continue; | ||
| } | ||
|
|
||
| if host_tools == Some(true) { | ||
| rustc_targets.hosts.push(target.to_owned()); | ||
| rustc_targets.targets.push(target.to_owned()); | ||
| } else { | ||
| rustc_targets.targets.push(target.to_owned()); | ||
| } | ||
| } | ||
|
|
||
| rustc_targets | ||
| } | ||
|
|
||
| fn main() { | ||
| let targets = collect_rustc_targets(); | ||
Kobzol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Verify we ended up with a reasonable target list. | ||
| assert!(targets.hosts.len() >= 10); | ||
| assert!(targets.targets.len() >= 30); | ||
| assert!(targets.hosts.iter().any(|e| e == "x86_64-unknown-linux-gnu")); | ||
| assert!(targets.targets.iter().any(|e| e == "x86_64-unknown-linux-gnu")); | ||
|
|
||
| let mut output = String::new(); | ||
|
|
||
| writeln!(output, "static HOSTS: &[&str] = &[").unwrap(); | ||
| for host in targets.hosts { | ||
| writeln!(output, " {:?},", host).unwrap(); | ||
| } | ||
| writeln!(output, "];").unwrap(); | ||
|
|
||
| writeln!(output, "static TARGETS: &[&str] = &[").unwrap(); | ||
| for target in targets.targets { | ||
| writeln!(output, " {:?},", target).unwrap(); | ||
| } | ||
| writeln!(output, "];").unwrap(); | ||
|
|
||
| std::fs::write(PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("targets.rs"), output) | ||
| .unwrap(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.