Skip to content

Enforce in bootstrap that build must have stage at least 1 #142581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/bootstrap/defaults/bootstrap.library.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# These defaults are meant for contributors to the standard library and documentation.
[build]
bench-stage = 1
build-stage = 1
check-stage = 1
test-stage = 1

Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Implementation of compiling the compiler and standard library, in "check"-based modes.

use crate::core::build_steps::compile;
use crate::core::build_steps::compile::{
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
};
Expand Down Expand Up @@ -106,7 +105,7 @@ impl Step for Std {
}

// Reuse the stage0 libstd
builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);
return;
}

Expand Down Expand Up @@ -253,8 +252,8 @@ impl Step for Rustc {
// the sysroot for the compiler to find. Otherwise, we're going to
// fail when building crates that need to generate code (e.g., build
// scripts and their dependencies).
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
builder.std(compiler, compiler.host);
builder.std(compiler, target);
} else {
builder.ensure(Std::new(target).build_kind(self.override_build_kind));
}
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Implementation of running clippy on the compiler, standard library and various tools.

use super::check;
use super::compile::{run_cargo, rustc_cargo, std_cargo};
use super::tool::{SourceType, prepare_tool_cargo};
use super::{check, compile};
use crate::builder::{Builder, ShouldRun};
use crate::core::build_steps::compile::std_crates_for_run_make;
use crate::core::builder;
Expand Down Expand Up @@ -214,8 +214,8 @@ impl Step for Rustc {
// the sysroot for the compiler to find. Otherwise, we're going to
// fail when building crates that need to generate code (e.g., build
// scripts and their dependencies).
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, compiler.host);
builder.std(compiler, target);
} else {
builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check)));
}
Expand Down
22 changes: 14 additions & 8 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Step for Std {
{
trace!(?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library");

builder.ensure(Std::new(compiler_to_use, target));
builder.std(compiler_to_use, target);
let msg = if compiler_to_use.host == target {
format!(
"Uplifting library (stage{} -> stage{})",
Expand Down Expand Up @@ -681,7 +681,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct StdLink {
pub struct StdLink {
pub compiler: Compiler,
pub target_compiler: Compiler,
pub target: TargetSelection,
Expand All @@ -692,7 +692,7 @@ struct StdLink {
}

impl StdLink {
fn from_std(std: Std, host_compiler: Compiler) -> Self {
pub fn from_std(std: Std, host_compiler: Compiler) -> Self {
Self {
compiler: host_compiler,
target_compiler: std.compiler,
Expand Down Expand Up @@ -1013,6 +1013,12 @@ impl Step for Rustc {
}

fn make_run(run: RunConfig<'_>) {
// If only `compiler` was passed, do not run this step.
// Instead the `Assemble` step will take care of compiling Rustc.
if run.builder.paths == vec![PathBuf::from("compiler")] {
return;
}
Comment on lines +1016 to +1020
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: this kinda feels iffy, in that I feel like the path filtering/handling logic that lead to

Rustc step was invoked twice, once with all crates and once with no crates (even though both of these mean the same thing).

makes this kinda weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love Rustc and Assemble to be just one step (to avoid things like this), but I guess that it's sort of an optimizatoin, Rustc allows building only selected crates, and doesn't involve building a ton of other things that you might not want for a quick build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that does make sense.


let crates = run.cargo_crates_in_set();
run.builder.ensure(Rustc {
build_compiler: run
Expand Down Expand Up @@ -1058,7 +1064,7 @@ impl Step for Rustc {

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

if builder.config.keep_stage.contains(&build_compiler.stage) {
trace!(stage = build_compiler.stage, "`keep-stage` requested");
Expand Down Expand Up @@ -1099,10 +1105,10 @@ impl Step for Rustc {
// build scripts and proc macros.
// If we are not cross-compiling, the Std build above will be the same one as the one we
// prepare here.
builder.ensure(Std::new(
builder.std(
builder.compiler(self.build_compiler.stage, builder.config.host_target),
builder.config.host_target,
));
);

let mut cargo = builder::Cargo::new(
builder,
Expand Down Expand Up @@ -2062,15 +2068,15 @@ impl Step for Assemble {
if builder.download_rustc() {
trace!("`download-rustc` requested, reusing CI compiler for stage > 0");

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

let mut precompiled_compiler = target_compiler;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ impl Step for Std {
return None;
}

builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);

let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
tarball.include_target_in_component_name(true);
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ impl Step for Rustc {
// Build the standard library, so that proc-macros can use it.
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
let compiler = builder.compiler(stage, builder.config.host_target);
builder.ensure(compile::Std::new(compiler, builder.config.host_target));
builder.std(compiler, builder.config.host_target);

let _guard = builder.msg_sysroot_tool(
Kind::Doc,
Expand Down Expand Up @@ -947,7 +947,7 @@ macro_rules! tool_doc {
t!(fs::create_dir_all(&out));

let compiler = builder.compiler(stage, builder.config.host_target);
builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);

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

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

// Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/perf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env::consts::EXE_EXTENSION;
use std::fmt::{Display, Formatter};

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

let compiler = builder.compiler(builder.top_stage, builder.config.host_target);
builder.ensure(Std::new(compiler, builder.config.host_target));
builder.std(compiler, builder.config.host_target);

if let Some(opts) = args.cmd.shared_opts()
&& opts.profiles.contains(&Profile::Doc)
Expand Down
30 changes: 15 additions & 15 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{env, fs, iter};

use clap_complete::shells;

use crate::core::build_steps::compile::run_cargo;
use crate::core::build_steps::compile::{Std, run_cargo};
use crate::core::build_steps::doc::DocumentationFormat;
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
use crate::core::build_steps::llvm::get_llvm_version;
Expand Down Expand Up @@ -544,7 +544,7 @@ impl Step for Miri {
// We also need sysroots, for Miri and for the host (the latter for build scripts).
// This is for the tests so everything is done with the target compiler.
let miri_sysroot = Miri::build_miri_sysroot(builder, target_compiler, target);
builder.ensure(compile::Std::new(target_compiler, host));
builder.std(target_compiler, host);
let host_sysroot = builder.sysroot(target_compiler);

// Miri has its own "target dir" for ui test dependencies. Make sure it gets cleared when
Expand Down Expand Up @@ -709,7 +709,7 @@ impl Step for CompiletestTest {

// We need `ToolStd` for the locally-built sysroot because
// compiletest uses unstable features of the `test` crate.
builder.ensure(compile::Std::new(compiler, host));
builder.std(compiler, host);
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
Expand Down Expand Up @@ -1009,7 +1009,7 @@ impl Step for RustdocGUI {
}

fn run(self, builder: &Builder<'_>) {
builder.ensure(compile::Std::new(self.compiler, self.target));
builder.std(self.compiler, self.target);

let mut cmd = builder.tool_cmd(Tool::RustdocGUITest);

Expand Down Expand Up @@ -1634,15 +1634,15 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
if suite == "mir-opt" {
builder.ensure(compile::Std::new(compiler, compiler.host).is_for_mir_opt_tests(true));
} else {
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.std(compiler, compiler.host);
}

let mut cmd = builder.tool_cmd(Tool::Compiletest);

if suite == "mir-opt" {
builder.ensure(compile::Std::new(compiler, target).is_for_mir_opt_tests(true));
} else {
builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);
}

builder.ensure(RemoteCopyLibs { compiler, target });
Expand Down Expand Up @@ -2177,7 +2177,7 @@ impl BookTest {
fn run_ext_doc(self, builder: &Builder<'_>) {
let compiler = self.compiler;

builder.ensure(compile::Std::new(compiler, compiler.host));
builder.std(compiler, compiler.host);

// mdbook just executes a binary named "rustdoc", so we need to update
// PATH so that it points to our rustdoc.
Expand Down Expand Up @@ -2263,7 +2263,7 @@ impl BookTest {
let compiler = self.compiler;
let host = self.compiler.host;

builder.ensure(compile::Std::new(compiler, host));
builder.std(compiler, host);

let _guard =
builder.msg(Kind::Test, compiler.stage, format!("book {}", self.name), host, host);
Expand Down Expand Up @@ -2410,7 +2410,7 @@ impl Step for ErrorIndex {
drop(guard);
// The tests themselves need to link to std, so make sure it is
// available.
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.std(compiler, compiler.host);
markdown_test(builder, compiler, &output);
}
}
Expand Down Expand Up @@ -2473,7 +2473,7 @@ impl Step for CrateLibrustc {
}

fn run(self, builder: &Builder<'_>) {
builder.ensure(compile::Std::new(self.compiler, self.target));
builder.std(self.compiler, self.target);

// To actually run the tests, delegate to a copy of the `Crate` step.
builder.ensure(Crate {
Expand Down Expand Up @@ -2641,7 +2641,7 @@ impl Step for Crate {

// Prepare sysroot
// See [field@compile::Std::force_recompile].
builder.ensure(compile::Std::new(compiler, compiler.host).force_recompile(true));
builder.ensure(Std::new(compiler, compiler.host).force_recompile(true));

// If we're not doing a full bootstrap but we're testing a stage2
// version of libstd, then what we're actually testing is the libstd
Expand Down Expand Up @@ -2767,7 +2767,7 @@ impl Step for CrateRustdoc {
// using `download-rustc`, the rustc_private artifacts may be in a *different sysroot* from
// the target rustdoc (`ci-rustc-sysroot` vs `stage2`). In that case, we need to ensure this
// explicitly to make sure it ends up in the stage2 sysroot.
builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);
builder.ensure(compile::Rustc::new(compiler, target));

let mut cargo = tool::prepare_tool_cargo(
Expand Down Expand Up @@ -2911,7 +2911,7 @@ impl Step for RemoteCopyLibs {
return;
}

builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);

builder.info(&format!("REMOTE copy libs to emulator ({target})"));

Expand Down Expand Up @@ -3101,7 +3101,7 @@ impl Step for TierCheck {

/// Tests the Platform Support page in the rustc book.
fn run(self, builder: &Builder<'_>) {
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
builder.std(self.compiler, self.compiler.host);
let mut cargo = tool::prepare_tool_cargo(
builder,
self.compiler,
Expand Down Expand Up @@ -3334,7 +3334,7 @@ impl Step for CodegenCranelift {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Std::new(compiler, target));
builder.std(compiler, target);

// If we're not doing a full bootstrap but we're testing a stage2
// version of libstd, then what we're actually testing is the libstd
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ impl Step for ToolBuild {
Mode::ToolRustc => {
// If compiler was forced, its artifacts should be prepared earlier.
if !self.compiler.is_forced_compiler() {
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
builder.std(self.compiler, self.compiler.host);
builder.ensure(compile::Rustc::new(self.compiler, target));
}
}
Mode::ToolStd => {
// If compiler was forced, its artifacts should be prepared earlier.
if !self.compiler.is_forced_compiler() {
builder.ensure(compile::Std::new(self.compiler, target))
builder.std(self.compiler, target)
}
}
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};

use super::{Builder, Kind};
use crate::core::build_steps::test;
use crate::core::build_steps::tool::SourceType;
use crate::core::build_steps::{compile, test};
use crate::core::config::SplitDebuginfo;
use crate::core::config::flags::Color;
use crate::utils::build_stamp;
Expand Down Expand Up @@ -842,7 +842,7 @@ impl Builder<'_> {

// If this is for `miri-test`, prepare the sysroots.
if cmd_kind == Kind::MiriTest {
self.ensure(compile::Std::new(compiler, compiler.host));
self.std(compiler, compiler.host);
let host_sysroot = self.sysroot(compiler);
let miri_sysroot = test::Miri::build_miri_sysroot(self, compiler, target);
cargo.env("MIRI_SYSROOT", &miri_sysroot);
Expand Down
Loading
Loading