Skip to content

Commit b7991a2

Browse files
committed
Fix staging in x install
1 parent fd4c735 commit b7991a2

File tree

3 files changed

+77
-81
lines changed

3 files changed

+77
-81
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -762,36 +762,39 @@ pub struct Std {
762762
pub target: TargetSelection,
763763
}
764764

765-
impl Step for Std {
766-
type Output = Option<GeneratedTarball>;
767-
const DEFAULT: bool = true;
768-
769-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
770-
run.alias("rust-std")
771-
}
772-
773-
fn make_run(run: RunConfig<'_>) {
765+
impl Std {
766+
pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
774767
// This is a build time optimization for running just `x dist rust-std` (without
775768
// `x dist rustc`).
776769
// If we know that we will be uplifting a stage2+ library from stage 1 anyway,
777770
// there is no point in building a stage2 rustc, which will then not do anything (because
778771
// the stdlib will be uplifted).
779-
let top_stage = run.builder.top_stage;
772+
let top_stage = builder.top_stage;
780773
let stage = if top_stage > 1
781-
&& compile::Std::should_be_uplifted_from_stage_1(run.builder, top_stage, run.target)
774+
&& compile::Std::should_be_uplifted_from_stage_1(builder, top_stage, target)
782775
{
783-
run.builder.info(&format!(
776+
builder.info(&format!(
784777
"Note: stage {top_stage} library for `{}` would be uplifted from stage 1, so stage was downgraded from {top_stage} to 1 to avoid needless compiler build(s)",
785-
run.target
778+
target
786779
));
787780
1
788781
} else {
789782
top_stage
790783
};
791-
run.builder.ensure(Std {
792-
build_compiler: run.builder.compiler(stage, run.builder.config.host_target),
793-
target: run.target,
794-
});
784+
Std { build_compiler: builder.compiler(stage, builder.config.host_target), target }
785+
}
786+
}
787+
788+
impl Step for Std {
789+
type Output = Option<GeneratedTarball>;
790+
const DEFAULT: bool = true;
791+
792+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
793+
run.alias("rust-std")
794+
}
795+
796+
fn make_run(run: RunConfig<'_>) {
797+
run.builder.ensure(Std::new(run.builder, run.target));
795798
}
796799

797800
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {

src/bootstrap/src/core/build_steps/install.rs

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,14 @@ fn is_dir_writable_for_user(dir: &Path) -> bool {
6565
fn install_sh(
6666
builder: &Builder<'_>,
6767
package: &str,
68-
stage: u32,
69-
host: Option<TargetSelection>,
68+
build_compiler: impl Into<Option<Compiler>>,
69+
target: Option<TargetSelection>,
7070
tarball: &GeneratedTarball,
7171
) {
72-
let _guard = builder.msg(
73-
Kind::Install,
74-
package,
75-
None,
76-
(host.unwrap_or(builder.host_target), stage),
77-
host,
78-
);
72+
let _guard = match build_compiler.into() {
73+
Some(build_compiler) => builder.msg(Kind::Install, package, None, build_compiler, target),
74+
None => builder.msg_unstaged(Kind::Install, package, target.unwrap_or(builder.host_target)),
75+
};
7976

8077
let prefix = default_path(&builder.config.prefix, "/usr/local");
8178
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));
@@ -167,10 +164,10 @@ macro_rules! install {
167164
IS_HOST: $IS_HOST:expr,
168165
$run_item:block $(, $c:ident)*;)+) => {
169166
$(
170-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
167+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
171168
pub struct $name {
172-
pub compiler: Compiler,
173-
pub target: TargetSelection,
169+
build_compiler: Compiler,
170+
target: TargetSelection,
174171
}
175172

176173
impl $name {
@@ -194,7 +191,7 @@ macro_rules! install {
194191

195192
fn make_run(run: RunConfig<'_>) {
196193
run.builder.ensure($name {
197-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
194+
build_compiler: run.builder.compiler(run.builder.top_stage - 1, run.builder.config.host_target),
198195
target: run.target,
199196
});
200197
}
@@ -209,104 +206,103 @@ macro_rules! install {
209206
install!((self, builder, _config),
210207
Docs, path = "src/doc", _config.docs, IS_HOST: false, {
211208
let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs");
212-
install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball);
209+
install_sh(builder, "docs", self.build_compiler, Some(self.target), &tarball);
213210
};
214211
Std, path = "library/std", true, IS_HOST: false, {
215212
// `expect` should be safe, only None when host != build, but this
216213
// only runs when host == build
217-
let tarball = builder.ensure(dist::Std {
218-
build_compiler: self.compiler,
219-
target: self.target
220-
}).expect("missing std");
221-
install_sh(builder, "std", self.compiler.stage, Some(self.target), &tarball);
214+
let std = dist::Std::new(builder, self.target);
215+
let build_compiler = std.build_compiler;
216+
let tarball = builder.ensure(std).expect("missing std");
217+
install_sh(builder, "std", build_compiler, Some(self.target), &tarball);
222218
};
223219
Cargo, alias = "cargo", Self::should_build(_config), IS_HOST: true, {
224220
let tarball = builder
225-
.ensure(dist::Cargo { build_compiler: self.compiler, target: self.target })
221+
.ensure(dist::Cargo { build_compiler: self.build_compiler, target: self.target })
226222
.expect("missing cargo");
227-
install_sh(builder, "cargo", self.compiler.stage, Some(self.target), &tarball);
223+
install_sh(builder, "cargo", self.build_compiler, Some(self.target), &tarball);
228224
};
229225
RustAnalyzer, alias = "rust-analyzer", Self::should_build(_config), IS_HOST: true, {
230226
if let Some(tarball) =
231-
builder.ensure(dist::RustAnalyzer { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target), target: self.target })
227+
builder.ensure(dist::RustAnalyzer { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target), target: self.target })
232228
{
233-
install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball);
229+
install_sh(builder, "rust-analyzer", self.build_compiler, Some(self.target), &tarball);
234230
} else {
235231
builder.info(
236-
&format!("skipping Install rust-analyzer stage{} ({})", self.compiler.stage, self.target),
232+
&format!("skipping Install rust-analyzer stage{} ({})", self.build_compiler.stage + 1, self.target),
237233
);
238234
}
239235
};
240236
Clippy, alias = "clippy", Self::should_build(_config), IS_HOST: true, {
241237
let tarball = builder
242-
.ensure(dist::Clippy { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target), target: self.target })
238+
.ensure(dist::Clippy { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target), target: self.target })
243239
.expect("missing clippy");
244-
install_sh(builder, "clippy", self.compiler.stage, Some(self.target), &tarball);
240+
install_sh(builder, "clippy", self.build_compiler, Some(self.target), &tarball);
245241
};
246242
Miri, alias = "miri", Self::should_build(_config), IS_HOST: true, {
247-
if let Some(tarball) = builder.ensure(dist::Miri { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target) , target: self.target }) {
248-
install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball);
243+
if let Some(tarball) = builder.ensure(dist::Miri { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target) , target: self.target }) {
244+
install_sh(builder, "miri", self.build_compiler, Some(self.target), &tarball);
249245
} else {
250246
// Miri is only available on nightly
251247
builder.info(
252-
&format!("skipping Install miri stage{} ({})", self.compiler.stage, self.target),
248+
&format!("skipping Install miri stage{} ({})", self.build_compiler.stage + 1, self.target),
253249
);
254250
}
255251
};
256252
LlvmTools, alias = "llvm-tools", _config.llvm_tools_enabled && _config.llvm_enabled(_config.host_target), IS_HOST: true, {
257253
if let Some(tarball) = builder.ensure(dist::LlvmTools { target: self.target }) {
258-
install_sh(builder, "llvm-tools", self.compiler.stage, Some(self.target), &tarball);
254+
install_sh(builder, "llvm-tools", None, Some(self.target), &tarball);
259255
} else {
260256
builder.info(
261-
&format!("skipping llvm-tools stage{} ({}): external LLVM", self.compiler.stage, self.target),
257+
&format!("skipping llvm-tools ({}): external LLVM", self.target),
262258
);
263259
}
264260
};
265261
Rustfmt, alias = "rustfmt", Self::should_build(_config), IS_HOST: true, {
266262
if let Some(tarball) = builder.ensure(dist::Rustfmt {
267-
compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target),
263+
compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target),
268264
target: self.target
269265
}) {
270-
install_sh(builder, "rustfmt", self.compiler.stage, Some(self.target), &tarball);
266+
install_sh(builder, "rustfmt", self.build_compiler, Some(self.target), &tarball);
271267
} else {
272268
builder.info(
273-
&format!("skipping Install Rustfmt stage{} ({})", self.compiler.stage, self.target),
269+
&format!("skipping Install Rustfmt stage{} ({})", self.build_compiler.stage + 1, self.target),
274270
);
275271
}
276272
};
277273
Rustc, path = "compiler/rustc", true, IS_HOST: true, {
278274
let tarball = builder.ensure(dist::Rustc {
279-
target_compiler: builder.compiler(builder.top_stage, self.target),
275+
target_compiler: builder.compiler(self.build_compiler.stage + 1, self.target),
280276
});
281-
install_sh(builder, "rustc", self.compiler.stage, Some(self.target), &tarball);
277+
install_sh(builder, "rustc", self.build_compiler, Some(self.target), &tarball);
282278
};
283279
RustcCodegenCranelift, alias = "rustc-codegen-cranelift", Self::should_build(_config), IS_HOST: true, {
284280
if let Some(tarball) = builder.ensure(dist::CraneliftCodegenBackend {
285-
compilers: RustcPrivateCompilers::new(builder, builder.top_stage, self.target),
281+
compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target),
286282
target: self.target
287283
}) {
288-
install_sh(builder, "rustc-codegen-cranelift", self.compiler.stage, Some(self.target), &tarball);
284+
install_sh(builder, "rustc-codegen-cranelift", self.build_compiler, Some(self.target), &tarball);
289285
} else {
290286
builder.info(
291287
&format!("skipping Install CodegenBackend(\"cranelift\") stage{} ({})",
292-
self.compiler.stage, self.target),
288+
self.build_compiler.stage + 1, self.target),
293289
);
294290
}
295291
};
296292
LlvmBitcodeLinker, alias = "llvm-bitcode-linker", Self::should_build(_config), IS_HOST: true, {
297-
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { build_compiler: self.compiler, target: self.target }) {
298-
install_sh(builder, "llvm-bitcode-linker", self.compiler.stage, Some(self.target), &tarball);
293+
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { build_compiler: self.build_compiler, target: self.target }) {
294+
install_sh(builder, "llvm-bitcode-linker", self.build_compiler, Some(self.target), &tarball);
299295
} else {
300296
builder.info(
301-
&format!("skipping llvm-bitcode-linker stage{} ({})", self.compiler.stage, self.target),
297+
&format!("skipping llvm-bitcode-linker stage{} ({})", self.build_compiler.stage + 1, self.target),
302298
);
303299
}
304300
};
305301
);
306302

307303
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
308304
pub struct Src {
309-
pub stage: u32,
305+
stage: u32,
310306
}
311307

312308
impl Step for Src {
@@ -326,6 +322,6 @@ impl Step for Src {
326322

327323
fn run(self, builder: &Builder<'_>) {
328324
let tarball = builder.ensure(dist::Src);
329-
install_sh(builder, "src", self.stage, None, &tarball);
325+
install_sh(builder, "src", None, None, &tarball);
330326
}
331327
}

src/bootstrap/src/core/builder/tests.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,18 +2233,18 @@ mod snapshot {
22332233
[build] llvm <host>
22342234
[build] rustc 0 <host> -> rustc 1 <host>
22352235
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
2236-
[build] rustc 1 <host> -> std 1 <host>
2237-
[build] rustc 1 <host> -> rustc 2 <host>
2238-
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
22392236
[build] rustc 0 <host> -> UnstableBookGen 1 <host>
22402237
[build] rustc 0 <host> -> Rustbook 1 <host>
22412238
[doc] unstable-book (book) <host>
2239+
[build] rustc 1 <host> -> std 1 <host>
22422240
[doc] book (book) <host>
22432241
[doc] book/first-edition (book) <host>
22442242
[doc] book/second-edition (book) <host>
22452243
[doc] book/2018-edition (book) <host>
22462244
[build] rustdoc 1 <host>
22472245
[doc] rustc 1 <host> -> standalone 2 <host>
2246+
[build] rustc 1 <host> -> rustc 2 <host>
2247+
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
22482248
[build] rustdoc 2 <host>
22492249
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
22502250
[build] rustc 1 <host> -> error-index 2 <host>
@@ -2263,26 +2263,23 @@ mod snapshot {
22632263
[doc] rustc 1 <host> -> releases 2 <host>
22642264
[build] rustc 0 <host> -> RustInstaller 1 <host>
22652265
[dist] docs <host>
2266-
[build] rustc 2 <host> -> std 2 <host>
2267-
[dist] rustc 2 <host> -> std 2 <host>
2266+
[dist] rustc 1 <host> -> std 1 <host>
22682267
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
22692268
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
22702269
[dist] rustc <host>
2271-
[build] rustc 2 <host> -> cargo 3 <host>
2272-
[dist] rustc 2 <host> -> cargo 3 <host>
2273-
[build] rustc 2 <host> -> rustc 3 <host>
2274-
[build] rustc 2 <host> -> WasmComponentLd 3 <host>
2275-
[build] rustc 2 <host> -> rust-analyzer 3 <host>
2276-
[dist] rustc 2 <host> -> rust-analyzer 3 <host>
2277-
[build] rustc 2 <host> -> rustfmt 3 <host>
2278-
[build] rustc 2 <host> -> cargo-fmt 3 <host>
2279-
[dist] rustc 2 <host> -> rustfmt 3 <host>
2280-
[build] rustc 2 <host> -> clippy-driver 3 <host>
2281-
[build] rustc 2 <host> -> cargo-clippy 3 <host>
2282-
[dist] rustc 2 <host> -> clippy 3 <host>
2283-
[build] rustc 2 <host> -> miri 3 <host>
2284-
[build] rustc 2 <host> -> cargo-miri 3 <host>
2285-
[dist] rustc 2 <host> -> miri 3 <host>
2270+
[build] rustc 1 <host> -> cargo 2 <host>
2271+
[dist] rustc 1 <host> -> cargo 2 <host>
2272+
[build] rustc 1 <host> -> rust-analyzer 2 <host>
2273+
[dist] rustc 1 <host> -> rust-analyzer 2 <host>
2274+
[build] rustc 1 <host> -> rustfmt 2 <host>
2275+
[build] rustc 1 <host> -> cargo-fmt 2 <host>
2276+
[dist] rustc 1 <host> -> rustfmt 2 <host>
2277+
[build] rustc 1 <host> -> clippy-driver 2 <host>
2278+
[build] rustc 1 <host> -> cargo-clippy 2 <host>
2279+
[dist] rustc 1 <host> -> clippy 2 <host>
2280+
[build] rustc 1 <host> -> miri 2 <host>
2281+
[build] rustc 1 <host> -> cargo-miri 2 <host>
2282+
[dist] rustc 1 <host> -> miri 2 <host>
22862283
[dist] src <>
22872284
");
22882285
}

0 commit comments

Comments
 (0)