bootstrap/core/build_steps/
synthetic_targets.rs1use crate::Compiler;
11use crate::core::builder::{Builder, Step};
12use crate::core::config::TargetSelection;
13
14#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15pub(crate) struct MirOptPanicAbortSyntheticTarget {
16 pub(crate) compiler: Compiler,
17 pub(crate) base: TargetSelection,
18}
19
20impl Step for MirOptPanicAbortSyntheticTarget {
21 type Output = TargetSelection;
22
23 fn run(self, builder: &Builder<'_>) -> Self::Output {
24 create_synthetic_target(builder, self.compiler, "miropt-abort", self.base, |spec| {
25 spec.insert("panic-strategy".into(), "abort".into());
26 })
27 }
28}
29
30fn create_synthetic_target(
31 builder: &Builder<'_>,
32 compiler: Compiler,
33 suffix: &str,
34 base: TargetSelection,
35 customize: impl FnOnce(&mut serde_json::Map<String, serde_json::Value>),
36) -> TargetSelection {
37 if base.contains("synthetic") {
38 panic!("cannot create synthetic targets with other synthetic targets as their base");
41 }
42
43 let name = format!("{base}-synthetic-{suffix}");
44 let path = builder.out.join("synthetic-target-specs").join(format!("{name}.json"));
45 std::fs::create_dir_all(path.parent().unwrap()).unwrap();
46
47 if builder.config.dry_run() {
48 std::fs::write(&path, b"dry run\n").unwrap();
49 return TargetSelection::create_synthetic(&name, path.to_str().unwrap());
50 }
51
52 let mut cmd = builder.rustc_cmd(compiler);
53 cmd.arg("--target").arg(base.rustc_target_arg());
54 cmd.args(["-Zunstable-options", "--print", "target-spec-json"]);
55
56 cmd.env("RUSTC_BOOTSTRAP", "1");
59
60 let output = cmd.run_capture(builder).stdout();
61 let mut spec: serde_json::Value = serde_json::from_slice(output.as_bytes()).unwrap();
62 let spec_map = spec.as_object_mut().unwrap();
63
64 spec_map.remove("is-builtin");
66
67 customize(spec_map);
68
69 std::fs::write(&path, serde_json::to_vec_pretty(&spec).unwrap()).unwrap();
70 TargetSelection::create_synthetic(&name, path.to_str().unwrap())
71}