Skip to content

Commit 71ff1c6

Browse files
committed
Auto merge of #121341 - GrigorenkoPV:bootstrap-rustup-cargo, r=onur-ozkan
bootstrap: don't resolve symlinks for initial_cargo I have put the following in my `config.toml`: ```toml # Includes one of the default files in src/bootstrap/defaults profile = "compiler" change-id = 121203 [build] cargo = "/usr/bin/cargo" rustc = "/usr/bin/rustc" rustfmt = "/usr/bin/rustfmt" ``` I have rustup installed from Arch's repos, which has all of the above paths be symlinks to `/usr/bin/rustup`. This works just fine with the `argv[0]` trick that rustup uses. However, `bootstrap` resolves symlinks to check whether `cargo` exists and then uses the resolved path, so it ends up calling `rustup` directly expecting it to behave like `cargo`. Which it doesn't. This PR removes the canonicalization step, in turn fixing the issue, but sacrificing a pretty error message. However, this exact thing is checked by `x.py` in advance, so I hope it is not a big deal?
2 parents a28d221 + c42057f commit 71ff1c6

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

Diff for: src/bootstrap/src/core/config/config.rs

+33-30
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::utils::cache::{Interned, INTERNER};
2222
use crate::utils::channel::{self, GitInfo};
2323
use crate::utils::helpers::{exe, output, t};
2424
use build_helper::exit;
25+
use build_helper::util::fail;
2526
use semver::Version;
2627
use serde::{Deserialize, Deserializer};
2728
use serde_derive::Deserialize;
@@ -1418,19 +1419,23 @@ impl Config {
14181419

14191420
config.initial_rustc = if let Some(rustc) = rustc {
14201421
if !flags.skip_stage0_validation {
1421-
config.check_build_rustc_version(&rustc);
1422+
config.check_stage0_version(&rustc, "rustc");
14221423
}
14231424
PathBuf::from(rustc)
14241425
} else {
14251426
config.download_beta_toolchain();
14261427
config.out.join(config.build.triple).join("stage0/bin/rustc")
14271428
};
14281429

1429-
config.initial_cargo = cargo
1430-
.map(|cargo| {
1431-
t!(PathBuf::from(cargo).canonicalize(), "`initial_cargo` not found on disk")
1432-
})
1433-
.unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/cargo"));
1430+
config.initial_cargo = if let Some(cargo) = cargo {
1431+
if !flags.skip_stage0_validation {
1432+
config.check_stage0_version(&cargo, "cargo");
1433+
}
1434+
PathBuf::from(cargo)
1435+
} else {
1436+
config.download_beta_toolchain();
1437+
config.out.join(config.build.triple).join("stage0/bin/cargo")
1438+
};
14341439

14351440
// NOTE: it's important this comes *after* we set `initial_rustc` just above.
14361441
if config.dry_run() {
@@ -2286,39 +2291,37 @@ impl Config {
22862291
}
22872292
}
22882293

2289-
pub fn check_build_rustc_version(&self, rustc_path: &str) {
2294+
// check rustc/cargo version is same or lower with 1 apart from the building one
2295+
pub fn check_stage0_version(&self, program_path: &str, component_name: &'static str) {
22902296
if self.dry_run() {
22912297
return;
22922298
}
22932299

2294-
// check rustc version is same or lower with 1 apart from the building one
2295-
let mut cmd = Command::new(rustc_path);
2296-
cmd.arg("--version");
2297-
let rustc_output = output(&mut cmd)
2298-
.lines()
2299-
.next()
2300-
.unwrap()
2301-
.split(' ')
2302-
.nth(1)
2303-
.unwrap()
2304-
.split('-')
2305-
.next()
2306-
.unwrap()
2307-
.to_owned();
2308-
let rustc_version = Version::parse(rustc_output.trim()).unwrap();
2300+
let stage0_output = output(Command::new(program_path).arg("--version"));
2301+
let mut stage0_output = stage0_output.lines().next().unwrap().split(' ');
2302+
2303+
let stage0_name = stage0_output.next().unwrap();
2304+
if stage0_name != component_name {
2305+
fail(&format!(
2306+
"Expected to find {component_name} at {program_path} but it claims to be {stage0_name}"
2307+
));
2308+
}
2309+
2310+
let stage0_version =
2311+
Version::parse(stage0_output.next().unwrap().split('-').next().unwrap().trim())
2312+
.unwrap();
23092313
let source_version =
23102314
Version::parse(fs::read_to_string(self.src.join("src/version")).unwrap().trim())
23112315
.unwrap();
2312-
if !(source_version == rustc_version
2313-
|| (source_version.major == rustc_version.major
2314-
&& (source_version.minor == rustc_version.minor
2315-
|| source_version.minor == rustc_version.minor + 1)))
2316+
if !(source_version == stage0_version
2317+
|| (source_version.major == stage0_version.major
2318+
&& (source_version.minor == stage0_version.minor
2319+
|| source_version.minor == stage0_version.minor + 1)))
23162320
{
23172321
let prev_version = format!("{}.{}.x", source_version.major, source_version.minor - 1);
2318-
eprintln!(
2319-
"Unexpected rustc version: {rustc_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
2320-
);
2321-
exit!(1);
2322+
fail(&format!(
2323+
"Unexpected {component_name} version: {stage0_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
2324+
));
23222325
}
23232326
}
23242327

0 commit comments

Comments
 (0)