Skip to content

Commit 0a7f2c3

Browse files
Rollup merge of #95503 - jyn514:build-single-crate, r=Mark-Simulacrum
bootstrap: Allow building individual crates This aims to be as unintrusive as possible, but did still require adding a new `tail_args` field to all `Rustc` and `Std` steps. New library and compiler crates are added to the sysroot as they are built, since it's useful to have e.g. just alloc and not std. Fixes #44293.
2 parents 41ad4d9 + d0011b0 commit 0a7f2c3

File tree

9 files changed

+226
-182
lines changed

9 files changed

+226
-182
lines changed

src/bootstrap/builder.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::process::{Command, Stdio};
1313
use std::time::{Duration, Instant};
1414

1515
use crate::cache::{Cache, Interned, INTERNER};
16-
use crate::compile;
1716
use crate::config::{SplitDebuginfo, TargetSelection};
1817
use crate::dist;
1918
use crate::doc;
@@ -26,6 +25,7 @@ use crate::tool::{self, SourceType};
2625
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir, output, t};
2726
use crate::EXTRA_CHECK_CFGS;
2827
use crate::{check, Config};
28+
use crate::{compile, Crate};
2929
use crate::{Build, CLang, DocTests, GitRepo, Mode};
3030

3131
pub use crate::Compiler;
@@ -304,9 +304,7 @@ impl StepDescription {
304304
if paths.is_empty() || builder.config.include_default_paths {
305305
for (desc, should_run) in v.iter().zip(&should_runs) {
306306
if desc.default && should_run.is_really_default() {
307-
for pathset in &should_run.paths {
308-
desc.maybe_run(builder, vec![pathset.clone()]);
309-
}
307+
desc.maybe_run(builder, should_run.paths.iter().cloned().collect());
310308
}
311309
}
312310
}
@@ -424,8 +422,16 @@ impl<'a> ShouldRun<'a> {
424422
/// any of its (local) dependencies.
425423
///
426424
/// `make_run` will be called a single time with all matching command-line paths.
427-
pub fn krate(mut self, name: &str) -> Self {
428-
for krate in self.builder.in_tree_crates(name, None) {
425+
pub fn crate_or_deps(self, name: &str) -> Self {
426+
let crates = self.builder.in_tree_crates(name, None);
427+
self.crates(crates)
428+
}
429+
430+
/// Indicates it should run if the command-line selects any of the given crates.
431+
///
432+
/// `make_run` will be called a single time with all matching command-line paths.
433+
pub(crate) fn crates(mut self, crates: Vec<&Crate>) -> Self {
434+
for krate in crates {
429435
let path = krate.local_path(self.builder);
430436
self.paths.insert(PathSet::one(path, self.kind));
431437
}
@@ -581,6 +587,7 @@ impl<'a> Builder<'a> {
581587
match kind {
582588
Kind::Build => describe!(
583589
compile::Std,
590+
compile::Rustc,
584591
compile::Assemble,
585592
compile::CodegenBackend,
586593
compile::StartupObjects,

src/bootstrap/builder/tests.rs

+63-62
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ fn check_cli<const N: usize>(paths: [&str; N]) {
5757
);
5858
}
5959

60+
macro_rules! std {
61+
($host:ident => $target:ident, stage = $stage:literal) => {
62+
compile::Std::new(
63+
Compiler { host: TargetSelection::from_user(stringify!($host)), stage: $stage },
64+
TargetSelection::from_user(stringify!($target)),
65+
)
66+
};
67+
}
68+
69+
macro_rules! rustc {
70+
($host:ident => $target:ident, stage = $stage:literal) => {
71+
compile::Rustc::new(
72+
Compiler { host: TargetSelection::from_user(stringify!($host)), stage: $stage },
73+
TargetSelection::from_user(stringify!($target)),
74+
)
75+
};
76+
}
77+
6078
#[test]
6179
fn test_valid() {
6280
// make sure multi suite paths are accepted
@@ -117,6 +135,17 @@ fn test_exclude_kind() {
117135
assert!(run_build(&[path], config).contains::<tool::CargoTest>());
118136
}
119137

138+
/// Ensure that if someone passes both a single crate and `library`, all library crates get built.
139+
#[test]
140+
fn alias_and_path_for_library() {
141+
let mut cache =
142+
run_build(&["library".into(), "core".into()], configure("build", &["A"], &["A"]));
143+
assert_eq!(
144+
first(cache.all::<compile::Std>()),
145+
&[std!(A => A, stage = 0), std!(A => A, stage = 1)]
146+
);
147+
}
148+
120149
mod defaults {
121150
use super::{configure, first, run_build};
122151
use crate::builder::*;
@@ -130,10 +159,7 @@ mod defaults {
130159
let a = TargetSelection::from_user("A");
131160
assert_eq!(
132161
first(cache.all::<compile::Std>()),
133-
&[
134-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
135-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
136-
]
162+
&[std!(A => A, stage = 0), std!(A => A, stage = 1),]
137163
);
138164
assert!(!cache.all::<compile::Assemble>().is_empty());
139165
// Make sure rustdoc is only built once.
@@ -143,10 +169,7 @@ mod defaults {
143169
// - this is the compiler it's _linked_ to, not built with.
144170
&[tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } }],
145171
);
146-
assert_eq!(
147-
first(cache.all::<compile::Rustc>()),
148-
&[compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },]
149-
);
172+
assert_eq!(first(cache.all::<compile::Rustc>()), &[rustc!(A => A, stage = 0)],);
150173
}
151174

152175
#[test]
@@ -155,10 +178,7 @@ mod defaults {
155178
let mut cache = run_build(&[], config);
156179

157180
let a = TargetSelection::from_user("A");
158-
assert_eq!(
159-
first(cache.all::<compile::Std>()),
160-
&[compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },]
161-
);
181+
assert_eq!(first(cache.all::<compile::Std>()), &[std!(A => A, stage = 0)]);
162182
assert!(!cache.all::<compile::Assemble>().is_empty());
163183
assert_eq!(
164184
first(cache.all::<tool::Rustdoc>()),
@@ -185,10 +205,10 @@ mod defaults {
185205
assert_eq!(
186206
first(cache.all::<compile::Std>()),
187207
&[
188-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
189-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
190-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: b },
191-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
208+
std!(A => A, stage = 0),
209+
std!(A => A, stage = 1),
210+
std!(A => B, stage = 0),
211+
std!(A => B, stage = 1),
192212
]
193213
);
194214
assert_eq!(
@@ -208,10 +228,7 @@ mod defaults {
208228
);
209229
assert_eq!(
210230
first(cache.all::<compile::Rustc>()),
211-
&[
212-
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
213-
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: b },
214-
]
231+
&[rustc!(A => A, stage = 0), rustc!(A => B, stage = 0),]
215232
);
216233
}
217234

@@ -334,19 +351,18 @@ mod dist {
334351
assert_eq!(
335352
first(cache.all::<compile::Std>()),
336353
&[
337-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
338-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
339-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
340-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
341-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
354+
std!(A => A, stage = 0),
355+
std!(A => A, stage = 1),
356+
std!(A => A, stage = 2),
357+
std!(A => B, stage = 1),
358+
std!(A => B, stage = 2),
342359
],
343360
);
344361
assert_eq!(first(cache.all::<dist::Src>()), &[dist::Src]);
345362
}
346363

347364
#[test]
348365
fn dist_only_cross_host() {
349-
let a = TargetSelection::from_user("A");
350366
let b = TargetSelection::from_user("B");
351367
let mut config = configure(&["A", "B"], &["A", "B"]);
352368
config.docs = false;
@@ -360,10 +376,7 @@ mod dist {
360376
);
361377
assert_eq!(
362378
first(cache.all::<compile::Rustc>()),
363-
&[
364-
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
365-
compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
366-
]
379+
&[rustc!(A => A, stage = 0), rustc!(A => B, stage = 1),]
367380
);
368381
}
369382

@@ -450,11 +463,11 @@ mod dist {
450463
assert_eq!(
451464
first(cache.all::<compile::Std>()),
452465
&[
453-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
454-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
455-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
456-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
457-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
466+
std!(A => A, stage = 0),
467+
std!(A => A, stage = 1),
468+
std!(A => A, stage = 2),
469+
std!(A => B, stage = 1),
470+
std!(A => B, stage = 2),
458471
]
459472
);
460473
assert_eq!(
@@ -474,33 +487,29 @@ mod dist {
474487
let mut builder = Builder::new(&build);
475488
builder.run_step_descriptions(
476489
&Builder::get_step_descriptions(Kind::Build),
477-
&["compiler/rustc".into(), "library/std".into()],
490+
&["compiler/rustc".into(), "library".into()],
478491
);
479492

480-
let a = TargetSelection::from_user("A");
481-
let b = TargetSelection::from_user("B");
482-
let c = TargetSelection::from_user("C");
483-
484493
assert_eq!(
485494
first(builder.cache.all::<compile::Std>()),
486495
&[
487-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
488-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
489-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
490-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
491-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
492-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
496+
std!(A => A, stage = 0),
497+
std!(A => A, stage = 1),
498+
std!(A => A, stage = 2),
499+
std!(A => B, stage = 1),
500+
std!(A => B, stage = 2),
501+
std!(A => C, stage = 2),
493502
]
494503
);
495-
assert!(!builder.cache.all::<compile::Assemble>().is_empty());
504+
assert_eq!(builder.cache.all::<compile::Assemble>().len(), 5);
496505
assert_eq!(
497506
first(builder.cache.all::<compile::Rustc>()),
498507
&[
499-
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
500-
compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
501-
compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: a },
502-
compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
503-
compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: b },
508+
rustc!(A => A, stage = 0),
509+
rustc!(A => A, stage = 1),
510+
rustc!(A => A, stage = 2),
511+
rustc!(A => B, stage = 1),
512+
rustc!(A => B, stage = 2),
504513
]
505514
);
506515
}
@@ -513,15 +522,10 @@ mod dist {
513522
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
514523

515524
let a = TargetSelection::from_user("A");
516-
let c = TargetSelection::from_user("C");
517525

518526
assert_eq!(
519527
first(builder.cache.all::<compile::Std>()),
520-
&[
521-
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
522-
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
523-
compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
524-
]
528+
&[std!(A => A, stage = 0), std!(A => A, stage = 1), std!(A => C, stage = 2),]
525529
);
526530
assert_eq!(
527531
first(builder.cache.all::<compile::Assemble>()),
@@ -533,10 +537,7 @@ mod dist {
533537
);
534538
assert_eq!(
535539
first(builder.cache.all::<compile::Rustc>()),
536-
&[
537-
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
538-
compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
539-
]
540+
&[rustc!(A => A, stage = 0), rustc!(A => A, stage = 1),]
540541
);
541542
}
542543

0 commit comments

Comments
 (0)