Skip to content

Commit ff6d296

Browse files
committed
refactor use of Cargo and configure_linker in bootstrap
Signed-off-by: onur-ozkan <[email protected]>
1 parent 993c72f commit ff6d296

File tree

7 files changed

+252
-187
lines changed

7 files changed

+252
-187
lines changed

Diff for: src/bootstrap/src/core/build_steps/check.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::core::build_steps::compile::{
44
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
55
};
66
use crate::core::build_steps::tool::{prepare_tool_cargo, SourceType};
7-
use crate::core::builder::{crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step};
7+
use crate::core::builder::{
8+
self, crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step,
9+
};
810
use crate::core::config::TargetSelection;
911
use crate::utils::cache::Interned;
1012
use crate::INTERNER;
@@ -110,14 +112,15 @@ impl Step for Std {
110112
let target = self.target;
111113
let compiler = builder.compiler(builder.top_stage, builder.config.build);
112114

113-
let mut cargo = builder.cargo(
115+
let mut cargo = builder::Cargo::new(
116+
builder,
114117
compiler,
115118
Mode::Std,
116119
SourceType::InTree,
117120
target,
118121
cargo_subcommand(builder.kind),
119-
false,
120122
);
123+
121124
std_cargo(builder, target, compiler.stage, &mut cargo);
122125
if matches!(builder.config.cmd, Subcommand::Fix { .. }) {
123126
// By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot.
@@ -163,13 +166,13 @@ impl Step for Std {
163166
// since we initialize with an empty sysroot.
164167
//
165168
// Currently only the "libtest" tree of crates does this.
166-
let mut cargo = builder.cargo(
169+
let mut cargo = builder::Cargo::new(
170+
builder,
167171
compiler,
168172
Mode::Std,
169173
SourceType::InTree,
170174
target,
171175
cargo_subcommand(builder.kind),
172-
false,
173176
);
174177

175178
// If we're not in stage 0, tests and examples will fail to compile
@@ -258,14 +261,15 @@ impl Step for Rustc {
258261
builder.ensure(Std::new(target));
259262
}
260263

261-
let mut cargo = builder.cargo(
264+
let mut cargo = builder::Cargo::new(
265+
builder,
262266
compiler,
263267
Mode::Rustc,
264268
SourceType::InTree,
265269
target,
266270
cargo_subcommand(builder.kind),
267-
false,
268271
);
272+
269273
rustc_cargo(builder, &mut cargo, target, compiler.stage);
270274

271275
// For ./x.py clippy, don't run with --all-targets because
@@ -335,14 +339,15 @@ impl Step for CodegenBackend {
335339

336340
builder.ensure(Rustc::new(target, builder));
337341

338-
let mut cargo = builder.cargo(
342+
let mut cargo = builder::Cargo::new(
343+
builder,
339344
compiler,
340345
Mode::Codegen,
341346
SourceType::InTree,
342347
target,
343348
cargo_subcommand(builder.kind),
344-
false,
345349
);
350+
346351
cargo
347352
.arg("--manifest-path")
348353
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+37-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use serde_derive::Deserialize;
2222
use crate::core::build_steps::dist;
2323
use crate::core::build_steps::llvm;
2424
use crate::core::build_steps::tool::SourceType;
25+
use crate::core::builder;
2526
use crate::core::builder::crate_description;
2627
use crate::core::builder::Cargo;
2728
use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
@@ -233,25 +234,35 @@ impl Step for Std {
233234
}
234235
}
235236

236-
let mut cargo = builder.cargo(
237-
compiler,
238-
Mode::Std,
239-
SourceType::InTree,
240-
target,
241-
if self.is_for_mir_opt_tests { "check" } else { "build" },
242-
self.is_for_mir_opt_tests,
243-
);
244237
// We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
245238
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
246239
// fact that this is a check build integrates nicely with run_cargo.
247-
if self.is_for_mir_opt_tests {
240+
let mut cargo = if self.is_for_mir_opt_tests {
241+
let mut cargo = builder::Cargo::new_for_mir_opt_tests(
242+
builder,
243+
compiler,
244+
Mode::Std,
245+
SourceType::InTree,
246+
target,
247+
"check",
248+
);
248249
cargo.rustflag("-Zalways-encode-mir");
249250
cargo.arg("--manifest-path").arg(builder.src.join("library/sysroot/Cargo.toml"));
251+
cargo
250252
} else {
253+
let mut cargo = builder::Cargo::new(
254+
builder,
255+
compiler,
256+
Mode::Std,
257+
SourceType::InTree,
258+
target,
259+
"build",
260+
);
251261
std_cargo(builder, target, compiler.stage, &mut cargo);
252262
for krate in &*self.crates {
253263
cargo.arg("-p").arg(krate);
254264
}
265+
cargo
255266
};
256267

257268
// See src/bootstrap/synthetic_targets.rs
@@ -915,8 +926,15 @@ impl Step for Rustc {
915926
builder.config.build,
916927
));
917928

918-
let mut cargo =
919-
builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build", false);
929+
let mut cargo = builder::Cargo::new(
930+
builder,
931+
compiler,
932+
Mode::Rustc,
933+
SourceType::InTree,
934+
target,
935+
"build",
936+
);
937+
920938
rustc_cargo(builder, &mut cargo, target, compiler.stage);
921939

922940
if builder.config.rust_profile_use.is_some()
@@ -1336,8 +1354,14 @@ impl Step for CodegenBackend {
13361354

13371355
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
13381356

1339-
let mut cargo =
1340-
builder.cargo(compiler, Mode::Codegen, SourceType::InTree, target, "build", false);
1357+
let mut cargo = builder::Cargo::new(
1358+
builder,
1359+
compiler,
1360+
Mode::Codegen,
1361+
SourceType::InTree,
1362+
target,
1363+
"build",
1364+
);
13411365
cargo
13421366
.arg("--manifest-path")
13431367
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));

Diff for: src/bootstrap/src/core/build_steps/doc.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{fs, mem};
1313

1414
use crate::core::build_steps::compile;
1515
use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool};
16-
use crate::core::builder::crate_description;
16+
use crate::core::builder::{self, crate_description};
1717
use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1818
use crate::core::config::{Config, TargetSelection};
1919
use crate::utils::cache::{Interned, INTERNER};
@@ -684,7 +684,9 @@ fn doc_std(
684684
// as a function parameter.
685685
let out_dir = target_dir.join(target.triple).join("doc");
686686

687-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "doc", false);
687+
let mut cargo =
688+
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "doc");
689+
688690
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
689691
cargo
690692
.arg("--no-deps")
@@ -786,7 +788,8 @@ impl Step for Rustc {
786788

787789
// Build cargo command.
788790
let mut cargo =
789-
builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc", false);
791+
builder::Cargo::new(builder, compiler, Mode::Rustc, SourceType::InTree, target, "doc");
792+
790793
cargo.rustdocflag("--document-private-items");
791794
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
792795
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");

Diff for: src/bootstrap/src/core/build_steps/run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Step for Miri {
165165
SourceType::InTree,
166166
&[],
167167
);
168-
miri.add_rustc_lib_path(builder, compiler);
168+
miri.add_rustc_lib_path(builder);
169169
// Forward arguments.
170170
miri.arg("--").arg("--target").arg(target.rustc_target_arg());
171171
miri.args(builder.config.args());

Diff for: src/bootstrap/src/core/build_steps/test.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::core::build_steps::llvm;
2020
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
2121
use crate::core::build_steps::tool::{self, SourceType, Tool};
2222
use crate::core::build_steps::toolstate::ToolState;
23+
use crate::core::builder;
2324
use crate::core::builder::crate_description;
2425
use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
2526
use crate::core::config::flags::get_completion;
@@ -380,7 +381,7 @@ impl Step for RustAnalyzer {
380381
// work in Rust CI
381382
cargo.env("SKIP_SLOW_TESTS", "1");
382383

383-
cargo.add_rustc_lib_path(builder, compiler);
384+
cargo.add_rustc_lib_path(builder);
384385
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder);
385386
}
386387
}
@@ -426,7 +427,7 @@ impl Step for Rustfmt {
426427
t!(fs::create_dir_all(&dir));
427428
cargo.env("RUSTFMT_TEST_DIR", dir);
428429

429-
cargo.add_rustc_lib_path(builder, compiler);
430+
cargo.add_rustc_lib_path(builder);
430431

431432
run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder);
432433
}
@@ -476,7 +477,7 @@ impl Step for RustDemangler {
476477
t!(fs::create_dir_all(&dir));
477478

478479
cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
479-
cargo.add_rustc_lib_path(builder, compiler);
480+
cargo.add_rustc_lib_path(builder);
480481

481482
run_cargo_test(
482483
cargo,
@@ -517,7 +518,7 @@ impl Miri {
517518
SourceType::InTree,
518519
&[],
519520
);
520-
cargo.add_rustc_lib_path(builder, compiler);
521+
cargo.add_rustc_lib_path(builder);
521522
cargo.arg("--").arg("miri").arg("setup");
522523
cargo.arg("--target").arg(target.rustc_target_arg());
523524

@@ -618,7 +619,7 @@ impl Step for Miri {
618619
);
619620
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, target);
620621

621-
cargo.add_rustc_lib_path(builder, compiler);
622+
cargo.add_rustc_lib_path(builder);
622623

623624
// miri tests need to know about the stage sysroot
624625
cargo.env("MIRI_SYSROOT", &miri_sysroot);
@@ -671,7 +672,7 @@ impl Step for Miri {
671672
SourceType::Submodule,
672673
&[],
673674
);
674-
cargo.add_rustc_lib_path(builder, compiler);
675+
cargo.add_rustc_lib_path(builder);
675676
cargo.arg("--").arg("miri").arg("test");
676677
if builder.config.locked_deps {
677678
cargo.arg("--locked");
@@ -788,7 +789,7 @@ impl Step for Clippy {
788789
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
789790
cargo.env("HOST_LIBS", host_libs);
790791

791-
cargo.add_rustc_lib_path(builder, compiler);
792+
cargo.add_rustc_lib_path(builder);
792793
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
793794

794795
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
@@ -2499,8 +2500,15 @@ impl Step for Crate {
24992500
// we're working with automatically.
25002501
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
25012502

2502-
let mut cargo =
2503-
builder.cargo(compiler, mode, SourceType::InTree, target, builder.kind.as_str(), false);
2503+
let mut cargo = builder::Cargo::new(
2504+
builder,
2505+
compiler,
2506+
mode,
2507+
SourceType::InTree,
2508+
target,
2509+
builder.kind.as_str(),
2510+
);
2511+
25042512
match mode {
25052513
Mode::Std => {
25062514
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -3134,14 +3142,15 @@ impl Step for CodegenCranelift {
31343142
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
31353143

31363144
let build_cargo = || {
3137-
let mut cargo = builder.cargo(
3145+
let mut cargo = builder::Cargo::new(
3146+
builder,
31383147
compiler,
31393148
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
31403149
SourceType::InTree,
31413150
target,
31423151
"run",
3143-
false,
31443152
);
3153+
31453154
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_cranelift"));
31463155
cargo
31473156
.arg("--manifest-path")
@@ -3261,14 +3270,15 @@ impl Step for CodegenGCC {
32613270
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
32623271

32633272
let build_cargo = || {
3264-
let mut cargo = builder.cargo(
3273+
let mut cargo = builder::Cargo::new(
3274+
builder,
32653275
compiler,
32663276
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
32673277
SourceType::InTree,
32683278
target,
32693279
"run",
3270-
false,
32713280
);
3281+
32723282
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_gcc"));
32733283
cargo
32743284
.arg("--manifest-path")

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::process::Command;
55

66
use crate::core::build_steps::compile;
77
use crate::core::build_steps::toolstate::ToolState;
8+
use crate::core::builder;
89
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
910
use crate::core::config::TargetSelection;
1011
use crate::utils::channel::GitInfo;
@@ -142,7 +143,8 @@ pub fn prepare_tool_cargo(
142143
source_type: SourceType,
143144
extra_features: &[String],
144145
) -> CargoCommand {
145-
let mut cargo = builder.cargo(compiler, mode, source_type, target, command, false);
146+
let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, command);
147+
146148
let dir = builder.src.join(path);
147149
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
148150

0 commit comments

Comments
 (0)