Skip to content

Commit a279ba4

Browse files
committed
Consolidate stageN directories in the build directory
Now stageN-X corresponds to stage N X, as it should.
1 parent a153133 commit a279ba4

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

src/bootstrap/src/bin/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn main() {
258258
eprintln!("{prefix} libdir: {libdir:?}");
259259
}
260260

261-
maybe_dump(format!("stage{stage}-rustc"), &cmd);
261+
maybe_dump(format!("stage{}-rustc", stage + 1), &cmd);
262262

263263
let start = Instant::now();
264264
let (child, status) = {

src/bootstrap/src/bin/rustdoc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ fn main() {
5656
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
5757
// We also declare that the flag is expected, which we need to do to not
5858
// get warnings about it being unexpected.
59-
if stage == "0" {
59+
if stage == 0 {
6060
cmd.arg("--cfg=bootstrap");
6161
}
6262

63-
maybe_dump(format!("stage{stage}-rustdoc"), &cmd);
63+
maybe_dump(format!("stage{}-rustdoc", stage + 1), &cmd);
6464

6565
if verbose > 1 {
6666
eprintln!(

src/bootstrap/src/core/build_steps/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn clean_specific_stage(build: &Build, stage: u32) {
129129

130130
for entry in entries {
131131
let entry = t!(entry);
132-
let stage_prefix = format!("stage{stage}");
132+
let stage_prefix = format!("stage{}", stage + 1);
133133

134134
// if current entry is not related with the target stage, continue
135135
if !entry.file_name().to_str().unwrap_or("").contains(&stage_prefix) {

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ pub(crate) fn get_tool_target_compiler(
380380
/// tools directory.
381381
fn copy_link_tool_bin(
382382
builder: &Builder<'_>,
383-
compiler: Compiler,
383+
build_compiler: Compiler,
384384
target: TargetSelection,
385385
mode: Mode,
386386
name: &str,
387387
) -> PathBuf {
388-
let cargo_out = builder.cargo_out(compiler, mode, target).join(exe(name, target));
389-
let bin = builder.tools_dir(compiler).join(exe(name, target));
388+
let cargo_out = builder.cargo_out(build_compiler, mode, target).join(exe(name, target));
389+
let bin = builder.tools_dir(build_compiler).join(exe(name, target));
390390
builder.copy_link(&cargo_out, &bin, FileType::Executable);
391391
bin
392392
}

src/bootstrap/src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,17 @@ impl Build {
859859
if self.config.rust_optimize.is_release() { "release" } else { "debug" }
860860
}
861861

862-
fn tools_dir(&self, compiler: Compiler) -> PathBuf {
863-
let out = self.out.join(compiler.host).join(format!("stage{}-tools-bin", compiler.stage));
862+
fn tools_dir(&self, build_compiler: Compiler) -> PathBuf {
863+
let out = self
864+
.out
865+
.join(build_compiler.host)
866+
.join(format!("stage{}-tools-bin", build_compiler.stage + 1));
864867
t!(fs::create_dir_all(&out));
865868
out
866869
}
867870

868871
/// Returns the root directory for all output generated in a particular
869-
/// stage when running with a particular host compiler.
872+
/// stage when being built with a particular build compiler.
870873
///
871874
/// The mode indicates what the root directory is for.
872875
fn stage_out(&self, build_compiler: Compiler, mode: Mode) -> PathBuf {
@@ -876,15 +879,17 @@ impl Build {
876879
(None, "bootstrap-tools")
877880
}
878881
fn staged_tool(build_compiler: Compiler) -> (Option<u32>, &'static str) {
879-
(Some(build_compiler.stage), "tools")
882+
(Some(build_compiler.stage + 1), "tools")
880883
}
881884

882885
let (stage, suffix) = match mode {
886+
// Std is special, stage N std is built with stage N rustc
883887
Mode::Std => (Some(build_compiler.stage), "std"),
884-
Mode::Rustc => (Some(build_compiler.stage), "rustc"),
885-
Mode::Codegen => (Some(build_compiler.stage), "codegen"),
888+
// The rest of things are built with stage N-1 rustc
889+
Mode::Rustc => (Some(build_compiler.stage + 1), "rustc"),
890+
Mode::Codegen => (Some(build_compiler.stage + 1), "codegen"),
886891
Mode::ToolBootstrap => bootstrap_tool(),
887-
Mode::ToolStd | Mode::ToolRustc => (Some(build_compiler.stage), "tools"),
892+
Mode::ToolStd | Mode::ToolRustc => (Some(build_compiler.stage + 1), "tools"),
888893
Mode::ToolTarget => {
889894
// If we're not cross-compiling (the common case), share the target directory with
890895
// bootstrap tools to reuse the build cache.
@@ -907,8 +912,8 @@ impl Build {
907912
/// Returns the root output directory for all Cargo output in a given stage,
908913
/// running a particular compiler, whether or not we're building the
909914
/// standard library, and targeting the specified architecture.
910-
fn cargo_out(&self, compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf {
911-
self.stage_out(compiler, mode).join(target).join(self.cargo_dir())
915+
fn cargo_out(&self, build_compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf {
916+
self.stage_out(build_compiler, mode).join(target).join(self.cargo_dir())
912917
}
913918

914919
/// Root output directory of LLVM for `target`

src/bootstrap/src/utils/shared_helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ pub fn parse_rustc_verbose() -> usize {
8181
}
8282

8383
/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
84+
/// This is the stage of the *build compiler*, which we are wrapping using a rustc/rustdoc wrapper.
8485
///
8586
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
86-
pub fn parse_rustc_stage() -> String {
87-
env::var("RUSTC_STAGE").unwrap_or_else(|_| {
87+
pub fn parse_rustc_stage() -> u32 {
88+
env::var("RUSTC_STAGE").ok().and_then(|v| v.parse().ok()).unwrap_or_else(|| {
8889
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
8990
eprintln!("rustc shim: FATAL: RUSTC_STAGE was not set");
9091
eprintln!("rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap");

0 commit comments

Comments
 (0)