Skip to content

Commit

Permalink
abstract configure_linker from Builder::cargo
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Feb 10, 2024
1 parent 993c72f commit f094467
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 168 deletions.
11 changes: 7 additions & 4 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ impl Step for Std {
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
false,
);
cargo.configure_linker(builder);

std_cargo(builder, target, compiler.stage, &mut cargo);
if matches!(builder.config.cmd, Subcommand::Fix { .. }) {
// By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot.
Expand Down Expand Up @@ -169,8 +170,8 @@ impl Step for Std {
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
false,
);
cargo.configure_linker(builder);

// If we're not in stage 0, tests and examples will fail to compile
// from `core` definitions being loaded from two different `libcore`
Expand Down Expand Up @@ -264,8 +265,9 @@ impl Step for Rustc {
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
false,
);
cargo.configure_linker(builder);

rustc_cargo(builder, &mut cargo, target, compiler.stage);

// For ./x.py clippy, don't run with --all-targets because
Expand Down Expand Up @@ -341,8 +343,9 @@ impl Step for CodegenBackend {
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
false,
);
cargo.configure_linker(builder);

cargo
.arg("--manifest-path")
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
Expand Down
11 changes: 6 additions & 5 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ impl Step for Std {
SourceType::InTree,
target,
if self.is_for_mir_opt_tests { "check" } else { "build" },
self.is_for_mir_opt_tests,
);
// 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
Expand All @@ -248,6 +247,7 @@ impl Step for Std {
cargo.rustflag("-Zalways-encode-mir");
cargo.arg("--manifest-path").arg(builder.src.join("library/sysroot/Cargo.toml"));
} else {
cargo.configure_linker(builder);
std_cargo(builder, target, compiler.stage, &mut cargo);
for krate in &*self.crates {
cargo.arg("-p").arg(krate);
Expand Down Expand Up @@ -915,8 +915,9 @@ impl Step for Rustc {
builder.config.build,
));

let mut cargo =
builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build", false);
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build");
cargo.configure_linker(builder);

rustc_cargo(builder, &mut cargo, target, compiler.stage);

if builder.config.rust_profile_use.is_some()
Expand Down Expand Up @@ -1336,8 +1337,8 @@ impl Step for CodegenBackend {

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

let mut cargo =
builder.cargo(compiler, Mode::Codegen, SourceType::InTree, target, "build", false);
let mut cargo = builder.cargo(compiler, Mode::Codegen, SourceType::InTree, target, "build");
cargo.configure_linker(builder);
cargo
.arg("--manifest-path")
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
Expand Down
9 changes: 6 additions & 3 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,9 @@ fn doc_std(
// as a function parameter.
let out_dir = target_dir.join(target.triple).join("doc");

let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "doc", false);
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "doc");
cargo.configure_linker(builder);

compile::std_cargo(builder, target, compiler.stage, &mut cargo);
cargo
.arg("--no-deps")
Expand Down Expand Up @@ -785,8 +787,9 @@ impl Step for Rustc {
);

// Build cargo command.
let mut cargo =
builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc", false);
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
cargo.configure_linker(builder);

cargo.rustdocflag("--document-private-items");
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Step for Miri {
SourceType::InTree,
&[],
);
miri.add_rustc_lib_path(builder, compiler);
miri.add_rustc_lib_path(builder);
// Forward arguments.
miri.arg("--").arg("--target").arg(target.rustc_target_arg());
miri.args(builder.config.args());
Expand Down
24 changes: 14 additions & 10 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl Step for RustAnalyzer {
// work in Rust CI
cargo.env("SKIP_SLOW_TESTS", "1");

cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder);
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ impl Step for Rustfmt {
t!(fs::create_dir_all(&dir));
cargo.env("RUSTFMT_TEST_DIR", dir);

cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);

run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder);
}
Expand Down Expand Up @@ -476,7 +476,7 @@ impl Step for RustDemangler {
t!(fs::create_dir_all(&dir));

cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);

run_cargo_test(
cargo,
Expand Down Expand Up @@ -517,7 +517,7 @@ impl Miri {
SourceType::InTree,
&[],
);
cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);
cargo.arg("--").arg("miri").arg("setup");
cargo.arg("--target").arg(target.rustc_target_arg());

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

cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);

// miri tests need to know about the stage sysroot
cargo.env("MIRI_SYSROOT", &miri_sysroot);
Expand Down Expand Up @@ -671,7 +671,7 @@ impl Step for Miri {
SourceType::Submodule,
&[],
);
cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);
cargo.arg("--").arg("miri").arg("test");
if builder.config.locked_deps {
cargo.arg("--locked");
Expand Down Expand Up @@ -788,7 +788,7 @@ impl Step for Clippy {
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
cargo.env("HOST_LIBS", host_libs);

cargo.add_rustc_lib_path(builder, compiler);
cargo.add_rustc_lib_path(builder);
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);

let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
Expand Down Expand Up @@ -2500,7 +2500,9 @@ impl Step for Crate {
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);

let mut cargo =
builder.cargo(compiler, mode, SourceType::InTree, target, builder.kind.as_str(), false);
builder.cargo(compiler, mode, SourceType::InTree, target, builder.kind.as_str());
cargo.configure_linker(builder);

match mode {
Mode::Std => {
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
Expand Down Expand Up @@ -3140,8 +3142,9 @@ impl Step for CodegenCranelift {
SourceType::InTree,
target,
"run",
false,
);
cargo.configure_linker(builder);

cargo.current_dir(&builder.src.join("compiler/rustc_codegen_cranelift"));
cargo
.arg("--manifest-path")
Expand Down Expand Up @@ -3267,8 +3270,9 @@ impl Step for CodegenGCC {
SourceType::InTree,
target,
"run",
false,
);
cargo.configure_linker(builder);

cargo.current_dir(&builder.src.join("compiler/rustc_codegen_gcc"));
cargo
.arg("--manifest-path")
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ pub fn prepare_tool_cargo(
source_type: SourceType,
extra_features: &[String],
) -> CargoCommand {
let mut cargo = builder.cargo(compiler, mode, source_type, target, command, false);
let mut cargo = builder.cargo(compiler, mode, source_type, target, command);
cargo.configure_linker(builder);

let dir = builder.src.join(path);
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));

Expand Down
Loading

0 comments on commit f094467

Please sign in to comment.