Skip to content

Commit 450a2d8

Browse files
committed
Add Builder::std method for building a standard library
1 parent 58d5e11 commit 450a2d8

File tree

10 files changed

+84
-41
lines changed

10 files changed

+84
-41
lines changed

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
};
@@ -89,7 +88,7 @@ impl Step for Std {
8988
}
9089

9190
// Reuse the stage0 libstd
92-
builder.ensure(compile::Std::new(compiler, target));
91+
builder.std(compiler, target);
9392
return;
9493
}
9594

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

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;
@@ -214,8 +214,8 @@ impl Step for Rustc {
214214
// the sysroot for the compiler to find. Otherwise, we're going to
215215
// fail when building crates that need to generate code (e.g., build
216216
// scripts and their dependencies).
217-
builder.ensure(compile::Std::new(compiler, compiler.host));
218-
builder.ensure(compile::Std::new(compiler, target));
217+
builder.std(compiler, compiler.host);
218+
builder.std(compiler, target);
219219
} else {
220220
builder.ensure(check::Std::new(target));
221221
}

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

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

216-
builder.ensure(Std::new(compiler_to_use, target));
216+
builder.std(compiler_to_use, target);
217217
let msg = if compiler_to_use.host == target {
218218
format!(
219219
"Uplifting library (stage{} -> stage{})",
@@ -690,7 +690,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
690690
}
691691

692692
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
693-
struct StdLink {
693+
pub struct StdLink {
694694
pub compiler: Compiler,
695695
pub target_compiler: Compiler,
696696
pub target: TargetSelection,
@@ -701,7 +701,7 @@ struct StdLink {
701701
}
702702

703703
impl StdLink {
704-
fn from_std(std: Std, host_compiler: Compiler) -> Self {
704+
pub fn from_std(std: Std, host_compiler: Compiler) -> Self {
705705
Self {
706706
compiler: host_compiler,
707707
target_compiler: std.compiler,
@@ -1067,7 +1067,7 @@ impl Step for Rustc {
10671067

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

10721072
if builder.config.keep_stage.contains(&build_compiler.stage) {
10731073
trace!(stage = build_compiler.stage, "`keep-stage` requested");
@@ -1108,10 +1108,10 @@ impl Step for Rustc {
11081108
// build scripts and proc macros.
11091109
// If we are not cross-compiling, the Std build above will be the same one as the one we
11101110
// prepare here.
1111-
builder.ensure(Std::new(
1111+
builder.std(
11121112
builder.compiler(self.build_compiler.stage, builder.config.host_target),
11131113
builder.config.host_target,
1114-
));
1114+
);
11151115

11161116
let mut cargo = builder::Cargo::new(
11171117
builder,
@@ -2079,15 +2079,15 @@ impl Step for Assemble {
20792079
if builder.download_rustc() {
20802080
trace!("`download-rustc` requested, reusing CI compiler for stage > 0");
20812081

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

20932093
let mut precompiled_compiler = target_compiler;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl Step for Std {
711711
return None;
712712
}
713713

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

716716
let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
717717
tarball.include_target_in_component_name(true);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl Step for Rustc {
804804
// Build the standard library, so that proc-macros can use it.
805805
// (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.)
806806
let compiler = builder.compiler(stage, builder.config.host_target);
807-
builder.ensure(compile::Std::new(compiler, builder.config.host_target));
807+
builder.std(compiler, builder.config.host_target);
808808

809809
let _guard = builder.msg_sysroot_tool(
810810
Kind::Doc,
@@ -947,7 +947,7 @@ macro_rules! tool_doc {
947947
t!(fs::create_dir_all(&out));
948948

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

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

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

12771277
// Run rustbook/mdbook to generate the HTML pages.
12781278
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)

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{env, fs, iter};
1010

1111
use clap_complete::shells;
1212

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

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

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

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

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

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

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

16421642
if suite == "mir-opt" {
16431643
builder.ensure(compile::Std::new(compiler, target).is_for_mir_opt_tests(true));
16441644
} else {
1645-
builder.ensure(compile::Std::new(compiler, target));
1645+
builder.std(compiler, target);
16461646
}
16471647

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

2180-
builder.ensure(compile::Std::new(compiler, compiler.host));
2180+
builder.std(compiler, compiler.host);
21812181

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

2266-
builder.ensure(compile::Std::new(compiler, host));
2266+
builder.std(compiler, host);
22672267

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

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

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

26422642
// Prepare sysroot
26432643
// See [field@compile::Std::force_recompile].
2644-
builder.ensure(compile::Std::new(compiler, compiler.host).force_recompile(true));
2644+
builder.ensure(Std::new(compiler, compiler.host).force_recompile(true));
26452645

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

27732773
let mut cargo = tool::prepare_tool_cargo(
@@ -2911,7 +2911,7 @@ impl Step for RemoteCopyLibs {
29112911
return;
29122912
}
29132913

2914-
builder.ensure(compile::Std::new(compiler, target));
2914+
builder.std(compiler, target);
29152915

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

@@ -3101,7 +3101,7 @@ impl Step for TierCheck {
31013101

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

3337-
builder.ensure(compile::Std::new(compiler, target));
3337+
builder.std(compiler, target);
33383338

33393339
// If we're not doing a full bootstrap but we're testing a stage2
33403340
// version of libstd, then what we're actually testing is the libstd

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ impl Step for ToolBuild {
122122
Mode::ToolRustc => {
123123
// If compiler was forced, its artifacts should be prepared earlier.
124124
if !self.compiler.is_forced_compiler() {
125-
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
125+
builder.std(self.compiler, self.compiler.host);
126126
builder.ensure(compile::Rustc::new(self.compiler, target));
127127
}
128128
}
129129
Mode::ToolStd => {
130130
// If compiler was forced, its artifacts should be prepared earlier.
131131
if !self.compiler.is_forced_compiler() {
132-
builder.ensure(compile::Std::new(self.compiler, target))
132+
builder.std(self.compiler, target)
133133
}
134134
}
135135
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::ffi::{OsStr, OsString};
33
use std::path::{Path, PathBuf};
44

55
use super::{Builder, Kind};
6+
use crate::core::build_steps::test;
67
use crate::core::build_steps::tool::SourceType;
7-
use crate::core::build_steps::{compile, test};
88
use crate::core::config::SplitDebuginfo;
99
use crate::core::config::flags::Color;
1010
use crate::utils::build_stamp;
@@ -842,7 +842,7 @@ impl Builder<'_> {
842842

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

0 commit comments

Comments
 (0)