Skip to content

Commit ea2db36

Browse files
committed
be able to build stage1 library with CI-rustc
Signed-off-by: onur-ozkan <[email protected]>
1 parent 754327b commit ea2db36

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

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

+14-28
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,23 @@ impl Step for Std {
151151
)]
152152
fn run(self, builder: &Builder<'_>) {
153153
let target = self.target;
154-
let compiler = self.compiler;
155154

156155
// We already have std ready to be used for stage 0.
157-
if compiler.stage == 0 {
156+
if self.compiler.stage == 0 {
157+
let compiler = self.compiler;
158158
builder.ensure(StdLink::from_std(self, compiler));
159159

160160
return;
161161
}
162162

163+
let compiler = if builder.download_rustc() && self.force_recompile {
164+
// When there are changes in the library tree with CI-rustc, we want to build
165+
// the stageN library and that requires using stageN-1 compiler.
166+
builder.compiler(self.compiler.stage.saturating_sub(1), builder.config.build)
167+
} else {
168+
self.compiler
169+
};
170+
163171
// When using `download-rustc`, we already have artifacts for the host available. Don't
164172
// recompile them.
165173
if builder.download_rustc() && builder.is_builder_target(target) && !self.force_recompile {
@@ -192,17 +200,16 @@ impl Step for Std {
192200

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

195-
let mut compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
203+
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
196204
trace!(?compiler_to_use);
197205

198206
if compiler_to_use != compiler
199-
// Never uplift std unless we have compiled stage 2; if stage 2 is compiled,
207+
// Never uplift std unless we have compiled stage 1; if stage 1 is compiled,
200208
// uplift it from there.
201209
//
202210
// FIXME: improve `fn compiler_for` to avoid adding stage condition here.
203-
&& compiler.stage > 2
211+
&& compiler.stage > 1
204212
{
205-
compiler_to_use.stage = 2;
206213
trace!(?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library");
207214

208215
builder.ensure(Std::new(compiler_to_use, target));
@@ -235,27 +242,6 @@ impl Step for Std {
235242

236243
target_deps.extend(self.copy_extra_objects(builder, &compiler, target));
237244

238-
// The LLD wrappers and `rust-lld` are self-contained linking components that can be
239-
// necessary to link the stdlib on some targets. We'll also need to copy these binaries to
240-
// the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
241-
if compiler.stage == 0 && builder.is_builder_target(compiler.host) {
242-
trace!(
243-
"(build == host) copying linking components to `stage0-sysroot` for bootstrapping"
244-
);
245-
// We want to copy the host `bin` folder within the `rustlib` folder in the sysroot.
246-
let src_sysroot_bin = builder
247-
.rustc_snapshot_sysroot()
248-
.join("lib")
249-
.join("rustlib")
250-
.join(compiler.host)
251-
.join("bin");
252-
if src_sysroot_bin.exists() {
253-
let target_sysroot_bin = builder.sysroot_target_bindir(compiler, target);
254-
t!(fs::create_dir_all(&target_sysroot_bin));
255-
builder.cp_link_r(&src_sysroot_bin, &target_sysroot_bin);
256-
}
257-
}
258-
259245
// We build a sysroot for mir-opt tests using the same trick that Miri does: A check build
260246
// with -Zalways-encode-mir. This frees us from the need to have a target linker, and the
261247
// fact that this is a check build integrates nicely with run_cargo.
@@ -750,7 +736,7 @@ impl Step for StdLink {
750736
let target = self.target;
751737

752738
// NOTE: intentionally does *not* check `target == builder.build` to avoid having to add the same check in `test::Crate`.
753-
let (libdir, hostdir) = if self.force_recompile && builder.download_rustc() {
739+
let (libdir, hostdir) = if !self.force_recompile && builder.download_rustc() {
754740
// NOTE: copies part of `sysroot_libdir` to avoid having to add a new `force_recompile` argument there too
755741
let lib = builder.sysroot_libdir_relative(self.compiler);
756742
let sysroot = builder.ensure(crate::core::build_steps::compile::Sysroot {

src/bootstrap/src/core/build_steps/tool.rs

-5
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,6 @@ pub(crate) fn get_tool_rustc_compiler(
330330
return target_compiler;
331331
}
332332

333-
if builder.download_rustc() && target_compiler.stage > 0 {
334-
// We already have the stage N compiler, we don't need to cut the stage.
335-
return builder.compiler(target_compiler.stage, builder.config.build);
336-
}
337-
338333
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
339334
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
340335
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the

0 commit comments

Comments
 (0)