Skip to content

Commit 9e92975

Browse files
committed
migrate helper stamp functions
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent c68c721 commit 9e92975

File tree

5 files changed

+79
-141
lines changed

5 files changed

+79
-141
lines changed

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

Lines changed: 23 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::core::builder::{
88
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, crate_description,
99
};
1010
use crate::core::config::TargetSelection;
11-
use crate::utils::build_stamp::BuildStamp;
12-
use crate::{Compiler, Mode, Subcommand};
11+
use crate::utils::build_stamp::{self, BuildStamp};
12+
use crate::{Mode, Subcommand};
1313

1414
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1515
pub struct Std {
@@ -82,22 +82,16 @@ impl Step for Std {
8282
format_args!("library artifacts{}", crate_description(&self.crates)),
8383
target,
8484
);
85-
run_cargo(
86-
builder,
87-
cargo,
88-
builder.config.free_args.clone(),
89-
&libstd_stamp(builder, compiler, target),
90-
vec![],
91-
true,
92-
false,
93-
);
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);
9488

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

@@ -138,16 +132,9 @@ impl Step for Std {
138132
cargo.arg("-p").arg(krate);
139133
}
140134

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

@@ -248,19 +235,14 @@ impl Step for Rustc {
248235
format_args!("compiler artifacts{}", crate_description(&self.crates)),
249236
target,
250237
);
251-
run_cargo(
252-
builder,
253-
cargo,
254-
builder.config.free_args.clone(),
255-
&librustc_stamp(builder, compiler, target),
256-
vec![],
257-
true,
258-
false,
259-
);
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);
260242

261243
let libdir = builder.sysroot_target_libdir(compiler, target);
262244
let hostdir = builder.sysroot_target_libdir(compiler, compiler.host);
263-
add_to_sysroot(builder, &libdir, &hostdir, &librustc_stamp(builder, compiler, target));
245+
add_to_sysroot(builder, &libdir, &hostdir, &stamp);
264246
}
265247
}
266248

@@ -314,15 +296,10 @@ impl Step for CodegenBackend {
314296

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

317-
run_cargo(
318-
builder,
319-
cargo,
320-
builder.config.free_args.clone(),
321-
&codegen_backend_stamp(builder, compiler, target, backend),
322-
vec![],
323-
true,
324-
false,
325-
);
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);
326303
}
327304
}
328305

@@ -379,23 +356,13 @@ impl Step for RustAnalyzer {
379356
cargo.arg("--benches");
380357
}
381358

382-
let _guard = builder.msg_check("rust-analyzer artifacts", target);
383-
run_cargo(
384-
builder,
385-
cargo,
386-
builder.config.free_args.clone(),
387-
&stamp(builder, compiler, target),
388-
vec![],
389-
true,
390-
false,
391-
);
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");
392363

393-
/// Cargo's output path in a given stage, compiled by a particular
394-
/// compiler for the specified target.
395-
fn stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> BuildStamp {
396-
BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target))
397-
.with_prefix("rust-analyzer-check")
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

@@ -498,42 +465,3 @@ tool_check_step!(RunMakeSupport { path: "src/tools/run-make-support", default: f
498465
// Compiletest is implicitly "checked" when it gets built in order to run tests,
499466
// so this is mainly for people working on compiletest to run locally.
500467
tool_check_step!(Compiletest { path: "src/tools/compiletest", default: false });
501-
502-
/// Cargo's output path for the standard library in a given stage, compiled
503-
/// by a particular compiler for the specified target.
504-
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> BuildStamp {
505-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target)).with_prefix("libstd-check")
506-
}
507-
508-
/// Cargo's output path for the standard library in a given stage, compiled
509-
/// by a particular compiler for the specified target.
510-
fn libstd_test_stamp(
511-
builder: &Builder<'_>,
512-
compiler: Compiler,
513-
target: TargetSelection,
514-
) -> BuildStamp {
515-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target))
516-
.with_prefix("libstd-check-test")
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(
522-
builder: &Builder<'_>,
523-
compiler: Compiler,
524-
target: TargetSelection,
525-
) -> BuildStamp {
526-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Rustc, target)).with_prefix("librustc-check")
527-
}
528-
529-
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
530-
/// compiler for the specified target and backend.
531-
fn codegen_backend_stamp(
532-
builder: &Builder<'_>,
533-
compiler: Compiler,
534-
target: TargetSelection,
535-
backend: &str,
536-
) -> BuildStamp {
537-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Codegen, target))
538-
.with_prefix(&format!("librustc_codegen_{backend}-check"))
539-
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +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::BuildStamp;
10+
use crate::utils::build_stamp::{self, BuildStamp};
1111
use crate::{Mode, Subcommand, TargetSelection};
1212

1313
/// Disable the most spammy clippy lints
@@ -168,7 +168,7 @@ impl Step for Std {
168168
builder,
169169
cargo,
170170
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
171-
&libstd_stamp(builder, compiler, target),
171+
&build_stamp::libstd_stamp(builder, compiler, target),
172172
vec![],
173173
true,
174174
false,
@@ -244,7 +244,7 @@ impl Step for Rustc {
244244
builder,
245245
cargo,
246246
lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC),
247-
&librustc_stamp(builder, compiler, target),
247+
&build_stamp::librustc_stamp(builder, compiler, target),
248248
vec![],
249249
true,
250250
false,

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::core::builder::{
2424
Builder, Cargo, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath, crate_description,
2525
};
2626
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
27+
use crate::utils::build_stamp;
2728
use crate::utils::build_stamp::BuildStamp;
2829
use crate::utils::exec::command;
2930
use crate::utils::helpers::{
@@ -255,7 +256,7 @@ impl Step for Std {
255256
builder,
256257
cargo,
257258
vec![],
258-
&libstd_stamp(builder, compiler, target),
259+
&build_stamp::libstd_stamp(builder, compiler, target),
259260
target_deps,
260261
self.is_for_mir_opt_tests, // is_check
261262
false,
@@ -645,7 +646,12 @@ impl Step for StdLink {
645646
(libdir, hostdir)
646647
};
647648

648-
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
649+
add_to_sysroot(
650+
builder,
651+
&libdir,
652+
&hostdir,
653+
&build_stamp::libstd_stamp(builder, compiler, target),
654+
);
649655

650656
// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
651657
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
@@ -974,7 +980,7 @@ impl Step for Rustc {
974980
compiler.host,
975981
target,
976982
);
977-
let stamp = librustc_stamp(builder, compiler, target);
983+
let stamp = build_stamp::librustc_stamp(builder, compiler, target);
978984
run_cargo(
979985
builder,
980986
cargo,
@@ -1330,7 +1336,7 @@ impl Step for RustcLink {
13301336
builder,
13311337
&builder.sysroot_target_libdir(previous_stage_compiler, target),
13321338
&builder.sysroot_target_libdir(previous_stage_compiler, compiler.host),
1333-
&librustc_stamp(builder, compiler, target),
1339+
&build_stamp::librustc_stamp(builder, compiler, target),
13341340
);
13351341
}
13361342
}
@@ -1470,7 +1476,7 @@ impl Step for CodegenBackend {
14701476
f.display()
14711477
);
14721478
}
1473-
let stamp = codegen_backend_stamp(builder, compiler, target, &backend);
1479+
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, &backend);
14741480
let codegen_backend = codegen_backend.to_str().unwrap();
14751481
t!(fs::write(stamp, codegen_backend));
14761482
}
@@ -1509,7 +1515,7 @@ fn copy_codegen_backends_to_sysroot(
15091515
continue; // Already built as part of rustc
15101516
}
15111517

1512-
let stamp = codegen_backend_stamp(builder, compiler, target, backend);
1518+
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend);
15131519
let dylib = t!(fs::read_to_string(&stamp));
15141520
let file = Path::new(&dylib);
15151521
let filename = file.file_name().unwrap().to_str().unwrap();
@@ -1524,38 +1530,6 @@ fn copy_codegen_backends_to_sysroot(
15241530
}
15251531
}
15261532

1527-
/// Cargo's output path for the standard library in a given stage, compiled
1528-
/// by a particular compiler for the specified target.
1529-
pub fn libstd_stamp(
1530-
builder: &Builder<'_>,
1531-
compiler: Compiler,
1532-
target: TargetSelection,
1533-
) -> BuildStamp {
1534-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target)).with_prefix("libstd")
1535-
}
1536-
1537-
/// Cargo's output path for librustc in a given stage, compiled by a particular
1538-
/// compiler for the specified target.
1539-
pub fn librustc_stamp(
1540-
builder: &Builder<'_>,
1541-
compiler: Compiler,
1542-
target: TargetSelection,
1543-
) -> BuildStamp {
1544-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Rustc, target)).with_prefix("librustc")
1545-
}
1546-
1547-
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
1548-
/// compiler for the specified target and backend.
1549-
fn codegen_backend_stamp(
1550-
builder: &Builder<'_>,
1551-
compiler: Compiler,
1552-
target: TargetSelection,
1553-
backend: &str,
1554-
) -> BuildStamp {
1555-
BuildStamp::new(&builder.cargo_out(compiler, Mode::Codegen, target))
1556-
.with_prefix(&format!("librustc_codegen_{backend}"))
1557-
}
1558-
15591533
pub fn compiler_file(
15601534
builder: &Builder<'_>,
15611535
compiler: &Path,
@@ -1912,7 +1886,7 @@ impl Step for Assemble {
19121886
builder.info(&msg);
19131887

19141888
// Link in all dylibs to the libdir
1915-
let stamp = librustc_stamp(builder, build_compiler, target_compiler.host);
1889+
let stamp = build_stamp::librustc_stamp(builder, build_compiler, target_compiler.host);
19161890
let proc_macros = builder
19171891
.read_stamp_file(&stamp)
19181892
.into_iter()

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::core::build_steps::vendor::default_paths_to_vendor;
2323
use crate::core::build_steps::{compile, llvm};
2424
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2525
use crate::core::config::TargetSelection;
26-
use crate::utils::build_stamp::BuildStamp;
26+
use crate::utils::build_stamp::{self, BuildStamp};
2727
use crate::utils::channel::{self, Info};
2828
use crate::utils::exec::{BootstrapCommand, command};
2929
use crate::utils::helpers::{
@@ -674,7 +674,7 @@ impl Step for Std {
674674
tarball.include_target_in_component_name(true);
675675

676676
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
677-
let stamp = compile::libstd_stamp(builder, compiler_to_use, target);
677+
let stamp = build_stamp::libstd_stamp(builder, compiler_to_use, target);
678678
verify_uefi_rlib_format(builder, target, &stamp);
679679
copy_target_libs(builder, target, tarball.image_dir(), &stamp);
680680

@@ -724,7 +724,7 @@ impl Step for RustcDev {
724724
let tarball = Tarball::new(builder, "rustc-dev", &target.triple);
725725

726726
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
727-
let stamp = compile::librustc_stamp(builder, compiler_to_use, target);
727+
let stamp = build_stamp::librustc_stamp(builder, compiler_to_use, target);
728728
copy_target_libs(builder, target, tarball.image_dir(), &stamp);
729729

730730
let src_files = &["Cargo.lock"];

src/bootstrap/src/utils/build_stamp.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use std::path::{Path, PathBuf};
22
use std::{fs, io};
33

4+
use crate::core::builder::Builder;
5+
use crate::core::config::TargetSelection;
6+
use crate::{Compiler, Mode};
7+
48
#[derive(Clone)]
59
pub struct BuildStamp {
610
path: PathBuf,
@@ -69,3 +73,35 @@ impl BuildStamp {
6973
}
7074
}
7175
}
76+
77+
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
78+
/// compiler for the specified target and backend.
79+
pub fn codegen_backend_stamp(
80+
builder: &Builder<'_>,
81+
compiler: Compiler,
82+
target: TargetSelection,
83+
backend: &str,
84+
) -> BuildStamp {
85+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Codegen, target))
86+
.with_prefix(&format!("librustc_codegen_{backend}"))
87+
}
88+
89+
/// Cargo's output path for the standard library in a given stage, compiled
90+
/// by a particular compiler for the specified target.
91+
pub fn libstd_stamp(
92+
builder: &Builder<'_>,
93+
compiler: Compiler,
94+
target: TargetSelection,
95+
) -> BuildStamp {
96+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Std, target)).with_prefix("libstd")
97+
}
98+
99+
/// Cargo's output path for librustc in a given stage, compiled by a particular
100+
/// compiler for the specified target.
101+
pub fn librustc_stamp(
102+
builder: &Builder<'_>,
103+
compiler: Compiler,
104+
target: TargetSelection,
105+
) -> BuildStamp {
106+
BuildStamp::new(&builder.cargo_out(compiler, Mode::Rustc, target)).with_prefix("librustc")
107+
}

0 commit comments

Comments
 (0)