Skip to content
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

centralize build stamp logic #135281

Merged
merged 23 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
58306c6
implement `BuildStamp` that is stricter impl for build stamps
onur-ozkan Jan 9, 2025
e3de3c7
use `BuildStamp` instead of std paths and strings
onur-ozkan Jan 9, 2025
c68c721
migrate `HashStamp` to `BuildStamp`
onur-ozkan Jan 9, 2025
9e92975
migrate helper stamp functions
onur-ozkan Jan 9, 2025
236d580
migrate `Builder::clear_if_dirty`
onur-ozkan Jan 9, 2025
9e1c9fd
document `build_stamp` implementation
onur-ozkan Jan 9, 2025
cacb4fe
add test coverage for `build_stamp` implementation
onur-ozkan Jan 9, 2025
615131b
migrate `generate_smart_stamp_hash`
onur-ozkan Jan 9, 2025
9e86d76
fix compiler errors
onur-ozkan Jan 9, 2025
1fa6657
fix an invalid prefix usage on enzyme
onur-ozkan Jan 9, 2025
9878d63
add coverage for `BuildStamp::with_prefix`
onur-ozkan Jan 9, 2025
a72068a
migrate `program_out_of_date` to `BuildStamp::is_up_to_date`
onur-ozkan Jan 9, 2025
3751652
auto label `A-bootstrap-stamp`
onur-ozkan Jan 9, 2025
bdb7518
apply minor improvements on build_stamp
onur-ozkan Jan 11, 2025
ffd4c5b
migrate lld build stamp
onur-ozkan Jan 11, 2025
216969b
run git only inside the current directory
onur-ozkan Jan 11, 2025
99322a5
extend sanitizers stamp calculation
onur-ozkan Jan 11, 2025
dcc001a
refactor `with_stamp` as `add_stamp` for incrementality
onur-ozkan Jan 12, 2025
9611d8e
avoid magical `AsRef<Path>` implementation
onur-ozkan Jan 12, 2025
fae26e7
add change entry for renamings
onur-ozkan Jan 12, 2025
b54d652
rustc-dev-guide: update outdated LLVM stamp filename
onur-ozkan Jan 12, 2025
b03fba7
rename `done_stamp` to `lld_stamp`
onur-ozkan Jan 12, 2025
2a4bcf5
update doc-comment of `BuildStamp::add_stamp`
onur-ozkan Jan 12, 2025
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
119 changes: 25 additions & 94 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Implementation of compiling the compiler and standard library, in "check"-based modes.

use std::path::PathBuf;

use crate::core::build_steps::compile::{
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
};
Expand All @@ -10,7 +8,8 @@ use crate::core::builder::{
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, crate_description,
};
use crate::core::config::TargetSelection;
use crate::{Compiler, Mode, Subcommand};
use crate::utils::build_stamp::{self, BuildStamp};
use crate::{Mode, Subcommand};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Std {
Expand Down Expand Up @@ -83,22 +82,16 @@ impl Step for Std {
format_args!("library artifacts{}", crate_description(&self.crates)),
target,
);
run_cargo(
builder,
cargo,
builder.config.free_args.clone(),
&libstd_stamp(builder, compiler, target),
vec![],
true,
false,
);

let stamp = build_stamp::libstd_stamp(builder, compiler, target).with_prefix("check");
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);

// We skip populating the sysroot in non-zero stage because that'll lead
// to rlib/rmeta conflicts if std gets built during this session.
if compiler.stage == 0 {
let libdir = builder.sysroot_target_libdir(compiler, target);
let hostdir = builder.sysroot_target_libdir(compiler, compiler.host);
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
add_to_sysroot(builder, &libdir, &hostdir, &stamp);
}
drop(_guard);

Expand Down Expand Up @@ -139,16 +132,9 @@ impl Step for Std {
cargo.arg("-p").arg(krate);
}

let stamp = build_stamp::libstd_stamp(builder, compiler, target).with_prefix("check-test");
let _guard = builder.msg_check("library test/bench/example targets", target);
run_cargo(
builder,
cargo,
builder.config.free_args.clone(),
&libstd_test_stamp(builder, compiler, target),
vec![],
true,
false,
);
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
}
}

Expand Down Expand Up @@ -249,19 +235,14 @@ impl Step for Rustc {
format_args!("compiler artifacts{}", crate_description(&self.crates)),
target,
);
run_cargo(
builder,
cargo,
builder.config.free_args.clone(),
&librustc_stamp(builder, compiler, target),
vec![],
true,
false,
);

let stamp = build_stamp::librustc_stamp(builder, compiler, target).with_prefix("check");

run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);

let libdir = builder.sysroot_target_libdir(compiler, target);
let hostdir = builder.sysroot_target_libdir(compiler, compiler.host);
add_to_sysroot(builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
add_to_sysroot(builder, &libdir, &hostdir, &stamp);
}
}

Expand Down Expand Up @@ -315,15 +296,10 @@ impl Step for CodegenBackend {

let _guard = builder.msg_check(backend, target);

run_cargo(
builder,
cargo,
builder.config.free_args.clone(),
&codegen_backend_stamp(builder, compiler, target, backend),
vec![],
true,
false,
);
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend)
.with_prefix("check");

run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
}
}

Expand Down Expand Up @@ -380,22 +356,13 @@ impl Step for RustAnalyzer {
cargo.arg("--benches");
}

let _guard = builder.msg_check("rust-analyzer artifacts", target);
run_cargo(
builder,
cargo,
builder.config.free_args.clone(),
&stamp(builder, compiler, target),
vec![],
true,
false,
);
// Cargo's output path in a given stage, compiled by a particular
// compiler for the specified target.
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
.with_prefix("rust-analyzer-check");

/// Cargo's output path in a given stage, compiled by a particular
/// compiler for the specified target.
fn stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rust-analyzer-check.stamp")
}
let _guard = builder.msg_check("rust-analyzer artifacts", target);
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
}
}

Expand Down Expand Up @@ -469,9 +436,8 @@ fn run_tool_check_step(
cargo.arg("--all-targets");
}

let stamp = builder
.cargo_out(compiler, Mode::ToolRustc, target)
.join(format!(".{}-check.stamp", step_type_name.to_lowercase()));
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
.with_prefix(&format!("{}-check", step_type_name.to_lowercase()));

let _guard = builder.msg_check(format!("{display_name} artifacts"), target);
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
Expand Down Expand Up @@ -499,38 +465,3 @@ tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: f
// Compiletest is implicitly "checked" when it gets built in order to run tests,
// so this is mainly for people working on compiletest to run locally.
tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
}

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_test_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: TargetSelection,
) -> PathBuf {
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check-test.stamp")
}

/// Cargo's output path for librustc in a given stage, compiled by a particular
/// compiler for the specified target.
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
}

/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
/// compiler for the specified target and backend.
fn codegen_backend_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: TargetSelection,
backend: &str,
) -> PathBuf {
builder
.cargo_out(compiler, Mode::Codegen, target)
.join(format!(".librustc_codegen_{backend}-check.stamp"))
}
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::io::{self, ErrorKind};
use std::path::Path;

use crate::core::builder::{Builder, RunConfig, ShouldRun, Step, crate_description};
use crate::utils::build_stamp::BuildStamp;
use crate::utils::helpers::t;
use crate::{Build, Compiler, Kind, Mode, Subcommand};

Expand Down Expand Up @@ -146,7 +147,7 @@ fn clean_default(build: &Build) {
rm_rf(&build.out.join("dist"));
rm_rf(&build.out.join("bootstrap").join(".last-warned-change-id"));
rm_rf(&build.out.join("bootstrap-shims-dump"));
rm_rf(&build.out.join("rustfmt.stamp"));
rm_rf(BuildStamp::new(&build.out).with_prefix("rustfmt").path());

let mut hosts: Vec<_> = build.hosts.iter().map(|t| build.out.join(t)).collect();
// After cross-compilation, artifacts of the host architecture (which may differ from build.host)
Expand Down
13 changes: 7 additions & 6 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Implementation of running clippy on the compiler, standard library and various tools.

use super::compile::{librustc_stamp, libstd_stamp, run_cargo, rustc_cargo, std_cargo};
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;
use crate::core::builder::{Alias, Kind, RunConfig, Step, crate_description};
use crate::utils::build_stamp::{self, BuildStamp};
use crate::{Mode, Subcommand, TargetSelection};

/// Disable the most spammy clippy lints
Expand Down Expand Up @@ -167,7 +168,7 @@ impl Step for Std {
builder,
cargo,
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
&libstd_stamp(builder, compiler, target),
&build_stamp::libstd_stamp(builder, compiler, target),
vec![],
true,
false,
Expand Down Expand Up @@ -243,7 +244,7 @@ impl Step for Rustc {
builder,
cargo,
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
&librustc_stamp(builder, compiler, target),
&build_stamp::librustc_stamp(builder, compiler, target),
vec![],
true,
false,
Expand Down Expand Up @@ -307,9 +308,9 @@ macro_rules! lint_any {
&target,
);

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

run_cargo(
builder,
Expand Down
Loading
Loading