Skip to content

Commit 627513a

Browse files
committed
Auto merge of #135281 - onur-ozkan:build-stamps, r=jieyouxu
centralize build stamp logic This PR brings all the stamp file handling into one place inside `build_stamp` module, which takes care of everything related to build stamps. By doing this, we cut down on duplicated code and types and keep the codebase easier to maintain and more consistent. Main goals are: - Make stamp handling stricter so we don't have to pass `Path`s around and manually `join` on arbitrary directories - Keep all stamp-related logic in one place - Make it easier to test and debug - Avoid duplication - Keep things simple and well-documented Resolves #134962
2 parents 7bb9888 + 2a4bcf5 commit 627513a

File tree

21 files changed

+434
-362
lines changed

21 files changed

+434
-362
lines changed

src/bootstrap/src/core/build_steps/check.rs

+25-94
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use std::path::PathBuf;
4-
53
use crate::core::build_steps::compile::{
64
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
75
};
@@ -10,7 +8,8 @@ use crate::core::builder::{
108
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, crate_description,
119
};
1210
use crate::core::config::TargetSelection;
13-
use crate::{Compiler, Mode, Subcommand};
11+
use crate::utils::build_stamp::{self, BuildStamp};
12+
use crate::{Mode, Subcommand};
1413

1514
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1615
pub struct Std {
@@ -83,22 +82,16 @@ impl Step for Std {
8382
format_args!("library artifacts{}", crate_description(&self.crates)),
8483
target,
8584
);
86-
run_cargo(
87-
builder,
88-
cargo,
89-
builder.config.free_args.clone(),
90-
&libstd_stamp(builder, compiler, target),
91-
vec![],
92-
true,
93-
false,
94-
);
85+
86+
let stamp = build_stamp::libstd_stamp(builder, compiler, target).with_prefix("check");
87+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
9588

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

@@ -139,16 +132,9 @@ impl Step for Std {
139132
cargo.arg("-p").arg(krate);
140133
}
141134

135+
let stamp = build_stamp::libstd_stamp(builder, compiler, target).with_prefix("check-test");
142136
let _guard = builder.msg_check("library test/bench/example targets", target);
143-
run_cargo(
144-
builder,
145-
cargo,
146-
builder.config.free_args.clone(),
147-
&libstd_test_stamp(builder, compiler, target),
148-
vec![],
149-
true,
150-
false,
151-
);
137+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
152138
}
153139
}
154140

@@ -249,19 +235,14 @@ impl Step for Rustc {
249235
format_args!("compiler artifacts{}", crate_description(&self.crates)),
250236
target,
251237
);
252-
run_cargo(
253-
builder,
254-
cargo,
255-
builder.config.free_args.clone(),
256-
&librustc_stamp(builder, compiler, target),
257-
vec![],
258-
true,
259-
false,
260-
);
238+
239+
let stamp = build_stamp::librustc_stamp(builder, compiler, target).with_prefix("check");
240+
241+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
261242

262243
let libdir = builder.sysroot_target_libdir(compiler, target);
263244
let hostdir = builder.sysroot_target_libdir(compiler, compiler.host);
264-
add_to_sysroot(builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
245+
add_to_sysroot(builder, &libdir, &hostdir, &stamp);
265246
}
266247
}
267248

@@ -315,15 +296,10 @@ impl Step for CodegenBackend {
315296

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

318-
run_cargo(
319-
builder,
320-
cargo,
321-
builder.config.free_args.clone(),
322-
&codegen_backend_stamp(builder, compiler, target, backend),
323-
vec![],
324-
true,
325-
false,
326-
);
299+
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend)
300+
.with_prefix("check");
301+
302+
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
327303
}
328304
}
329305

@@ -380,22 +356,13 @@ impl Step for RustAnalyzer {
380356
cargo.arg("--benches");
381357
}
382358

383-
let _guard = builder.msg_check("rust-analyzer artifacts", target);
384-
run_cargo(
385-
builder,
386-
cargo,
387-
builder.config.free_args.clone(),
388-
&stamp(builder, compiler, target),
389-
vec![],
390-
true,
391-
false,
392-
);
359+
// Cargo's output path in a given stage, compiled by a particular
360+
// compiler for the specified target.
361+
let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
362+
.with_prefix("rust-analyzer-check");
393363

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

@@ -469,9 +436,8 @@ fn run_tool_check_step(
469436
cargo.arg("--all-targets");
470437
}
471438

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

476442
let _guard = builder.msg_check(format!("{display_name} artifacts"), target);
477443
run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false);
@@ -499,38 +465,3 @@ tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: f
499465
// Compiletest is implicitly "checked" when it gets built in order to run tests,
500466
// so this is mainly for people working on compiletest to run locally.
501467
tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });
502-
503-
/// Cargo's output path for the standard library in a given stage, compiled
504-
/// by a particular compiler for the specified target.
505-
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
506-
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
507-
}
508-
509-
/// Cargo's output path for the standard library in a given stage, compiled
510-
/// by a particular compiler for the specified target.
511-
fn libstd_test_stamp(
512-
builder: &Builder<'_>,
513-
compiler: Compiler,
514-
target: TargetSelection,
515-
) -> PathBuf {
516-
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check-test.stamp")
517-
}
518-
519-
/// Cargo's output path for librustc in a given stage, compiled by a particular
520-
/// compiler for the specified target.
521-
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
522-
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
523-
}
524-
525-
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
526-
/// compiler for the specified target and backend.
527-
fn codegen_backend_stamp(
528-
builder: &Builder<'_>,
529-
compiler: Compiler,
530-
target: TargetSelection,
531-
backend: &str,
532-
) -> PathBuf {
533-
builder
534-
.cargo_out(compiler, Mode::Codegen, target)
535-
.join(format!(".librustc_codegen_{backend}-check.stamp"))
536-
}

src/bootstrap/src/core/build_steps/clean.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::io::{self, ErrorKind};
1010
use std::path::Path;
1111

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

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

151152
let mut hosts: Vec<_> = build.hosts.iter().map(|t| build.out.join(t)).collect();
152153
// After cross-compilation, artifacts of the host architecture (which may differ from build.host)

src/bootstrap/src/core/build_steps/clippy.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Implementation of running clippy on the compiler, standard library and various tools.
22
3-
use super::compile::{librustc_stamp, libstd_stamp, run_cargo, rustc_cargo, std_cargo};
3+
use super::compile::{run_cargo, rustc_cargo, std_cargo};
44
use super::tool::{SourceType, prepare_tool_cargo};
55
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;
99
use crate::core::builder::{Alias, Kind, RunConfig, Step, crate_description};
10+
use crate::utils::build_stamp::{self, BuildStamp};
1011
use crate::{Mode, Subcommand, TargetSelection};
1112

1213
/// Disable the most spammy clippy lints
@@ -167,7 +168,7 @@ impl Step for Std {
167168
builder,
168169
cargo,
169170
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
170-
&libstd_stamp(builder, compiler, target),
171+
&build_stamp::libstd_stamp(builder, compiler, target),
171172
vec![],
172173
true,
173174
false,
@@ -243,7 +244,7 @@ impl Step for Rustc {
243244
builder,
244245
cargo,
245246
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
246-
&librustc_stamp(builder, compiler, target),
247+
&build_stamp::librustc_stamp(builder, compiler, target),
247248
vec![],
248249
true,
249250
false,
@@ -307,9 +308,9 @@ macro_rules! lint_any {
307308
&target,
308309
);
309310

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

314315
run_cargo(
315316
builder,

0 commit comments

Comments
 (0)