Skip to content

Commit a62488b

Browse files
committed
Handle uplifting in libstd dist step
1 parent 21c30ea commit a62488b

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ impl Std {
123123
}
124124

125125
impl Step for Std {
126-
type Output = ();
126+
/// Build stamp of std, if it was indeed built or uplifted.
127+
type Output = Option<BuildStamp>;
128+
127129
const DEFAULT: bool = true;
128130

129131
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -160,15 +162,15 @@ impl Step for Std {
160162
/// This will build the standard library for a particular stage of the build
161163
/// using the `compiler` targeting the `target` architecture. The artifacts
162164
/// created will also be linked into the sysroot directory.
163-
fn run(self, builder: &Builder<'_>) {
165+
fn run(self, builder: &Builder<'_>) -> Self::Output {
164166
let target = self.target;
165167

166168
// We already have std ready to be used for stage 0.
167169
if self.build_compiler.stage == 0 {
168170
let compiler = self.build_compiler;
169171
builder.ensure(StdLink::from_std(self, compiler));
170172

171-
return;
173+
return None;
172174
}
173175

174176
let build_compiler = if builder.download_rustc() && self.force_recompile {
@@ -193,7 +195,7 @@ impl Step for Std {
193195
&sysroot,
194196
builder.config.ci_rust_std_contents(),
195197
);
196-
return;
198+
return None;
197199
}
198200

199201
if builder.config.keep_stage.contains(&build_compiler.stage)
@@ -209,7 +211,7 @@ impl Step for Std {
209211
self.copy_extra_objects(builder, &build_compiler, target);
210212

211213
builder.ensure(StdLink::from_std(self, build_compiler));
212-
return;
214+
return Some(build_stamp::libstd_stamp(builder, build_compiler, target));
213215
}
214216

215217
let mut target_deps = builder.ensure(StartupObjects { compiler: build_compiler, target });
@@ -219,7 +221,7 @@ impl Step for Std {
219221

220222
if Self::should_be_uplifted_from_stage_1(builder, build_compiler.stage, target) {
221223
let build_compiler_for_std_to_uplift = builder.compiler(1, builder.host_target);
222-
builder.std(build_compiler_for_std_to_uplift, target);
224+
let stage_1_stamp = builder.std(build_compiler_for_std_to_uplift, target);
223225

224226
let msg = if build_compiler_for_std_to_uplift.host == target {
225227
format!(
@@ -240,7 +242,7 @@ impl Step for Std {
240242
self.copy_extra_objects(builder, &build_compiler, target);
241243

242244
builder.ensure(StdLink::from_std(self, build_compiler_for_std_to_uplift));
243-
return;
245+
return stage_1_stamp;
244246
}
245247

246248
target_deps.extend(self.copy_extra_objects(builder, &build_compiler, target));
@@ -293,11 +295,13 @@ impl Step for Std {
293295
build_compiler,
294296
target,
295297
);
298+
299+
let stamp = build_stamp::libstd_stamp(builder, build_compiler, target);
296300
run_cargo(
297301
builder,
298302
cargo,
299303
vec![],
300-
&build_stamp::libstd_stamp(builder, build_compiler, target),
304+
&stamp,
301305
target_deps,
302306
self.is_for_mir_opt_tests, // is_check
303307
false,
@@ -307,6 +311,7 @@ impl Step for Std {
307311
self,
308312
builder.compiler(build_compiler.stage, builder.config.host_target),
309313
));
314+
Some(stamp)
310315
}
311316

312317
fn metadata(&self) -> Option<StepMetadata> {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,14 @@ impl Step for Std {
791791
return None;
792792
}
793793

794-
builder.std(build_compiler, target);
794+
// It's possible that std was uplifted and thus built with a different build compiler
795+
// So we need to read the stamp that was actually generated when std was built
796+
let stamp =
797+
builder.std(build_compiler, target).expect("Standard library has to be built for dist");
795798

796799
let mut tarball = Tarball::new(builder, "rust-std", &target.triple);
797800
tarball.include_target_in_component_name(true);
798801

799-
let stamp = build_stamp::libstd_stamp(builder, build_compiler, target);
800802
verify_uefi_rlib_format(builder, target, &stamp);
801803
copy_target_libs(builder, target, tarball.image_dir(), &stamp);
802804

src/bootstrap/src/core/builder/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::core::build_steps::{
2222
};
2323
use crate::core::config::flags::Subcommand;
2424
use crate::core::config::{DryRun, TargetSelection};
25+
use crate::utils::build_stamp::BuildStamp;
2526
use crate::utils::cache::Cache;
2627
use crate::utils::exec::{BootstrapCommand, ExecutionContext, command};
2728
use crate::utils::helpers::{self, LldThreads, add_dylib_path, exe, libdir, linker_args, t};
@@ -1412,6 +1413,8 @@ impl<'a> Builder<'a> {
14121413
/// The standard library will be linked to the sysroot of the passed compiler.
14131414
///
14141415
/// Prefer using this method rather than manually invoking `Std::new`.
1416+
///
1417+
/// Returns an optional build stamp, if libstd was indeed built.
14151418
#[cfg_attr(
14161419
feature = "tracing",
14171420
instrument(
@@ -1425,7 +1428,7 @@ impl<'a> Builder<'a> {
14251428
),
14261429
),
14271430
)]
1428-
pub fn std(&self, compiler: Compiler, target: TargetSelection) {
1431+
pub fn std(&self, compiler: Compiler, target: TargetSelection) -> Option<BuildStamp> {
14291432
// FIXME: make the `Std` step return some type-level "proof" that std was indeed built,
14301433
// and then require passing that to all Cargo invocations that we do.
14311434

@@ -1444,10 +1447,11 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
14441447

14451448
// We still need to link the prebuilt standard library into the ephemeral stage0 sysroot
14461449
self.ensure(StdLink::from_std(Std::new(compiler, target), compiler));
1450+
None
14471451
} else {
14481452
// This step both compiles the std and links it into the compiler's sysroot.
14491453
// Yes, it's quite magical and side-effecty.. would be nice to refactor later.
1450-
self.ensure(Std::new(compiler, target));
1454+
self.ensure(Std::new(compiler, target))
14511455
}
14521456
}
14531457

0 commit comments

Comments
 (0)