Skip to content

Commit

Permalink
improve staging api
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 5, 2025
1 parent 79b6c4b commit 01fcb0d
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 216 deletions.
10 changes: 5 additions & 5 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Step for Std {
builder.require_submodule("library/stdarch", None);

let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, false);

let mut cargo = builder::Cargo::new(
builder,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Step for Rustc {
/// the `compiler` targeting the `target` architecture. The artifacts
/// created will also be linked into the sysroot directory.
fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, false);
let target = self.target;

if compiler.stage != 0 {
Expand Down Expand Up @@ -274,7 +274,7 @@ impl Step for CodegenBackend {
return;
}

let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, false);
let target = self.target;
let backend = self.backend;

Expand Down Expand Up @@ -329,7 +329,7 @@ impl Step for RustAnalyzer {
}

fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, true);
let target = self.target;

builder.ensure(Rustc::new(target, builder));
Expand Down Expand Up @@ -411,7 +411,7 @@ fn run_tool_check_step(
path: &str,
) {
let display_name = path.rsplit('/').next().unwrap();
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, true);

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

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! clean_crate_tree {

fn make_run(run: RunConfig<'_>) {
let builder = run.builder;
let compiler = builder.compiler(builder.top_stage, run.target);
let compiler = builder.compiler(builder.top_stage, run.target, false);
builder.ensure(Self { crates: run.cargo_crates_in_set(), compiler });
}

Expand Down
64 changes: 32 additions & 32 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Step for Std {
builder.require_submodule("library/stdarch", None);

let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, false);

let mut cargo = builder::Cargo::new(
builder,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl Step for Rustc {
/// This will lint the compiler for a particular stage of the build using
/// the `compiler` targeting the `target` architecture.
fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, false);
let target = self.target;

if compiler.stage != 0 {
Expand Down Expand Up @@ -254,7 +254,7 @@ impl Step for Rustc {

macro_rules! lint_any {
($(
$name:ident, $path:expr, $readable_name:expr
$name:ident, $path:expr, $readable_name:expr, $mode:expr
$(,lint_by_default = $lint_by_default:expr)*
;
)+) => {
Expand Down Expand Up @@ -283,15 +283,15 @@ macro_rules! lint_any {
}

fn run(self, builder: &Builder<'_>) -> Self::Output {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let compiler = builder.compiler(builder.top_stage, builder.config.build, $mode == Mode::ToolRustc);
let target = self.target;

builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check)));

let cargo = prepare_tool_cargo(
builder,
compiler,
Mode::ToolRustc,
$mode,
target,
Kind::Clippy,
$path,
Expand All @@ -301,15 +301,15 @@ macro_rules! lint_any {

let _guard = builder.msg_tool(
Kind::Clippy,
Mode::ToolRustc,
$mode,
$readable_name,
compiler.stage,
&compiler.host,
&target,
);

let stringified_name = stringify!($name).to_lowercase();
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
let stamp = BuildStamp::new(&builder.cargo_out(compiler, $mode, target))
.with_prefix(&format!("{}-check", stringified_name));

run_cargo(
Expand All @@ -328,31 +328,31 @@ macro_rules! lint_any {
}

lint_any!(
Bootstrap, "src/bootstrap", "bootstrap";
BuildHelper, "src/build_helper", "build_helper";
BuildManifest, "src/tools/build-manifest", "build-manifest";
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri";
Clippy, "src/tools/clippy", "clippy";
CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata";
CodegenGcc, "compiler/rustc_codegen_gcc", "rustc-codegen-gcc";
Compiletest, "src/tools/compiletest", "compiletest";
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
Jsondocck, "src/tools/jsondocck", "jsondocck";
Jsondoclint, "src/tools/jsondoclint", "jsondoclint";
LintDocs, "src/tools/lint-docs", "lint-docs";
LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker";
Miri, "src/tools/miri", "miri";
MiroptTestTools, "src/tools/miropt-test-tools", "miropt-test-tools";
OptDist, "src/tools/opt-dist", "opt-dist";
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
RemoteTestServer, "src/tools/remote-test-server", "remote-test-server";
Rls, "src/tools/rls", "rls";
RustAnalyzer, "src/tools/rust-analyzer", "rust-analyzer";
Rustdoc, "src/librustdoc", "clippy";
Rustfmt, "src/tools/rustfmt", "rustfmt";
RustInstaller, "src/tools/rust-installer", "rust-installer";
Tidy, "src/tools/tidy", "tidy";
TestFloatParse, "src/etc/test-float-parse", "test-float-parse";
Bootstrap, "src/bootstrap", "bootstrap", Mode::ToolBootstrap;
BuildHelper, "src/build_helper", "build_helper", Mode::ToolBootstrap;
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", Mode::ToolRustc;
Clippy, "src/tools/clippy", "clippy", Mode::ToolRustc;
CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata", Mode::ToolBootstrap;
CodegenGcc, "compiler/rustc_codegen_gcc", "rustc-codegen-gcc", Mode::ToolRustc;
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap;
CoverageDump, "src/tools/coverage-dump", "coverage-dump", Mode::ToolBootstrap;
Jsondocck, "src/tools/jsondocck", "jsondocck", Mode::ToolBootstrap;
Jsondoclint, "src/tools/jsondoclint", "jsondoclint", Mode::ToolBootstrap;
LintDocs, "src/tools/lint-docs", "lint-docs", Mode::ToolBootstrap;
LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker", Mode::ToolRustc;
Miri, "src/tools/miri", "miri", Mode::ToolRustc;
MiroptTestTools, "src/tools/miropt-test-tools", "miropt-test-tools", Mode::ToolRustc;
OptDist, "src/tools/opt-dist", "opt-dist", Mode::ToolBootstrap;
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
RemoteTestServer, "src/tools/remote-test-server", "remote-test-server", Mode::ToolBootstrap;
Rls, "src/tools/rls", "rls", Mode::ToolBootstrap;
RustAnalyzer, "src/tools/rust-analyzer", "rust-analyzer", Mode::ToolRustc;
Rustdoc, "src/librustdoc", "clippy", Mode::ToolRustc;
Rustfmt, "src/tools/rustfmt", "rustfmt", Mode::ToolRustc;
RustInstaller, "src/tools/rust-installer", "rust-installer", Mode::ToolBootstrap;
Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
TestFloatParse, "src/etc/test-float-parse", "test-float-parse", Mode::ToolStd;
);

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
35 changes: 20 additions & 15 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Step for Std {
&& builder.config.last_modified_commit(&["library"], "download-rustc", true).is_none();

run.builder.ensure(Std {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple(), false),
target: run.target,
crates,
force_recompile,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl Step for Std {

let mut target_deps = builder.ensure(StartupObjects { compiler, target });

let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target, false);
if compiler_to_use != compiler {
builder.ensure(Std::new(compiler_to_use, target));
let msg = if compiler_to_use.host == target {
Expand Down Expand Up @@ -264,7 +264,7 @@ impl Step for Std {

builder.ensure(StdLink::from_std(
self,
builder.compiler(compiler.stage, builder.config.build),
builder.compiler(compiler.stage, builder.config.build, false),
));
}
}
Expand Down Expand Up @@ -770,7 +770,7 @@ impl Step for StartupObjects {

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(StartupObjects {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple(), false),
target: run.target,
});
}
Expand Down Expand Up @@ -894,7 +894,7 @@ impl Step for Rustc {
fn make_run(run: RunConfig<'_>) {
let crates = run.cargo_crates_in_set();
run.builder.ensure(Rustc {
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple(), false),
target: run.target,
crates,
});
Expand Down Expand Up @@ -931,9 +931,9 @@ impl Step for Rustc {
return compiler.stage;
}

let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target, false);
if compiler_to_use != compiler {
let _ = builder.compiler(compiler_to_use.stage, target);
let _ = builder.compiler(compiler_to_use.stage, target, false);

let msg = if compiler_to_use.host == target {
format!(
Expand All @@ -957,7 +957,7 @@ impl Step for Rustc {

// Ensure that build scripts and proc macros have a std / libproc_macro to link against.
builder.ensure(Std::new(
builder.compiler(self.compiler.stage, builder.config.build),
builder.compiler(self.compiler.stage, builder.config.build, false),
builder.config.build,
));

Expand Down Expand Up @@ -1023,7 +1023,7 @@ impl Step for Rustc {

builder.ensure(RustcLink::from_rustc(
self,
builder.compiler(compiler.stage, builder.config.build),
builder.compiler(compiler.stage, builder.config.build, false),
));

compiler.stage
Expand Down Expand Up @@ -1424,7 +1424,7 @@ impl Step for CodegenBackend {

run.builder.ensure(CodegenBackend {
target: run.target,
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple(), false),
backend: backend.clone(),
});
}
Expand All @@ -1435,7 +1435,7 @@ impl Step for CodegenBackend {
let target = self.target;
let backend = self.backend;

let _ = builder.compiler(compiler.stage, target);
let _ = builder.compiler(compiler.stage, target, false);

if builder.config.keep_stage.contains(&compiler.stage) {
builder.info(
Expand All @@ -1447,7 +1447,7 @@ impl Step for CodegenBackend {
return;
}

let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target, false);
if compiler_to_use != compiler {
builder.ensure(CodegenBackend { compiler: compiler_to_use, target, backend });
return;
Expand Down Expand Up @@ -1745,7 +1745,7 @@ impl Step for Assemble {

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Assemble {
target_compiler: run.builder.compiler(run.builder.top_stage + 1, run.target),
target_compiler: run.builder.compiler(run.builder.top_stage + 1, run.target, false),
});
}

Expand Down Expand Up @@ -1846,7 +1846,8 @@ impl Step for Assemble {
//
// FIXME: It may be faster if we build just a stage 1 compiler and then
// use that to bootstrap this compiler forward.
let mut build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build);
let mut build_compiler =
builder.compiler(target_compiler.stage - 1, builder.config.build, false);

// Build enzyme
let enzyme_install = if builder.config.llvm_enzyme {
Expand Down Expand Up @@ -1989,7 +1990,11 @@ impl Step for Assemble {
);
}

maybe_install_llvm_bitcode_linker(target_compiler);
{
let mut compiler_for_rustc_tool = build_compiler;
compiler_for_rustc_tool.downgraded_from = Some(target_compiler.stage);
maybe_install_llvm_bitcode_linker(compiler_for_rustc_tool);
}

// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
// so that it can be found when the newly built `rustc` is run.
Expand Down
Loading

0 comments on commit 01fcb0d

Please sign in to comment.