Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn main() {
eprintln!("{prefix} libdir: {libdir:?}");
}

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

let start = Instant::now();
let (child, status) = {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ fn main() {
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
// We also declare that the flag is expected, which we need to do to not
// get warnings about it being unexpected.
if stage == "0" {
if stage == 0 {
cmd.arg("--cfg=bootstrap");
}

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

if verbose > 1 {
eprintln!(
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn clean_specific_stage(build: &Build, stage: u32) {

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

// if current entry is not related with the target stage, continue
if !entry.file_name().to_str().unwrap_or("").contains(&stage_prefix) {
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ pub(crate) fn get_tool_target_compiler(
/// tools directory.
fn copy_link_tool_bin(
builder: &Builder<'_>,
compiler: Compiler,
build_compiler: Compiler,
target: TargetSelection,
mode: Mode,
name: &str,
) -> PathBuf {
let cargo_out = builder.cargo_out(compiler, mode, target).join(exe(name, target));
let bin = builder.tools_dir(compiler).join(exe(name, target));
let cargo_out = builder.cargo_out(build_compiler, mode, target).join(exe(name, target));
let bin = builder.tools_dir(build_compiler).join(exe(name, target));
builder.copy_link(&cargo_out, &bin, FileType::Executable);
bin
}
Expand Down
23 changes: 14 additions & 9 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,14 +859,17 @@ impl Build {
if self.config.rust_optimize.is_release() { "release" } else { "debug" }
}

fn tools_dir(&self, compiler: Compiler) -> PathBuf {
let out = self.out.join(compiler.host).join(format!("stage{}-tools-bin", compiler.stage));
fn tools_dir(&self, build_compiler: Compiler) -> PathBuf {
let out = self
.out
.join(build_compiler.host)
.join(format!("stage{}-tools-bin", build_compiler.stage + 1));
t!(fs::create_dir_all(&out));
out
}

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

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

/// Root output directory of LLVM for `target`
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/src/utils/shared_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ pub fn parse_rustc_verbose() -> usize {
}

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