Skip to content

Commit 8f21a5c

Browse files
committed
Auto merge of #142581 - Kobzol:bootstrap-std-method, r=jieyouxu
Enforce in bootstrap that build must have stage at least 1 This PR is a step towards https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Proposal.20to.20cleanup.20stages.20and.20steps.20after.20the.20redesign/with/523586917. It's very hard or me to make self-contained changes to bootstrap at this moment, so this PR kind of does several things: 1) (first two commits) Try to reduce the usage of `Std::new` in bootstrap, and replace it with a `Builder::std` method (similar to `Builder::compiler`). This is mostly to remove executions of the `Std` step for stage 0, which doesn't make a lot of sense; I'd like to ideally have the invariant that when a step is invoked, it actually builds or does something. Eventually, I'd like for everything to go through `Builder::std`. (Note: I'm not totally married to this idea, if you don't like it, we can remove it from this PR. I mostly did it right now to remove stage 0 std steps from snapshot tests, which shouldn't be there, but we can also filter them out in a different way) 2) Make sure that when you pass `x build compiler`, only the `Assemble` root level step will be invoked, and not the `Rustc` step. Before, both were invoked, which actually ran `Rustc` twice, once with all `crates` filled, and once with no crates (but both actually represent the same situation). Since the `Rustc::make_run` step actually requests a compile that is one stage below it, this actually made `build compiler --stage 0` work, which we don't want to have anymore. 3) Enforce a bootstrap-global invariant that all `build` commands are always on stage `>=1`. If you try to `build` anything on stage 0, it will print a warning and exit bootstrap. This follows the intuition from the new staging rules after the stage redesign; artifacts that are "stage 0" come outside of bootstrap, and we can't really build something for which we don't have source (although we can still test it, but that's for another PR). Now the logic for build should be quite simple. For pretty much everything except for `Std`, you first use the stage0 compiler to build stage 1. Then you can build a stage 2 <something> using the previously built stage 1 (and then you can continue to stage 3 etc.). And that's it. The default build stage for everything is 1 (modulo download-ci-rustc, but that's a separate can of worms). The snapshot test infra isn't super nice at the moment, as one of next steps I want to create some simple Builder pattern that will allow us to configure the bootstrap invocations in a more "forward-compatible" way (e.g. now it's not possible to modify the config passed to `configure_with_args`). There are some things not yet fully resolved for build stage 0: 1) Cargo is still a `ModeRustc` tool, even though it doesn't really have to be, it is buildable with the stage0 compiler 2) bootstrap tools (`opt-dist`, `build-manifest` etc.) are still called stage0 tools, and in the bootstrap output it says something like "stage 0 rustc builds stage 0 opt-dist". Which is a bit weird, but functionally there's no difference, it's just a slightly inconsistent output. We still haven't decided if we should make these tools ignore staging altogether (which is IMO the right choice) or if we want to allow building stage 1/2/3/... bootstrap tools. r? `@jieyouxu` try-job: x86_64-rust-for-linux
2 parents 1e83852 + e69c023 commit 8f21a5c

File tree

17 files changed

+948
-685
lines changed

17 files changed

+948
-685
lines changed

src/bootstrap/defaults/bootstrap.library.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# These defaults are meant for contributors to the standard library and documentation.
22
[build]
33
bench-stage = 1
4-
build-stage = 1
54
check-stage = 1
65
test-stage = 1
76

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use crate::core::build_steps::compile;
43
use crate::core::build_steps::compile::{
54
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
65
};
@@ -87,7 +86,7 @@ impl Step for Std {
8786
}
8887

8988
// Reuse the stage0 libstd
90-
builder.ensure(compile::Std::new(compiler, target));
89+
builder.std(compiler, target);
9190
return;
9291
}
9392

@@ -221,8 +220,8 @@ impl Step for Rustc {
221220
// the sysroot for the compiler to find. Otherwise, we're going to
222221
// fail when building crates that need to generate code (e.g., build
223222
// scripts and their dependencies).
224-
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
225-
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
223+
builder.std(compiler, compiler.host);
224+
builder.std(compiler, target);
226225
} else {
227226
builder.ensure(Std::new(target));
228227
}

src/bootstrap/src/core/build_steps/clippy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Implementation of running clippy on the compiler, standard library and various tools.
22
3+
use super::check;
34
use super::compile::{run_cargo, rustc_cargo, std_cargo};
45
use super::tool::{SourceType, prepare_tool_cargo};
5-
use super::{check, compile};
66
use crate::builder::{Builder, ShouldRun};
77
use crate::core::build_steps::compile::std_crates_for_run_make;
88
use crate::core::builder;
@@ -212,8 +212,8 @@ impl Step for Rustc {
212212
// the sysroot for the compiler to find. Otherwise, we're going to
213213
// fail when building crates that need to generate code (e.g., build
214214
// scripts and their dependencies).
215-
builder.ensure(compile::Std::new(compiler, compiler.host));
216-
builder.ensure(compile::Std::new(compiler, target));
215+
builder.std(compiler, compiler.host);
216+
builder.std(compiler, target);
217217
} else {
218218
builder.ensure(check::Std::new(target));
219219
}

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl Step for Std {
211211
{
212212
trace!(?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library");
213213

214-
builder.ensure(Std::new(compiler_to_use, target));
214+
builder.std(compiler_to_use, target);
215215
let msg = if compiler_to_use.host == target {
216216
format!(
217217
"Uplifting library (stage{} -> stage{})",
@@ -688,7 +688,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
688688
}
689689

690690
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
691-
struct StdLink {
691+
pub struct StdLink {
692692
pub compiler: Compiler,
693693
pub target_compiler: Compiler,
694694
pub target: TargetSelection,
@@ -699,7 +699,7 @@ struct StdLink {
699699
}
700700

701701
impl StdLink {
702-
fn from_std(std: Std, host_compiler: Compiler) -> Self {
702+
pub fn from_std(std: Std, host_compiler: Compiler) -> Self {
703703
Self {
704704
compiler: host_compiler,
705705
target_compiler: std.compiler,
@@ -1020,6 +1020,12 @@ impl Step for Rustc {
10201020
}
10211021

10221022
fn make_run(run: RunConfig<'_>) {
1023+
// If only `compiler` was passed, do not run this step.
1024+
// Instead the `Assemble` step will take care of compiling Rustc.
1025+
if run.builder.paths == vec![PathBuf::from("compiler")] {
1026+
return;
1027+
}
1028+
10231029
let crates = run.cargo_crates_in_set();
10241030
run.builder.ensure(Rustc {
10251031
build_compiler: run
@@ -1065,7 +1071,7 @@ impl Step for Rustc {
10651071

10661072
// Build a standard library for `target` using the `build_compiler`.
10671073
// This will be the standard library that the rustc which we build *links to*.
1068-
builder.ensure(Std::new(build_compiler, target));
1074+
builder.std(build_compiler, target);
10691075

10701076
if builder.config.keep_stage.contains(&build_compiler.stage) {
10711077
trace!(stage = build_compiler.stage, "`keep-stage` requested");
@@ -1106,10 +1112,10 @@ impl Step for Rustc {
11061112
// build scripts and proc macros.
11071113
// If we are not cross-compiling, the Std build above will be the same one as the one we
11081114
// prepare here.
1109-
builder.ensure(Std::new(
1115+
builder.std(
11101116
builder.compiler(self.build_compiler.stage, builder.config.host_target),
11111117
builder.config.host_target,
1112-
));
1118+
);
11131119

11141120
let mut cargo = builder::Cargo::new(
11151121
builder,
@@ -2077,15 +2083,15 @@ impl Step for Assemble {
20772083
if builder.download_rustc() {
20782084
trace!("`download-rustc` requested, reusing CI compiler for stage > 0");
20792085

2080-
builder.ensure(Std::new(target_compiler, target_compiler.host));
2086+
builder.std(target_compiler, target_compiler.host);
20812087
let sysroot =
20822088
builder.ensure(Sysroot { compiler: target_compiler, force_recompile: false });
20832089
// Ensure that `libLLVM.so` ends up in the newly created target directory,
20842090
// so that tools using `rustc_private` can use it.
20852091
dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot);
20862092
// Lower stages use `ci-rustc-sysroot`, not stageN
20872093
if target_compiler.stage == builder.top_stage {
2088-
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage));
2094+
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage = target_compiler.stage));
20892095
}
20902096

20912097
let mut precompiled_compiler = target_compiler;

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::core::build_steps::doc::DocumentationFormat;
2323
use crate::core::build_steps::tool::{self, Tool};
2424
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
2525
use crate::core::build_steps::{compile, llvm};
26-
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
26+
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
2727
use crate::core::config::TargetSelection;
2828
use crate::utils::build_stamp::{self, BuildStamp};
2929
use crate::utils::channel::{self, Info};
@@ -84,6 +84,10 @@ impl Step for Docs {
8484
tarball.add_file(builder.src.join("src/doc/robots.txt"), dest, FileType::Regular);
8585
Some(tarball.generate())
8686
}
87+
88+
fn metadata(&self) -> Option<StepMetadata> {
89+
Some(StepMetadata::dist("docs", self.host))
90+
}
8791
}
8892

8993
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
@@ -354,6 +358,10 @@ impl Step for Mingw {
354358

355359
Some(tarball.generate())
356360
}
361+
362+
fn metadata(&self) -> Option<StepMetadata> {
363+
Some(StepMetadata::dist("mingw", self.host))
364+
}
357365
}
358366

359367
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
@@ -540,6 +548,10 @@ impl Step for Rustc {
540548
}
541549
}
542550
}
551+
552+
fn metadata(&self) -> Option<StepMetadata> {
553+
Some(StepMetadata::dist("rustc", self.compiler.host))
554+
}
543555
}
544556

545557
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -711,7 +723,7 @@ impl Step for Std {
711723
return None;
712724
}
713725

714-
builder.ensure(compile::Std::new(compiler, target));
726+
builder.std(compiler, target);
715727

716728
let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
717729
tarball.include_target_in_component_name(true);
@@ -723,6 +735,10 @@ impl Step for Std {
723735

724736
Some(tarball.generate())
725737
}
738+
739+
fn metadata(&self) -> Option<StepMetadata> {
740+
Some(StepMetadata::dist("std", self.target).built_by(self.compiler))
741+
}
726742
}
727743

728744
/// Tarball containing the compiler that gets downloaded and used by
@@ -1002,6 +1018,10 @@ impl Step for Src {
10021018

10031019
tarball.generate()
10041020
}
1021+
1022+
fn metadata(&self) -> Option<StepMetadata> {
1023+
Some(StepMetadata::dist("src", TargetSelection::default()))
1024+
}
10051025
}
10061026

10071027
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use std::{env, fs, mem};
1414
use crate::core::build_steps::compile;
1515
use crate::core::build_steps::tool::{self, SourceType, Tool, prepare_tool_cargo};
1616
use crate::core::builder::{
17-
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, crate_description,
17+
self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata,
18+
crate_description,
1819
};
1920
use crate::core::config::{Config, TargetSelection};
2021
use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date};
@@ -662,6 +663,10 @@ impl Step for Std {
662663
}
663664
}
664665
}
666+
667+
fn metadata(&self) -> Option<StepMetadata> {
668+
Some(StepMetadata::doc("std", self.target).stage(self.stage))
669+
}
665670
}
666671

667672
/// Name of the crates that are visible to consumers of the standard library.
@@ -804,7 +809,7 @@ impl Step for Rustc {
804809
// Build the standard library, so that proc-macros can use it.
805810
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
806811
let compiler = builder.compiler(stage, builder.config.host_target);
807-
builder.ensure(compile::Std::new(compiler, builder.config.host_target));
812+
builder.std(compiler, builder.config.host_target);
808813

809814
let _guard = builder.msg_sysroot_tool(
810815
Kind::Doc,
@@ -947,7 +952,7 @@ macro_rules! tool_doc {
947952
t!(fs::create_dir_all(&out));
948953

949954
let compiler = builder.compiler(stage, builder.config.host_target);
950-
builder.ensure(compile::Std::new(compiler, target));
955+
builder.std(compiler, target);
951956

952957
if true $(&& $rustc_tool)? {
953958
// Build rustc docs so that we generate relative links.
@@ -1195,7 +1200,7 @@ impl Step for RustcBook {
11951200
let rustc = builder.rustc(self.compiler);
11961201
// The tool runs `rustc` for extracting output examples, so it needs a
11971202
// functional sysroot.
1198-
builder.ensure(compile::Std::new(self.compiler, self.target));
1203+
builder.std(self.compiler, self.target);
11991204
let mut cmd = builder.tool_cmd(Tool::LintDocs);
12001205
cmd.arg("--src");
12011206
cmd.arg(builder.src.join("compiler"));
@@ -1272,7 +1277,7 @@ impl Step for Reference {
12721277

12731278
// This is needed for generating links to the standard library using
12741279
// the mdbook-spec plugin.
1275-
builder.ensure(compile::Std::new(self.compiler, builder.config.host_target));
1280+
builder.std(self.compiler, builder.config.host_target);
12761281

12771282
// Run rustbook/mdbook to generate the HTML pages.
12781283
builder.ensure(RustbookSrc {

src/bootstrap/src/core/build_steps/perf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::env::consts::EXE_EXTENSION;
22
use std::fmt::{Display, Formatter};
33

4-
use crate::core::build_steps::compile::{Std, Sysroot};
4+
use crate::core::build_steps::compile::Sysroot;
55
use crate::core::build_steps::tool::{RustcPerf, Rustdoc};
66
use crate::core::builder::Builder;
77
use crate::core::config::DebuginfoLevel;
@@ -152,7 +152,7 @@ Consider setting `rust.debuginfo-level = 1` in `bootstrap.toml`."#);
152152
}
153153

154154
let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
155-
builder.ensure(Std::new(compiler, builder.config.host_target));
155+
builder.std(compiler, builder.config.host_target);
156156

157157
if let Some(opts) = args.cmd.shared_opts()
158158
&& opts.profiles.contains(&Profile::Doc)

0 commit comments

Comments
 (0)