Skip to content

Commit f732c37

Browse files
committed
Auto merge of rust-lang#119861 - cuviper:beta-next, r=cuviper
[beta] backports - mir-opt and custom target fixes rust-lang#119619 - Update LLVM submodule rust-lang#119802 r? ghost
2 parents 7bcd95c + 5539d3f commit f732c37

File tree

4 files changed

+46
-15
lines changed

4 files changed

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

src/tools/compiletest/src/common.rs

+33-12
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ impl TargetCfgs {
479479
let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&rustc_output(
480480
config,
481481
&["--print=all-target-specs-json", "-Zunstable-options"],
482+
Default::default(),
482483
))
483484
.unwrap();
484485

@@ -491,16 +492,33 @@ impl TargetCfgs {
491492
let mut all_families = HashSet::new();
492493
let mut all_pointer_widths = HashSet::new();
493494

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

506524
for (target, cfg) in targets.iter() {
@@ -545,7 +563,9 @@ impl TargetCfgs {
545563
// code below extracts them from `--print=cfg`: make sure to only override fields that can
546564
// actually be changed with `-C` flags.
547565
for config in
548-
rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines()
566+
rustc_output(config, &["--print=cfg", "--target", &config.target], Default::default())
567+
.trim()
568+
.lines()
549569
{
550570
let (name, value) = config
551571
.split_once("=\"")
@@ -624,11 +644,12 @@ pub enum Endian {
624644
Big,
625645
}
626646

627-
fn rustc_output(config: &Config, args: &[&str]) -> String {
647+
fn rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String {
628648
let mut command = Command::new(&config.rustc_path);
629649
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
630650
command.args(&config.target_rustcflags).args(args);
631651
command.env("RUSTC_BOOTSTRAP", "1");
652+
command.envs(envs);
632653

633654
let output = match command.output() {
634655
Ok(output) => output,

0 commit comments

Comments
 (0)