Skip to content

Commit d39a8b0

Browse files
authored
Rollup merge of rust-lang#119619 - onur-ozkan:panic-abort-mir-opt, r=oli-obk
mir-opt and custom target fixes From rust-lang#115642 (comment) > > Could you please test the last two commits from https://github.com/onur-ozkan/rust/commits/panic-abort-mir-opt when you have the time? The first commit should resolve the error of using the nightly flag with a stable compiler, and the second one should resolve the custom target issue. > I tested with the two commits and the errors of using nightly flag and custom target specs were not seen. Testing was completed for the test suites like ui, run-pass-valgrind, coverage, mir-opt, codegen, assembly, incremental. Fixes rust-lang#115642
2 parents b6d9423 + b888e2f commit d39a8b0

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

src/bootstrap/src/core/build_steps/synthetic_targets.rs

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ fn create_synthetic_target(
5959
let mut cmd = Command::new(builder.rustc(compiler));
6060
cmd.arg("--target").arg(base.rustc_target_arg());
6161
cmd.args(["-Zunstable-options", "--print", "target-spec-json"]);
62+
63+
// If `rust.channel` is set to either beta or stable, rustc will complain that
64+
// we cannot use nightly features. So `RUSTC_BOOTSTRAP` is needed here.
65+
cmd.env("RUSTC_BOOTSTRAP", "1");
66+
6267
cmd.stdout(Stdio::piped());
6368

6469
let output = cmd.spawn().unwrap().wait_with_output().unwrap();

src/bootstrap/src/core/build_steps/test.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,13 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
15961596
// NOTE: Only stage 1 is special cased because we need the rustc_private artifacts to match the
15971597
// running compiler in stage 2 when plugins run.
15981598
let stage_id = if suite == "ui-fulldeps" && compiler.stage == 1 {
1599-
compiler = builder.compiler(compiler.stage - 1, target);
1600-
format!("stage{}-{}", compiler.stage + 1, target)
1599+
// At stage 0 (stage - 1) we are using the beta compiler. Using `self.target` can lead finding
1600+
// an incorrect compiler path on cross-targets, as the stage 0 beta compiler is always equal
1601+
// to `build.build` in the configuration.
1602+
let build = builder.build.build;
1603+
1604+
compiler = builder.compiler(compiler.stage - 1, build);
1605+
format!("stage{}-{}", compiler.stage + 1, build)
16011606
} else {
16021607
format!("stage{}-{}", compiler.stage, target)
16031608
};

src/tools/compiletest/src/common.rs

+33-12
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ impl TargetCfgs {
483483
let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&rustc_output(
484484
config,
485485
&["--print=all-target-specs-json", "-Zunstable-options"],
486+
Default::default(),
486487
))
487488
.unwrap();
488489

@@ -495,16 +496,33 @@ impl TargetCfgs {
495496
let mut all_families = HashSet::new();
496497
let mut all_pointer_widths = HashSet::new();
497498

498-
// Handle custom target specs, which are not included in `--print=all-target-specs-json`.
499-
if config.target.ends_with(".json") {
500-
targets.insert(
501-
config.target.clone(),
502-
serde_json::from_str(&rustc_output(
503-
config,
504-
&["--print=target-spec-json", "-Zunstable-options", "--target", &config.target],
505-
))
506-
.unwrap(),
507-
);
499+
// If current target is not included in the `--print=all-target-specs-json` output,
500+
// we check whether it is a custom target from the user or a synthetic target from bootstrap.
501+
if !targets.contains_key(&config.target) {
502+
let mut envs: HashMap<String, String> = HashMap::new();
503+
504+
if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
505+
envs.insert("RUST_TARGET_PATH".into(), t);
506+
}
507+
508+
// This returns false only when the target is neither a synthetic target
509+
// nor a custom target from the user, indicating it is most likely invalid.
510+
if config.target.ends_with(".json") || !envs.is_empty() {
511+
targets.insert(
512+
config.target.clone(),
513+
serde_json::from_str(&rustc_output(
514+
config,
515+
&[
516+
"--print=target-spec-json",
517+
"-Zunstable-options",
518+
"--target",
519+
&config.target,
520+
],
521+
envs,
522+
))
523+
.unwrap(),
524+
);
525+
}
508526
}
509527

510528
for (target, cfg) in targets.iter() {
@@ -549,7 +567,9 @@ impl TargetCfgs {
549567
// code below extracts them from `--print=cfg`: make sure to only override fields that can
550568
// actually be changed with `-C` flags.
551569
for config in
552-
rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines()
570+
rustc_output(config, &["--print=cfg", "--target", &config.target], Default::default())
571+
.trim()
572+
.lines()
553573
{
554574
let (name, value) = config
555575
.split_once("=\"")
@@ -628,11 +648,12 @@ pub enum Endian {
628648
Big,
629649
}
630650

631-
fn rustc_output(config: &Config, args: &[&str]) -> String {
651+
fn rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String {
632652
let mut command = Command::new(&config.rustc_path);
633653
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
634654
command.args(&config.target_rustcflags).args(args);
635655
command.env("RUSTC_BOOTSTRAP", "1");
656+
command.envs(envs);
636657

637658
let output = match command.output() {
638659
Ok(output) => output,

0 commit comments

Comments
 (0)