Auto merge of #145295 - Kobzol:unify-stages, r=jieyouxu

Consolidate stage directories and group logs in bootstrap

My post-stage-0-redesign bootstrap fixes aren't done yet, but I think that enough steps have been migrated to the new system that it makes sense to actually modify the directories on disk, and what gets printed when bootstrap runs, so that it actually corresponds to the new system. Before, the printed stages didn't always make sense.

This PR:
- Fixes the numbering of `stageN` directories in the build directory. It was not corresponding to the correct stages before; notice that I did not modify `bootstrap/README.md`, as it was essentially describing what happens after this PR (first commit).
- Unifies all steps that output a build group to use the `Builder::msg` method. It's probably not the final stage, and some of the test steps might not be fully accurate yet, because I didn't fix test step numbering yet, but I think that it's a clear improvement from before, and now that everything uses the same method, we can easily make changes across the board, to ensure that it stays unified (second commit).

r? `@jieyouxu`

try-job: dist-x86_64-msvc
try-job: dist-x86_64-linux
This commit is contained in:
bors 2025-08-12 21:06:10 +00:00
commit 1553adfe68
18 changed files with 241 additions and 266 deletions

View file

@ -258,7 +258,7 @@ fn main() {
eprintln!("{prefix} libdir: {libdir:?}"); eprintln!("{prefix} libdir: {libdir:?}");
} }
maybe_dump(format!("stage{stage}-rustc"), &cmd); maybe_dump(format!("stage{}-rustc", stage + 1), &cmd);
let start = Instant::now(); let start = Instant::now();
let (child, status) = { let (child, status) = {

View file

@ -56,11 +56,11 @@ fn main() {
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`. // 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 // We also declare that the flag is expected, which we need to do to not
// get warnings about it being unexpected. // get warnings about it being unexpected.
if stage == "0" { if stage == 0 {
cmd.arg("--cfg=bootstrap"); cmd.arg("--cfg=bootstrap");
} }
maybe_dump(format!("stage{stage}-rustdoc"), &cmd); maybe_dump(format!("stage{}-rustdoc", stage + 1), &cmd);
if verbose > 1 { if verbose > 1 {
eprintln!( eprintln!(

View file

@ -72,7 +72,6 @@ impl Step for Std {
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let build_compiler = self.build_compiler; let build_compiler = self.build_compiler;
let stage = build_compiler.stage;
let target = self.target; let target = self.target;
let mut cargo = builder::Cargo::new( let mut cargo = builder::Cargo::new(
@ -94,10 +93,12 @@ impl Step for Std {
cargo.arg("-p").arg(krate); cargo.arg("-p").arg(krate);
} }
let _guard = builder.msg_check( let _guard = builder.msg(
Kind::Check,
format_args!("library artifacts{}", crate_description(&self.crates)), format_args!("library artifacts{}", crate_description(&self.crates)),
Mode::Std,
self.build_compiler,
target, target,
Some(stage),
); );
let stamp = build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check"); let stamp = build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check");
@ -136,7 +137,13 @@ impl Step for Std {
let stamp = let stamp =
build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check-test"); build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check-test");
let _guard = builder.msg_check("library test/bench/example targets", target, Some(stage)); let _guard = builder.msg(
Kind::Check,
"library test/bench/example targets",
Mode::Std,
self.build_compiler,
target,
);
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
} }
@ -227,10 +234,12 @@ impl Step for Rustc {
cargo.arg("-p").arg(krate); cargo.arg("-p").arg(krate);
} }
let _guard = builder.msg_check( let _guard = builder.msg(
Kind::Check,
format_args!("compiler artifacts{}", crate_description(&self.crates)), format_args!("compiler artifacts{}", crate_description(&self.crates)),
Mode::Rustc,
self.build_compiler,
target, target,
None,
); );
let stamp = let stamp =
@ -357,7 +366,13 @@ impl Step for CodegenBackend {
.arg(builder.src.join(format!("compiler/{}/Cargo.toml", backend.crate_name()))); .arg(builder.src.join(format!("compiler/{}/Cargo.toml", backend.crate_name())));
rustc_cargo_env(builder, &mut cargo, target); rustc_cargo_env(builder, &mut cargo, target);
let _guard = builder.msg_check(backend.crate_name(), target, None); let _guard = builder.msg(
Kind::Check,
backend.crate_name(),
Mode::Codegen,
self.build_compiler,
target,
);
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend) let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend)
.with_prefix("check"); .with_prefix("check");
@ -482,14 +497,7 @@ fn run_tool_check_step(
let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, mode, target)) let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, mode, target))
.with_prefix(&format!("{display_name}-check")); .with_prefix(&format!("{display_name}-check"));
let stage = match mode { let _guard = builder.msg(builder.kind, display_name, mode, build_compiler, target);
// Mode::ToolRustc is included here because of how msg_sysroot_tool prints stages
Mode::Std | Mode::ToolRustc => build_compiler.stage,
_ => build_compiler.stage + 1,
};
let _guard =
builder.msg_tool(builder.kind, mode, display_name, stage, &build_compiler.host, &target);
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
} }

View file

@ -129,7 +129,7 @@ fn clean_specific_stage(build: &Build, stage: u32) {
for entry in entries { for entry in entries {
let entry = t!(entry); 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 current entry is not related with the target stage, continue
if !entry.file_name().to_str().unwrap_or("").contains(&stage_prefix) { if !entry.file_name().to_str().unwrap_or("").contains(&stage_prefix) {

View file

@ -143,11 +143,11 @@ impl Step for Std {
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let target = self.target; let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.host_target); let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target);
let mut cargo = builder::Cargo::new( let mut cargo = builder::Cargo::new(
builder, builder,
compiler, build_compiler,
Mode::Std, Mode::Std,
SourceType::InTree, SourceType::InTree,
target, target,
@ -160,14 +160,19 @@ impl Step for Std {
cargo.arg("-p").arg(krate); cargo.arg("-p").arg(krate);
} }
let _guard = let _guard = builder.msg(
builder.msg_clippy(format_args!("library{}", crate_description(&self.crates)), target); Kind::Clippy,
format_args!("library{}", crate_description(&self.crates)),
Mode::Std,
build_compiler,
target,
);
run_cargo( run_cargo(
builder, builder,
cargo, cargo,
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC), lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
&build_stamp::libstd_stamp(builder, compiler, target), &build_stamp::libstd_stamp(builder, build_compiler, target),
vec![], vec![],
true, true,
false, false,
@ -203,33 +208,33 @@ impl Step for Rustc {
/// This will lint the compiler for a particular stage of the build using /// This will lint the compiler for a particular stage of the build using
/// the `compiler` targeting the `target` architecture. /// the `compiler` targeting the `target` architecture.
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(builder.top_stage, builder.config.host_target); let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target);
let target = self.target; let target = self.target;
if !builder.download_rustc() { if !builder.download_rustc() {
if compiler.stage != 0 { if build_compiler.stage != 0 {
// If we're not in stage 0, then we won't have a std from the beta // If we're not in stage 0, then we won't have a std from the beta
// compiler around. That means we need to make sure there's one in // compiler around. That means we need to make sure there's one in
// the sysroot for the compiler to find. Otherwise, we're going to // the sysroot for the compiler to find. Otherwise, we're going to
// fail when building crates that need to generate code (e.g., build // fail when building crates that need to generate code (e.g., build
// scripts and their dependencies). // scripts and their dependencies).
builder.std(compiler, compiler.host); builder.std(build_compiler, build_compiler.host);
builder.std(compiler, target); builder.std(build_compiler, target);
} else { } else {
builder.ensure(check::Std::new(compiler, target)); builder.ensure(check::Std::new(build_compiler, target));
} }
} }
let mut cargo = builder::Cargo::new( let mut cargo = builder::Cargo::new(
builder, builder,
compiler, build_compiler,
Mode::Rustc, Mode::Rustc,
SourceType::InTree, SourceType::InTree,
target, target,
Kind::Clippy, Kind::Clippy,
); );
rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates); rustc_cargo(builder, &mut cargo, target, &build_compiler, &self.crates);
// Explicitly pass -p for all compiler crates -- this will force cargo // Explicitly pass -p for all compiler crates -- this will force cargo
// to also lint the tests/benches/examples for these crates, rather // to also lint the tests/benches/examples for these crates, rather
@ -238,14 +243,19 @@ impl Step for Rustc {
cargo.arg("-p").arg(krate); cargo.arg("-p").arg(krate);
} }
let _guard = let _guard = builder.msg(
builder.msg_clippy(format_args!("compiler{}", crate_description(&self.crates)), target); Kind::Clippy,
format_args!("compiler{}", crate_description(&self.crates)),
Mode::Rustc,
build_compiler,
target,
);
run_cargo( run_cargo(
builder, builder,
cargo, cargo,
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC), lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
&build_stamp::librustc_stamp(builder, compiler, target), &build_stamp::librustc_stamp(builder, build_compiler, target),
vec![], vec![],
true, true,
false, false,
@ -284,16 +294,16 @@ macro_rules! lint_any {
} }
fn run(self, builder: &Builder<'_>) -> Self::Output { fn run(self, builder: &Builder<'_>) -> Self::Output {
let compiler = builder.compiler(builder.top_stage, builder.config.host_target); let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target);
let target = self.target; let target = self.target;
if !builder.download_rustc() { if !builder.download_rustc() {
builder.ensure(check::Rustc::new(builder, compiler, target)); builder.ensure(check::Rustc::new(builder, build_compiler, target));
}; };
let cargo = prepare_tool_cargo( let cargo = prepare_tool_cargo(
builder, builder,
compiler, build_compiler,
Mode::ToolRustc, Mode::ToolRustc,
target, target,
Kind::Clippy, Kind::Clippy,
@ -302,17 +312,16 @@ macro_rules! lint_any {
&[], &[],
); );
let _guard = builder.msg_tool( let _guard = builder.msg(
Kind::Clippy, Kind::Clippy,
Mode::ToolRustc,
$readable_name, $readable_name,
compiler.stage, Mode::ToolRustc,
&compiler.host, build_compiler,
&target, target,
); );
let stringified_name = stringify!($name).to_lowercase(); let stringified_name = stringify!($name).to_lowercase();
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target)) let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, Mode::ToolRustc, target))
.with_prefix(&format!("{}-check", stringified_name)); .with_prefix(&format!("{}-check", stringified_name));
run_cargo( run_cargo(

View file

@ -159,7 +159,7 @@ impl Step for Std {
return; return;
} }
let compiler = if builder.download_rustc() && self.force_recompile { let build_compiler = if builder.download_rustc() && self.force_recompile {
// When there are changes in the library tree with CI-rustc, we want to build // When there are changes in the library tree with CI-rustc, we want to build
// the stageN library and that requires using stageN-1 compiler. // the stageN library and that requires using stageN-1 compiler.
builder.compiler(self.compiler.stage.saturating_sub(1), builder.config.host_target) builder.compiler(self.compiler.stage.saturating_sub(1), builder.config.host_target)
@ -173,7 +173,8 @@ impl Step for Std {
&& builder.config.is_host_target(target) && builder.config.is_host_target(target)
&& !self.force_recompile && !self.force_recompile
{ {
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false }); let sysroot =
builder.ensure(Sysroot { compiler: build_compiler, force_recompile: false });
cp_rustc_component_to_ci_sysroot( cp_rustc_component_to_ci_sysroot(
builder, builder,
&sysroot, &sysroot,
@ -182,53 +183,58 @@ impl Step for Std {
return; return;
} }
if builder.config.keep_stage.contains(&compiler.stage) if builder.config.keep_stage.contains(&build_compiler.stage)
|| builder.config.keep_stage_std.contains(&compiler.stage) || builder.config.keep_stage_std.contains(&build_compiler.stage)
{ {
trace!(keep_stage = ?builder.config.keep_stage); trace!(keep_stage = ?builder.config.keep_stage);
trace!(keep_stage_std = ?builder.config.keep_stage_std); trace!(keep_stage_std = ?builder.config.keep_stage_std);
builder.info("WARNING: Using a potentially old libstd. This may not behave well."); builder.info("WARNING: Using a potentially old libstd. This may not behave well.");
builder.ensure(StartupObjects { compiler, target }); builder.ensure(StartupObjects { compiler: build_compiler, target });
self.copy_extra_objects(builder, &compiler, target); self.copy_extra_objects(builder, &build_compiler, target);
builder.ensure(StdLink::from_std(self, compiler)); builder.ensure(StdLink::from_std(self, build_compiler));
return; return;
} }
let mut target_deps = builder.ensure(StartupObjects { compiler, target }); let mut target_deps = builder.ensure(StartupObjects { compiler: build_compiler, target });
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); let compiler_to_use =
builder.compiler_for(build_compiler.stage, build_compiler.host, target);
trace!(?compiler_to_use); trace!(?compiler_to_use);
if compiler_to_use != compiler if compiler_to_use != build_compiler
// Never uplift std unless we have compiled stage 1; if stage 1 is compiled, // Never uplift std unless we have compiled stage 1; if stage 1 is compiled,
// uplift it from there. // uplift it from there.
// //
// FIXME: improve `fn compiler_for` to avoid adding stage condition here. // FIXME: improve `fn compiler_for` to avoid adding stage condition here.
&& compiler.stage > 1 && build_compiler.stage > 1
{ {
trace!(?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library"); trace!(
?compiler_to_use,
?build_compiler,
"build_compiler != compiler_to_use, uplifting library"
);
builder.std(compiler_to_use, target); builder.std(compiler_to_use, target);
let msg = if compiler_to_use.host == target { let msg = if compiler_to_use.host == target {
format!( format!(
"Uplifting library (stage{} -> stage{})", "Uplifting library (stage{} -> stage{})",
compiler_to_use.stage, compiler.stage compiler_to_use.stage, build_compiler.stage
) )
} else { } else {
format!( format!(
"Uplifting library (stage{}:{} -> stage{}:{})", "Uplifting library (stage{}:{} -> stage{}:{})",
compiler_to_use.stage, compiler_to_use.host, compiler.stage, target compiler_to_use.stage, compiler_to_use.host, build_compiler.stage, target
) )
}; };
builder.info(&msg); builder.info(&msg);
// Even if we're not building std this stage, the new sysroot must // Even if we're not building std this stage, the new sysroot must
// still contain the third party objects needed by various targets. // still contain the third party objects needed by various targets.
self.copy_extra_objects(builder, &compiler, target); self.copy_extra_objects(builder, &build_compiler, target);
builder.ensure(StdLink::from_std(self, compiler_to_use)); builder.ensure(StdLink::from_std(self, compiler_to_use));
return; return;
@ -236,11 +242,11 @@ impl Step for Std {
trace!( trace!(
?compiler_to_use, ?compiler_to_use,
?compiler, ?build_compiler,
"compiler == compiler_to_use, handling not-cross-compile scenario" "compiler == compiler_to_use, handling not-cross-compile scenario"
); );
target_deps.extend(self.copy_extra_objects(builder, &compiler, target)); target_deps.extend(self.copy_extra_objects(builder, &build_compiler, target));
// We build a sysroot for mir-opt tests using the same trick that Miri does: A check build // We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the // with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
@ -249,7 +255,7 @@ impl Step for Std {
trace!("building special sysroot for mir-opt tests"); trace!("building special sysroot for mir-opt tests");
let mut cargo = builder::Cargo::new_for_mir_opt_tests( let mut cargo = builder::Cargo::new_for_mir_opt_tests(
builder, builder,
compiler, build_compiler,
Mode::Std, Mode::Std,
SourceType::InTree, SourceType::InTree,
target, target,
@ -262,7 +268,7 @@ impl Step for Std {
trace!("building regular sysroot"); trace!("building regular sysroot");
let mut cargo = builder::Cargo::new( let mut cargo = builder::Cargo::new(
builder, builder,
compiler, build_compiler,
Mode::Std, Mode::Std,
SourceType::InTree, SourceType::InTree,
target, target,
@ -285,16 +291,16 @@ impl Step for Std {
let _guard = builder.msg( let _guard = builder.msg(
Kind::Build, Kind::Build,
compiler.stage,
format_args!("library artifacts{}", crate_description(&self.crates)), format_args!("library artifacts{}", crate_description(&self.crates)),
compiler.host, Mode::Std,
build_compiler,
target, target,
); );
run_cargo( run_cargo(
builder, builder,
cargo, cargo,
vec![], vec![],
&build_stamp::libstd_stamp(builder, compiler, target), &build_stamp::libstd_stamp(builder, build_compiler, target),
target_deps, target_deps,
self.is_for_mir_opt_tests, // is_check self.is_for_mir_opt_tests, // is_check
false, false,
@ -302,7 +308,7 @@ impl Step for Std {
builder.ensure(StdLink::from_std( builder.ensure(StdLink::from_std(
self, self,
builder.compiler(compiler.stage, builder.config.host_target), builder.compiler(build_compiler.stage, builder.config.host_target),
)); ));
} }
@ -1126,11 +1132,11 @@ impl Step for Rustc {
cargo.env("RUSTC_BOLT_LINK_FLAGS", "1"); cargo.env("RUSTC_BOLT_LINK_FLAGS", "1");
} }
let _guard = builder.msg_rustc_tool( let _guard = builder.msg(
Kind::Build, Kind::Build,
build_compiler.stage,
format_args!("compiler artifacts{}", crate_description(&self.crates)), format_args!("compiler artifacts{}", crate_description(&self.crates)),
build_compiler.host, Mode::Rustc,
build_compiler,
target, target,
); );
let stamp = build_stamp::librustc_stamp(builder, build_compiler, target); let stamp = build_stamp::librustc_stamp(builder, build_compiler, target);
@ -1603,13 +1609,8 @@ impl Step for GccCodegenBackend {
let gcc = builder.ensure(Gcc { target }); let gcc = builder.ensure(Gcc { target });
add_cg_gcc_cargo_flags(&mut cargo, &gcc); add_cg_gcc_cargo_flags(&mut cargo, &gcc);
let _guard = builder.msg_rustc_tool( let _guard =
Kind::Build, builder.msg(Kind::Build, "codegen backend gcc", Mode::Codegen, build_compiler, target);
build_compiler.stage,
"codegen backend gcc",
build_compiler.host,
target,
);
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false); let files = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false);
write_codegen_backend_stamp(stamp, files, builder.config.dry_run()) write_codegen_backend_stamp(stamp, files, builder.config.dry_run())
} }
@ -1687,11 +1688,11 @@ impl Step for CraneliftCodegenBackend {
.arg(builder.src.join("compiler/rustc_codegen_cranelift/Cargo.toml")); .arg(builder.src.join("compiler/rustc_codegen_cranelift/Cargo.toml"));
rustc_cargo_env(builder, &mut cargo, target); rustc_cargo_env(builder, &mut cargo, target);
let _guard = builder.msg_rustc_tool( let _guard = builder.msg(
Kind::Build, Kind::Build,
build_compiler.stage,
"codegen backend cranelift", "codegen backend cranelift",
build_compiler.host, Mode::Codegen,
build_compiler,
target, target,
); );
let files = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false); let files = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false);

View file

@ -239,7 +239,7 @@ impl Step for TheBook {
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
builder.require_submodule("src/doc/book", None); builder.require_submodule("src/doc/book", None);
let compiler = self.build_compiler; let build_compiler = self.build_compiler;
let target = self.target; let target = self.target;
let absolute_path = builder.src.join("src/doc/book"); let absolute_path = builder.src.join("src/doc/book");
@ -273,20 +273,20 @@ impl Step for TheBook {
let shared_assets = builder.ensure(SharedAssets { target }); let shared_assets = builder.ensure(SharedAssets { target });
// build the redirect pages // build the redirect pages
let _guard = builder.msg_doc(compiler, "book redirect pages", target); let _guard = builder.msg(Kind::Doc, "book redirect pages", None, build_compiler, target);
for file in t!(fs::read_dir(redirect_path)) { for file in t!(fs::read_dir(redirect_path)) {
let file = t!(file); let file = t!(file);
let path = file.path(); let path = file.path();
let path = path.to_str().unwrap(); let path = path.to_str().unwrap();
invoke_rustdoc(builder, compiler, &shared_assets, target, path); invoke_rustdoc(builder, build_compiler, &shared_assets, target, path);
} }
} }
} }
fn invoke_rustdoc( fn invoke_rustdoc(
builder: &Builder<'_>, builder: &Builder<'_>,
compiler: Compiler, build_compiler: Compiler,
shared_assets: &SharedAssetsPaths, shared_assets: &SharedAssetsPaths,
target: TargetSelection, target: TargetSelection,
markdown: &str, markdown: &str,
@ -298,7 +298,7 @@ fn invoke_rustdoc(
let header = builder.src.join("src/doc/redirect.inc"); let header = builder.src.join("src/doc/redirect.inc");
let footer = builder.src.join("src/doc/footer.inc"); let footer = builder.src.join("src/doc/footer.inc");
let mut cmd = builder.rustdoc_cmd(compiler); let mut cmd = builder.rustdoc_cmd(build_compiler);
let out = out.join("book"); let out = out.join("book");
@ -362,7 +362,7 @@ impl Step for Standalone {
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let target = self.target; let target = self.target;
let build_compiler = self.build_compiler; let build_compiler = self.build_compiler;
let _guard = builder.msg_doc(build_compiler, "standalone", target); let _guard = builder.msg(Kind::Doc, "standalone", None, build_compiler, target);
let out = builder.doc_out(target); let out = builder.doc_out(target);
t!(fs::create_dir_all(&out)); t!(fs::create_dir_all(&out));
@ -469,7 +469,7 @@ impl Step for Releases {
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let target = self.target; let target = self.target;
let build_compiler = self.build_compiler; let build_compiler = self.build_compiler;
let _guard = builder.msg_doc(build_compiler, "releases", target); let _guard = builder.msg(Kind::Doc, "releases", None, build_compiler, target);
let out = builder.doc_out(target); let out = builder.doc_out(target);
t!(fs::create_dir_all(&out)); t!(fs::create_dir_all(&out));
@ -784,7 +784,7 @@ fn doc_std(
let description = let description =
format!("library{} in {} format", crate_description(requested_crates), format.as_str()); format!("library{} in {} format", crate_description(requested_crates), format.as_str());
let _guard = builder.msg_doc(build_compiler, description, target); let _guard = builder.msg(Kind::Doc, description, None, build_compiler, target);
cargo.into_cmd().run(builder); cargo.into_cmd().run(builder);
builder.cp_link_r(&out_dir, out); builder.cp_link_r(&out_dir, out);
@ -861,11 +861,11 @@ impl Step for Rustc {
let build_compiler = self.build_compiler; let build_compiler = self.build_compiler;
builder.std(build_compiler, builder.config.host_target); builder.std(build_compiler, builder.config.host_target);
let _guard = builder.msg_rustc_tool( let _guard = builder.msg(
Kind::Doc, Kind::Doc,
build_compiler.stage,
format!("compiler{}", crate_description(&self.crates)), format!("compiler{}", crate_description(&self.crates)),
build_compiler.host, Mode::Rustc,
build_compiler,
target, target,
); );
@ -1059,7 +1059,7 @@ macro_rules! tool_doc {
let proc_macro_out_dir = builder.stage_out(build_compiler, mode).join("doc"); let proc_macro_out_dir = builder.stage_out(build_compiler, mode).join("doc");
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir); symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
let _guard = builder.msg_doc(build_compiler, stringify!($tool).to_lowercase(), target); let _guard = builder.msg(Kind::Doc, stringify!($tool).to_lowercase(), None, build_compiler, target);
cargo.into_cmd().run(builder); cargo.into_cmd().run(builder);
if !builder.config.dry_run() { if !builder.config.dry_run() {
@ -1314,13 +1314,8 @@ impl Step for RustcBook {
// bootstrap.toml), then this needs to explicitly update the dylib search // bootstrap.toml), then this needs to explicitly update the dylib search
// path. // path.
builder.add_rustc_lib_path(self.build_compiler, &mut cmd); builder.add_rustc_lib_path(self.build_compiler, &mut cmd);
let doc_generator_guard = builder.msg( let doc_generator_guard =
Kind::Run, builder.msg(Kind::Run, "lint-docs", None, self.build_compiler, self.target);
self.build_compiler.stage,
"lint-docs",
self.build_compiler.host,
self.target,
);
cmd.run(builder); cmd.run(builder);
drop(doc_generator_guard); drop(doc_generator_guard);

View file

@ -68,7 +68,13 @@ fn install_sh(
host: Option<TargetSelection>, host: Option<TargetSelection>,
tarball: &GeneratedTarball, tarball: &GeneratedTarball,
) { ) {
let _guard = builder.msg(Kind::Install, stage, package, host, host); let _guard = builder.msg(
Kind::Install,
package,
None,
(host.unwrap_or(builder.host_target), stage),
host,
);
let prefix = default_path(&builder.config.prefix, "/usr/local"); let prefix = default_path(&builder.config.prefix, "/usr/local");
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc")); let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));

View file

@ -161,8 +161,7 @@ You can skip linkcheck with --skip src/tools/linkchecker"
let linkchecker = builder.tool_cmd(Tool::Linkchecker); let linkchecker = builder.tool_cmd(Tool::Linkchecker);
// Run the linkchecker. // Run the linkchecker.
let _guard = let _guard = builder.msg(Kind::Test, "Linkcheck", None, compiler, bootstrap_host);
builder.msg(Kind::Test, compiler.stage, "Linkcheck", bootstrap_host, bootstrap_host);
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
linkchecker.delay_failure().arg(builder.out.join(host).join("doc")).run(builder); linkchecker.delay_failure().arg(builder.out.join(host).join("doc")).run(builder);
} }
@ -541,8 +540,7 @@ impl Miri {
cargo.env("MIRI_SYSROOT", &miri_sysroot); cargo.env("MIRI_SYSROOT", &miri_sysroot);
let mut cargo = BootstrapCommand::from(cargo); let mut cargo = BootstrapCommand::from(cargo);
let _guard = let _guard = builder.msg(Kind::Build, "miri sysroot", Mode::ToolRustc, compiler, target);
builder.msg(Kind::Build, compiler.stage, "miri sysroot", compiler.host, target);
cargo.run(builder); cargo.run(builder);
// # Determine where Miri put its sysroot. // # Determine where Miri put its sysroot.
@ -643,7 +641,8 @@ impl Step for Miri {
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg()); cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
{ {
let _guard = builder.msg_rustc_tool(Kind::Test, stage, "miri", host, target); let _guard =
builder.msg(Kind::Test, "miri", Mode::ToolRustc, miri.build_compiler, target);
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
cargo.run(builder); cargo.run(builder);
} }
@ -659,11 +658,11 @@ impl Step for Miri {
cargo.args(["tests/pass", "tests/panic"]); cargo.args(["tests/pass", "tests/panic"]);
{ {
let _guard = builder.msg_rustc_tool( let _guard = builder.msg(
Kind::Test, Kind::Test,
stage,
"miri (mir-opt-level 4)", "miri (mir-opt-level 4)",
host, Mode::ToolRustc,
miri.build_compiler,
target, target,
); );
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
@ -703,7 +702,7 @@ impl Step for CargoMiri {
} }
// This compiler runs on the host, we'll just use it for the target. // This compiler runs on the host, we'll just use it for the target.
let compiler = builder.compiler(stage, host); let build_compiler = builder.compiler(stage, host);
// Run `cargo miri test`. // Run `cargo miri test`.
// This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
@ -711,7 +710,7 @@ impl Step for CargoMiri {
// itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode. // itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode.
let mut cargo = tool::prepare_tool_cargo( let mut cargo = tool::prepare_tool_cargo(
builder, builder,
compiler, build_compiler,
Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test! Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test!
target, target,
Kind::MiriTest, Kind::MiriTest,
@ -736,7 +735,8 @@ impl Step for CargoMiri {
// Finally, run everything. // Finally, run everything.
let mut cargo = BootstrapCommand::from(cargo); let mut cargo = BootstrapCommand::from(cargo);
{ {
let _guard = builder.msg_rustc_tool(Kind::Test, stage, "cargo-miri", host, target); let _guard =
builder.msg(Kind::Test, "cargo-miri", Mode::ToolRustc, (host, stage), target);
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
cargo.run(builder); cargo.run(builder);
} }
@ -830,7 +830,7 @@ impl Step for Clippy {
/// Runs `cargo test` for clippy. /// Runs `cargo test` for clippy.
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let host = self.compilers.target(); let target = self.compilers.target();
// We need to carefully distinguish the compiler that builds clippy, and the compiler // We need to carefully distinguish the compiler that builds clippy, and the compiler
// that is linked into the clippy being tested. `target_compiler` is the latter, // that is linked into the clippy being tested. `target_compiler` is the latter,
@ -844,7 +844,7 @@ impl Step for Clippy {
builder, builder,
build_compiler, build_compiler,
Mode::ToolRustc, Mode::ToolRustc,
host, target,
Kind::Test, Kind::Test,
"src/tools/clippy", "src/tools/clippy",
SourceType::InTree, SourceType::InTree,
@ -858,7 +858,7 @@ impl Step for Clippy {
cargo.env("HOST_LIBS", host_libs); cargo.env("HOST_LIBS", host_libs);
// Build the standard library that the tests can use. // Build the standard library that the tests can use.
builder.std(target_compiler, host); builder.std(target_compiler, target);
cargo.env("TEST_SYSROOT", builder.sysroot(target_compiler)); cargo.env("TEST_SYSROOT", builder.sysroot(target_compiler));
cargo.env("TEST_RUSTC", builder.rustc(target_compiler)); cargo.env("TEST_RUSTC", builder.rustc(target_compiler));
cargo.env("TEST_RUSTC_LIB", builder.rustc_libdir(target_compiler)); cargo.env("TEST_RUSTC_LIB", builder.rustc_libdir(target_compiler));
@ -881,9 +881,9 @@ impl Step for Clippy {
} }
cargo.add_rustc_lib_path(builder); cargo.add_rustc_lib_path(builder);
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder); let cargo = prepare_cargo_test(cargo, &[], &[], target, builder);
let _guard = builder.msg_rustc_tool(Kind::Test, build_compiler.stage, "clippy", host, host); let _guard = builder.msg(Kind::Test, "clippy", Mode::ToolRustc, build_compiler, target);
// Clippy reports errors if it blessed the outputs // Clippy reports errors if it blessed the outputs
if cargo.allow_failure().run(builder) { if cargo.allow_failure().run(builder) {
@ -990,9 +990,9 @@ impl Step for RustdocJSStd {
)); ));
let _guard = builder.msg( let _guard = builder.msg(
Kind::Test, Kind::Test,
builder.top_stage,
"rustdoc-js-std", "rustdoc-js-std",
builder.config.host_target, None,
(builder.config.host_target, builder.top_stage),
self.target, self.target,
); );
command.run(builder); command.run(builder);
@ -1141,13 +1141,7 @@ impl Step for RustdocGUI {
} }
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
let _guard = builder.msg_rustc_tool( let _guard = builder.msg(Kind::Test, "rustdoc-gui", None, self.compiler, self.target);
Kind::Test,
self.compiler.stage,
"rustdoc-gui",
self.compiler.host,
self.target,
);
try_run_tests(builder, &mut cmd, true); try_run_tests(builder, &mut cmd, true);
} }
} }
@ -2237,9 +2231,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let _group = builder.msg( let _group = builder.msg(
Kind::Test, Kind::Test,
compiler.stage,
format!("compiletest suite={suite} mode={mode}"), format!("compiletest suite={suite} mode={mode}"),
compiler.host, // FIXME: compiletest sometimes behaves as ToolStd, we could expose that difference here
Mode::ToolBootstrap,
compiler,
target, target,
); );
try_run_tests(builder, &mut cmd, false); try_run_tests(builder, &mut cmd, false);
@ -2381,9 +2376,9 @@ impl BookTest {
builder.add_rust_test_threads(&mut rustbook_cmd); builder.add_rust_test_threads(&mut rustbook_cmd);
let _guard = builder.msg( let _guard = builder.msg(
Kind::Test, Kind::Test,
compiler.stage,
format_args!("mdbook {}", self.path.display()), format_args!("mdbook {}", self.path.display()),
compiler.host, None,
compiler,
compiler.host, compiler.host,
); );
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
@ -2402,8 +2397,7 @@ impl BookTest {
builder.std(compiler, host); builder.std(compiler, host);
let _guard = let _guard = builder.msg(Kind::Test, format!("book {}", self.name), None, compiler, host);
builder.msg(Kind::Test, compiler.stage, format!("book {}", self.name), host, host);
// Do a breadth-first traversal of the `src/doc` directory and just run // Do a breadth-first traversal of the `src/doc` directory and just run
// tests for all files that end in `*.md` // tests for all files that end in `*.md`
@ -2547,9 +2541,9 @@ impl Step for ErrorIndex {
let guard = builder.msg( let guard = builder.msg(
Kind::Test, Kind::Test,
target_compiler.stage,
"error-index", "error-index",
target_compiler.host, None,
self.compilers.build_compiler(),
target_compiler.host, target_compiler.host,
); );
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
@ -2650,9 +2644,8 @@ fn run_cargo_test<'a>(
let compiler = cargo.compiler(); let compiler = cargo.compiler();
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder); let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
let _time = helpers::timeit(builder); let _time = helpers::timeit(builder);
let _group = description.into().and_then(|what| { let _group =
builder.msg_rustc_tool(Kind::Test, compiler.stage, what, compiler.host, target) description.into().and_then(|what| builder.msg(Kind::Test, what, None, compiler, target));
});
#[cfg(feature = "build-metrics")] #[cfg(feature = "build-metrics")]
builder.metrics.begin_test_suite( builder.metrics.begin_test_suite(
@ -3176,8 +3169,9 @@ impl Step for Bootstrap {
/// Tests the build system itself. /// Tests the build system itself.
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let host = builder.config.host_target; let host = builder.config.host_target;
let compiler = builder.compiler(0, host); let build_compiler = builder.compiler(0, host);
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host); let _guard =
builder.msg(Kind::Test, "bootstrap", Mode::ToolBootstrap, build_compiler, host);
// Some tests require cargo submodule to be present. // Some tests require cargo submodule to be present.
builder.build.require_submodule("src/tools/cargo", None); builder.build.require_submodule("src/tools/cargo", None);
@ -3196,7 +3190,7 @@ impl Step for Bootstrap {
let mut cargo = tool::prepare_tool_cargo( let mut cargo = tool::prepare_tool_cargo(
builder, builder,
compiler, build_compiler,
Mode::ToolBootstrap, Mode::ToolBootstrap,
host, host,
Kind::Test, Kind::Test,
@ -3276,9 +3270,9 @@ impl Step for TierCheck {
let _guard = builder.msg( let _guard = builder.msg(
Kind::Test, Kind::Test,
self.compiler.stage,
"platform support check", "platform support check",
self.compiler.host, None,
self.compiler,
self.compiler.host, self.compiler.host,
); );
BootstrapCommand::from(cargo).delay_failure().run(builder); BootstrapCommand::from(cargo).delay_failure().run(builder);
@ -3326,10 +3320,10 @@ impl Step for RustInstaller {
/// Ensure the version placeholder replacement tool builds /// Ensure the version placeholder replacement tool builds
fn run(self, builder: &Builder<'_>) { fn run(self, builder: &Builder<'_>) {
let bootstrap_host = builder.config.host_target; let bootstrap_host = builder.config.host_target;
let compiler = builder.compiler(0, bootstrap_host); let build_compiler = builder.compiler(0, bootstrap_host);
let cargo = tool::prepare_tool_cargo( let cargo = tool::prepare_tool_cargo(
builder, builder,
compiler, build_compiler,
Mode::ToolBootstrap, Mode::ToolBootstrap,
bootstrap_host, bootstrap_host,
Kind::Test, Kind::Test,
@ -3338,13 +3332,8 @@ impl Step for RustInstaller {
&[], &[],
); );
let _guard = builder.msg( let _guard =
Kind::Test, builder.msg(Kind::Test, "rust-installer", None, build_compiler, bootstrap_host);
compiler.stage,
"rust-installer",
bootstrap_host,
bootstrap_host,
);
run_cargo_test(cargo, &[], &[], None, bootstrap_host, builder); run_cargo_test(cargo, &[], &[], None, bootstrap_host, builder);
// We currently don't support running the test.sh script outside linux(?) environments. // We currently don't support running the test.sh script outside linux(?) environments.
@ -3355,7 +3344,7 @@ impl Step for RustInstaller {
} }
let mut cmd = command(builder.src.join("src/tools/rust-installer/test.sh")); let mut cmd = command(builder.src.join("src/tools/rust-installer/test.sh"));
let tmpdir = testdir(builder, compiler.host).join("rust-installer"); let tmpdir = testdir(builder, build_compiler.host).join("rust-installer");
let _ = std::fs::remove_dir_all(&tmpdir); let _ = std::fs::remove_dir_all(&tmpdir);
let _ = std::fs::create_dir_all(&tmpdir); let _ = std::fs::create_dir_all(&tmpdir);
cmd.current_dir(&tmpdir); cmd.current_dir(&tmpdir);

View file

@ -26,7 +26,7 @@ use crate::core::builder::{
use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection}; use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
use crate::utils::exec::{BootstrapCommand, command}; use crate::utils::exec::{BootstrapCommand, command};
use crate::utils::helpers::{add_dylib_path, exe, t}; use crate::utils::helpers::{add_dylib_path, exe, t};
use crate::{Compiler, FileType, Kind, Mode, gha}; use crate::{Compiler, FileType, Kind, Mode};
#[derive(Debug, Clone, Hash, PartialEq, Eq)] #[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum SourceType { pub enum SourceType {
@ -58,28 +58,6 @@ struct ToolBuild {
artifact_kind: ToolArtifactKind, artifact_kind: ToolArtifactKind,
} }
impl Builder<'_> {
#[track_caller]
pub(crate) fn msg_tool(
&self,
kind: Kind,
mode: Mode,
tool: &str,
build_stage: u32,
host: &TargetSelection,
target: &TargetSelection,
) -> Option<gha::Group> {
match mode {
// depends on compiler stage, different to host compiler
Mode::ToolRustc => {
self.msg_rustc_tool(kind, build_stage, format_args!("tool {tool}"), *host, *target)
}
// doesn't depend on compiler, same as host compiler
_ => self.msg(kind, build_stage, format_args!("tool {tool}"), *host, *target),
}
}
}
/// Result of the tool build process. Each `Step` in this module is responsible /// Result of the tool build process. Each `Step` in this module is responsible
/// for using this type as `type Output = ToolBuildResult;` /// for using this type as `type Output = ToolBuildResult;`
#[derive(Clone)] #[derive(Clone)]
@ -166,14 +144,8 @@ impl Step for ToolBuild {
cargo.args(self.cargo_args); cargo.args(self.cargo_args);
let _guard = builder.msg_tool( let _guard =
Kind::Build, builder.msg(Kind::Build, self.tool, self.mode, self.build_compiler, self.target);
self.mode,
self.tool,
self.build_compiler.stage,
&self.build_compiler.host,
&self.target,
);
// we check this below // we check this below
let build_success = compile::stream_cargo(builder, cargo, vec![], &mut |_| {}); let build_success = compile::stream_cargo(builder, cargo, vec![], &mut |_| {});
@ -380,13 +352,13 @@ pub(crate) fn get_tool_target_compiler(
/// tools directory. /// tools directory.
fn copy_link_tool_bin( fn copy_link_tool_bin(
builder: &Builder<'_>, builder: &Builder<'_>,
compiler: Compiler, build_compiler: Compiler,
target: TargetSelection, target: TargetSelection,
mode: Mode, mode: Mode,
name: &str, name: &str,
) -> PathBuf { ) -> PathBuf {
let cargo_out = builder.cargo_out(compiler, mode, target).join(exe(name, target)); let cargo_out = builder.cargo_out(build_compiler, mode, target).join(exe(name, target));
let bin = builder.tools_dir(compiler).join(exe(name, target)); let bin = builder.tools_dir(build_compiler).join(exe(name, target));
builder.copy_link(&cargo_out, &bin, FileType::Executable); builder.copy_link(&cargo_out, &bin, FileType::Executable);
bin bin
} }

View file

@ -1597,7 +1597,7 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
cmd.env("CARGO", &self.initial_cargo); cmd.env("CARGO", &self.initial_cargo);
// Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler` // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
// in `tool::ToolBuild` step, so they match the Miri we just built. However this means they // in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
// are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the // are actually living one stage up, i.e. we are running `stage1-tools-bin/miri` with the
// libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact // libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
// that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary. // that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
// We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries // We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries

View file

@ -410,6 +410,25 @@ forward! {
download_rustc() -> bool, download_rustc() -> bool,
} }
/// A mostly temporary helper struct before we can migrate everything in bootstrap to use
/// the concept of a build compiler.
struct HostAndStage {
host: TargetSelection,
stage: u32,
}
impl From<(TargetSelection, u32)> for HostAndStage {
fn from((host, stage): (TargetSelection, u32)) -> Self {
Self { host, stage }
}
}
impl From<Compiler> for HostAndStage {
fn from(compiler: Compiler) -> Self {
Self { host: compiler.host, stage: compiler.stage }
}
}
impl Build { impl Build {
/// Creates a new set of build configuration from the `flags` on the command /// Creates a new set of build configuration from the `flags` on the command
/// line and the filesystem `config`. /// line and the filesystem `config`.
@ -859,14 +878,17 @@ impl Build {
if self.config.rust_optimize.is_release() { "release" } else { "debug" } if self.config.rust_optimize.is_release() { "release" } else { "debug" }
} }
fn tools_dir(&self, compiler: Compiler) -> PathBuf { fn tools_dir(&self, build_compiler: Compiler) -> PathBuf {
let out = self.out.join(compiler.host).join(format!("stage{}-tools-bin", compiler.stage)); let out = self
.out
.join(build_compiler.host)
.join(format!("stage{}-tools-bin", build_compiler.stage + 1));
t!(fs::create_dir_all(&out)); t!(fs::create_dir_all(&out));
out out
} }
/// Returns the root directory for all output generated in a particular /// 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. /// The mode indicates what the root directory is for.
fn stage_out(&self, build_compiler: Compiler, mode: Mode) -> PathBuf { fn stage_out(&self, build_compiler: Compiler, mode: Mode) -> PathBuf {
@ -876,15 +898,17 @@ impl Build {
(None, "bootstrap-tools") (None, "bootstrap-tools")
} }
fn staged_tool(build_compiler: Compiler) -> (Option<u32>, &'static str) { 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 { 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::Std => (Some(build_compiler.stage), "std"),
Mode::Rustc => (Some(build_compiler.stage), "rustc"), // The rest of things are built with stage N-1 rustc
Mode::Codegen => (Some(build_compiler.stage), "codegen"), Mode::Rustc => (Some(build_compiler.stage + 1), "rustc"),
Mode::Codegen => (Some(build_compiler.stage + 1), "codegen"),
Mode::ToolBootstrap => bootstrap_tool(), 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 => { Mode::ToolTarget => {
// If we're not cross-compiling (the common case), share the target directory with // If we're not cross-compiling (the common case), share the target directory with
// bootstrap tools to reuse the build cache. // bootstrap tools to reuse the build cache.
@ -907,8 +931,8 @@ impl Build {
/// Returns the root output directory for all Cargo output in a given stage, /// Returns the root output directory for all Cargo output in a given stage,
/// running a particular compiler, whether or not we're building the /// running a particular compiler, whether or not we're building the
/// standard library, and targeting the specified architecture. /// standard library, and targeting the specified architecture.
fn cargo_out(&self, compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf { fn cargo_out(&self, build_compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf {
self.stage_out(compiler, mode).join(target).join(self.cargo_dir()) self.stage_out(build_compiler, mode).join(target).join(self.cargo_dir())
} }
/// Root output directory of LLVM for `target` /// Root output directory of LLVM for `target`
@ -1067,45 +1091,14 @@ impl Build {
} }
} }
#[must_use = "Groups should not be dropped until the Step finishes running"] /// Return a `Group` guard for a [`Step`] that:
#[track_caller] /// - Performs `action`
fn msg_clippy( /// - On `what`
&self, /// - Where `what` possibly corresponds to a `mode`
what: impl Display, /// - `action` is performed using the given build compiler (`host_and_stage`).
target: impl Into<Option<TargetSelection>>, /// - Since some steps do not use the concept of a build compiler yet, it is also possible
) -> Option<gha::Group> { /// to pass the host and stage explicitly.
self.msg(Kind::Clippy, self.config.stage, what, self.config.host_target, target) /// - With a given `target`.
}
#[must_use = "Groups should not be dropped until the Step finishes running"]
#[track_caller]
fn msg_check(
&self,
what: impl Display,
target: impl Into<Option<TargetSelection>>,
custom_stage: Option<u32>,
) -> Option<gha::Group> {
self.msg(
Kind::Check,
custom_stage.unwrap_or(self.config.stage),
what,
self.config.host_target,
target,
)
}
#[must_use = "Groups should not be dropped until the Step finishes running"]
#[track_caller]
fn msg_doc(
&self,
compiler: Compiler,
what: impl Display,
target: impl Into<Option<TargetSelection>> + Copy,
) -> Option<gha::Group> {
self.msg(Kind::Doc, compiler.stage, what, compiler.host, target.into())
}
/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
/// ///
/// [`Step`]: crate::core::builder::Step /// [`Step`]: crate::core::builder::Step
#[must_use = "Groups should not be dropped until the Step finishes running"] #[must_use = "Groups should not be dropped until the Step finishes running"]
@ -1113,19 +1106,36 @@ impl Build {
fn msg( fn msg(
&self, &self,
action: impl Into<Kind>, action: impl Into<Kind>,
stage: u32,
what: impl Display, what: impl Display,
host: impl Into<Option<TargetSelection>>, mode: impl Into<Option<Mode>>,
host_and_stage: impl Into<HostAndStage>,
target: impl Into<Option<TargetSelection>>, target: impl Into<Option<TargetSelection>>,
) -> Option<gha::Group> { ) -> Option<gha::Group> {
let host_and_stage = host_and_stage.into();
let actual_stage = match mode.into() {
// Std has the same stage as the compiler that builds it
Some(Mode::Std) => host_and_stage.stage,
// Other things have stage corresponding to their build compiler + 1
Some(
Mode::Rustc
| Mode::Codegen
| Mode::ToolBootstrap
| Mode::ToolTarget
| Mode::ToolStd
| Mode::ToolRustc,
)
| None => host_and_stage.stage + 1,
};
let action = action.into().description(); let action = action.into().description();
let msg = |fmt| format!("{action} stage{stage} {what}{fmt}"); let msg = |fmt| format!("{action} stage{actual_stage} {what}{fmt}");
let msg = if let Some(target) = target.into() { let msg = if let Some(target) = target.into() {
let host = host.into().unwrap(); let build_stage = host_and_stage.stage;
let host = host_and_stage.host;
if host == target { if host == target {
msg(format_args!(" ({target})")) msg(format_args!(" (stage{build_stage} -> stage{actual_stage}, {target})"))
} else { } else {
msg(format_args!(" ({host} -> {target})")) msg(format_args!(" (stage{build_stage}:{host} -> stage{actual_stage}:{target})"))
} }
} else { } else {
msg(format_args!("")) msg(format_args!(""))
@ -1149,27 +1159,6 @@ impl Build {
self.group(&msg) self.group(&msg)
} }
#[must_use = "Groups should not be dropped until the Step finishes running"]
#[track_caller]
fn msg_rustc_tool(
&self,
action: impl Into<Kind>,
build_stage: u32,
what: impl Display,
host: TargetSelection,
target: TargetSelection,
) -> Option<gha::Group> {
let action = action.into().description();
let msg = |fmt| format!("{action} {what} {fmt}");
let msg = if host == target {
msg(format_args!("(stage{build_stage} -> stage{}, {target})", build_stage + 1))
} else {
msg(format_args!("(stage{build_stage}:{host} -> stage{}:{target})", build_stage + 1))
};
self.group(&msg)
}
#[track_caller] #[track_caller]
fn group(&self, msg: &str) -> Option<gha::Group> { fn group(&self, msg: &str) -> Option<gha::Group> {
match self.config.get_dry_run() { match self.config.get_dry_run() {

View file

@ -496,4 +496,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning, severity: ChangeSeverity::Warning,
summary: "It is no longer possible to `x doc` with stage 0. All doc commands have to be on stage 1+.", summary: "It is no longer possible to `x doc` with stage 0. All doc commands have to be on stage 1+.",
}, },
ChangeInfo {
change_id: 145295,
severity: ChangeSeverity::Warning,
summary: "The names of stageN directories in the build directory have been consolidated with the new (post-stage-0-redesign) staging scheme. Some tools and binaries might be located in a different build directory than before.",
},
]; ];

View file

@ -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`. /// 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. /// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
pub fn parse_rustc_stage() -> String { pub fn parse_rustc_stage() -> u32 {
env::var("RUSTC_STAGE").unwrap_or_else(|_| { 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. // 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: FATAL: RUSTC_STAGE was not set");
eprintln!("rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap"); eprintln!("rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap");

View file

@ -96,7 +96,7 @@ ENV RUST_CONFIGURE_ARGS \
--set rust.codegen-units=1 --set rust.codegen-units=1
ENV SCRIPT python3 ../x.py build --set rust.debug=true opt-dist && \ ENV SCRIPT python3 ../x.py build --set rust.debug=true opt-dist && \
./build/$HOSTS/stage0-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \ ./build/$HOSTS/stage1-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \
--host $HOSTS --target $HOSTS --include-default-paths build-manifest bootstrap --host $HOSTS --target $HOSTS --include-default-paths build-manifest bootstrap
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=clang ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=clang

View file

@ -4,7 +4,7 @@ set -eux
python3 ../x.py build --set rust.debug=true opt-dist python3 ../x.py build --set rust.debug=true opt-dist
./build/$HOSTS/stage0-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \ ./build/$HOSTS/stage1-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \
--host $HOSTS --target $HOSTS \ --host $HOSTS --target $HOSTS \
--include-default-paths \ --include-default-paths \
build-manifest bootstrap build-manifest bootstrap

View file

@ -656,7 +656,7 @@ auto:
--enable-full-tools --enable-full-tools
--enable-profiler --enable-profiler
--set rust.codegen-units=1 --set rust.codegen-units=1
SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage0-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage1-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths
DIST_REQUIRE_ALL_TOOLS: 1 DIST_REQUIRE_ALL_TOOLS: 1
CODEGEN_BACKENDS: llvm,cranelift CODEGEN_BACKENDS: llvm,cranelift
<<: *job-windows-8c <<: *job-windows-8c

View file

@ -118,7 +118,7 @@ Here is an example of how can `opt-dist` be used locally (outside of CI):
``` ```
3. Run the tool with the `local` mode and provide necessary parameters: 3. Run the tool with the `local` mode and provide necessary parameters:
```bash ```bash
./build/host/stage0-tools-bin/opt-dist local \ ./build/host/stage1-tools-bin/opt-dist local \
--target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu" --target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu"
--checkout-dir <path> \ # path to rust checkout, e.g. "." --checkout-dir <path> \ # path to rust checkout, e.g. "."
--llvm-dir <path> \ # path to built LLVM toolchain, e.g. "/foo/bar/llvm/install" --llvm-dir <path> \ # path to built LLVM toolchain, e.g. "/foo/bar/llvm/install"