Skip to content

Commit b47c969

Browse files
committed
bootstrap: Merge the libtest build step with libstd
Since its inception rustbuild has always worked in three stages: one for libstd, one for libtest, and one for rustc. These three stages were architected around crates.io dependencies, where rustc wants to depend on crates.io crates but said crates don't explicitly depend on libstd, requiring a sysroot assembly step in the middle. This same logic was applied for libtest where libtest wants to depend on crates.io crates (`getopts`) but `getopts` didn't say that it depended on std, so it needed `std` built ahead of time. Lots of time has passed since the inception of rustbuild, however, and we've since gotten to the point where even `std` itself is depending on crates.io crates (albeit with some wonky configuration). This commit applies the same logic to the two dependencies that the `test` crate pulls in from crates.io, `getopts` and `unicode-width`. Over the many years since rustbuild's inception `unicode-width` was the only dependency picked up by the `test` crate, so the extra configuration necessary to get crates building in this crate graph is unlikely to be too much of a burden on developers. After this patch it means that there are now only two build phasese of rustbuild, one for libstd and one for rustc. The libtest/libproc_macro build phase is all lumped into one now with `std`. This was originally motivated by rust-lang/cargo#7216 where Cargo was having to deal with synthesizing dependency edges but this commit makes them explicit in this repository.
1 parent 3def0f3 commit b47c969

File tree

18 files changed

+162
-497
lines changed

18 files changed

+162
-497
lines changed

Cargo.lock

+30-4
Original file line numberDiff line numberDiff line change
@@ -1139,10 +1139,12 @@ dependencies = [
11391139

11401140
[[package]]
11411141
name = "getopts"
1142-
version = "0.2.19"
1142+
version = "0.2.21"
11431143
source = "registry+https://github.com/rust-lang/crates.io-index"
1144-
checksum = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450"
1144+
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
11451145
dependencies = [
1146+
"rustc-std-workspace-core",
1147+
"rustc-std-workspace-std",
11461148
"unicode-width",
11471149
]
11481150

@@ -2375,6 +2377,9 @@ dependencies = [
23752377
[[package]]
23762378
name = "proc_macro"
23772379
version = "0.0.0"
2380+
dependencies = [
2381+
"std",
2382+
]
23782383

23792384
[[package]]
23802385
name = "profiler_builtins"
@@ -3063,6 +3068,13 @@ dependencies = [
30633068
"core",
30643069
]
30653070

3071+
[[package]]
3072+
name = "rustc-std-workspace-std"
3073+
version = "1.0.0"
3074+
dependencies = [
3075+
"std",
3076+
]
3077+
30663078
[[package]]
30673079
name = "rustc-workspace-hack"
30683080
version = "1.0.0"
@@ -4068,6 +4080,10 @@ dependencies = [
40684080
[[package]]
40694081
name = "term"
40704082
version = "0.0.0"
4083+
dependencies = [
4084+
"core",
4085+
"std",
4086+
]
40714087

40724088
[[package]]
40734089
name = "term"
@@ -4114,8 +4130,13 @@ dependencies = [
41144130
name = "test"
41154131
version = "0.0.0"
41164132
dependencies = [
4133+
"core",
41174134
"getopts",
4135+
"libc",
4136+
"panic_abort",
4137+
"panic_unwind",
41184138
"proc_macro",
4139+
"std",
41194140
"term 0.0.0",
41204141
]
41214142

@@ -4483,9 +4504,14 @@ checksum = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
44834504

44844505
[[package]]
44854506
name = "unicode-width"
4486-
version = "0.1.5"
4507+
version = "0.1.6"
44874508
source = "registry+https://github.com/rust-lang/crates.io-index"
4488-
checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
4509+
checksum = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
4510+
dependencies = [
4511+
"compiler_builtins",
4512+
"rustc-std-workspace-core",
4513+
"rustc-std-workspace-std",
4514+
]
44894515

44904516
[[package]]
44914517
name = "unicode-xid"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
6868
# here
6969
rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
7070
rustc-std-workspace-alloc = { path = 'src/tools/rustc-std-workspace-alloc' }
71+
rustc-std-workspace-std = { path = 'src/tools/rustc-std-workspace-std' }
7172

7273
[patch."https://github.com/rust-lang/rust-clippy"]
7374
clippy_lints = { path = "src/tools/clippy/clippy_lints" }

src/bootstrap/builder.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ impl<'a> Builder<'a> {
337337
match kind {
338338
Kind::Build => describe!(
339339
compile::Std,
340-
compile::Test,
341340
compile::Rustc,
342341
compile::CodegenBackend,
343342
compile::StartupObjects,
@@ -363,7 +362,6 @@ impl<'a> Builder<'a> {
363362
),
364363
Kind::Check | Kind::Clippy | Kind::Fix => describe!(
365364
check::Std,
366-
check::Test,
367365
check::Rustc,
368366
check::CodegenBackend,
369367
check::Rustdoc
@@ -425,8 +423,6 @@ impl<'a> Builder<'a> {
425423
doc::TheBook,
426424
doc::Standalone,
427425
doc::Std,
428-
doc::Test,
429-
doc::WhitelistedRustc,
430426
doc::Rustc,
431427
doc::Rustdoc,
432428
doc::ErrorIndex,
@@ -801,7 +797,7 @@ impl<'a> Builder<'a> {
801797
}
802798

803799
match mode {
804-
Mode::Std | Mode::Test | Mode::ToolBootstrap | Mode::ToolStd | Mode::ToolTest=> {},
800+
Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {},
805801
Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {
806802
// Build proc macros both for the host and the target
807803
if target != compiler.host && cmd != "check" {
@@ -852,7 +848,6 @@ impl<'a> Builder<'a> {
852848
// things still build right, please do!
853849
match mode {
854850
Mode::Std => metadata.push_str("std"),
855-
Mode::Test => metadata.push_str("test"),
856851
_ => {},
857852
}
858853
cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata);
@@ -948,9 +943,9 @@ impl<'a> Builder<'a> {
948943

949944
let debuginfo_level = match mode {
950945
Mode::Rustc | Mode::Codegen => self.config.rust_debuginfo_level_rustc,
951-
Mode::Std | Mode::Test => self.config.rust_debuginfo_level_std,
946+
Mode::Std => self.config.rust_debuginfo_level_std,
952947
Mode::ToolBootstrap | Mode::ToolStd |
953-
Mode::ToolTest | Mode::ToolRustc => self.config.rust_debuginfo_level_tools,
948+
Mode::ToolRustc => self.config.rust_debuginfo_level_tools,
954949
};
955950
cargo.env("RUSTC_DEBUGINFO_LEVEL", debuginfo_level.to_string());
956951

@@ -1150,7 +1145,6 @@ impl<'a> Builder<'a> {
11501145

11511146
match (mode, self.config.rust_codegen_units_std, self.config.rust_codegen_units) {
11521147
(Mode::Std, Some(n), _) |
1153-
(Mode::Test, Some(n), _) |
11541148
(_, _, Some(n)) => {
11551149
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
11561150
}

src/bootstrap/builder/tests.rs

+64-89
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,6 @@ fn dist_with_same_targets_and_hosts() {
365365
},
366366
]
367367
);
368-
assert_eq!(
369-
first(builder.cache.all::<compile::Test>()),
370-
&[
371-
compile::Test {
372-
compiler: Compiler { host: a, stage: 0 },
373-
target: a,
374-
},
375-
compile::Test {
376-
compiler: Compiler { host: a, stage: 1 },
377-
target: a,
378-
},
379-
compile::Test {
380-
compiler: Compiler { host: a, stage: 2 },
381-
target: a,
382-
},
383-
compile::Test {
384-
compiler: Compiler { host: a, stage: 1 },
385-
target: b,
386-
},
387-
]
388-
);
389368
assert_eq!(
390369
first(builder.cache.all::<compile::Assemble>()),
391370
&[
@@ -415,7 +394,47 @@ fn build_default() {
415394
let b = INTERNER.intern_str("B");
416395
let c = INTERNER.intern_str("C");
417396

418-
assert!(!builder.cache.all::<compile::Std>().is_empty());
397+
assert_eq!(
398+
first(builder.cache.all::<compile::Std>()),
399+
&[
400+
compile::Std {
401+
compiler: Compiler { host: a, stage: 0 },
402+
target: a,
403+
},
404+
compile::Std {
405+
compiler: Compiler { host: a, stage: 1 },
406+
target: a,
407+
},
408+
compile::Std {
409+
compiler: Compiler { host: a, stage: 2 },
410+
target: a,
411+
},
412+
compile::Std {
413+
compiler: Compiler { host: b, stage: 2 },
414+
target: a,
415+
},
416+
compile::Std {
417+
compiler: Compiler { host: a, stage: 1 },
418+
target: b,
419+
},
420+
compile::Std {
421+
compiler: Compiler { host: a, stage: 2 },
422+
target: b,
423+
},
424+
compile::Std {
425+
compiler: Compiler { host: b, stage: 2 },
426+
target: b,
427+
},
428+
compile::Std {
429+
compiler: Compiler { host: a, stage: 2 },
430+
target: c,
431+
},
432+
compile::Std {
433+
compiler: Compiler { host: b, stage: 2 },
434+
target: c,
435+
},
436+
]
437+
);
419438
assert!(!builder.cache.all::<compile::Assemble>().is_empty());
420439
assert_eq!(
421440
first(builder.cache.all::<compile::Rustc>()),
@@ -450,63 +469,61 @@ fn build_default() {
450469
},
451470
]
452471
);
472+
}
473+
474+
#[test]
475+
fn build_with_target_flag() {
476+
let mut config = configure(&["B"], &["C"]);
477+
config.skip_only_host_steps = true;
478+
let build = Build::new(config);
479+
let mut builder = Builder::new(&build);
480+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
481+
482+
let a = INTERNER.intern_str("A");
483+
let b = INTERNER.intern_str("B");
484+
let c = INTERNER.intern_str("C");
453485

454486
assert_eq!(
455-
first(builder.cache.all::<compile::Test>()),
487+
first(builder.cache.all::<compile::Std>()),
456488
&[
457-
compile::Test {
489+
compile::Std {
458490
compiler: Compiler { host: a, stage: 0 },
459491
target: a,
460492
},
461-
compile::Test {
493+
compile::Std {
462494
compiler: Compiler { host: a, stage: 1 },
463495
target: a,
464496
},
465-
compile::Test {
497+
compile::Std {
466498
compiler: Compiler { host: a, stage: 2 },
467499
target: a,
468500
},
469-
compile::Test {
501+
compile::Std {
470502
compiler: Compiler { host: b, stage: 2 },
471503
target: a,
472504
},
473-
compile::Test {
505+
compile::Std {
474506
compiler: Compiler { host: a, stage: 1 },
475507
target: b,
476508
},
477-
compile::Test {
509+
compile::Std {
478510
compiler: Compiler { host: a, stage: 2 },
479511
target: b,
480512
},
481-
compile::Test {
513+
compile::Std {
482514
compiler: Compiler { host: b, stage: 2 },
483515
target: b,
484516
},
485-
compile::Test {
517+
compile::Std {
486518
compiler: Compiler { host: a, stage: 2 },
487519
target: c,
488520
},
489-
compile::Test {
521+
compile::Std {
490522
compiler: Compiler { host: b, stage: 2 },
491523
target: c,
492524
},
493525
]
494526
);
495-
}
496-
497-
#[test]
498-
fn build_with_target_flag() {
499-
let mut config = configure(&["B"], &["C"]);
500-
config.skip_only_host_steps = true;
501-
let build = Build::new(config);
502-
let mut builder = Builder::new(&build);
503-
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
504-
505-
let a = INTERNER.intern_str("A");
506-
let b = INTERNER.intern_str("B");
507-
let c = INTERNER.intern_str("C");
508-
509-
assert!(!builder.cache.all::<compile::Std>().is_empty());
510527
assert_eq!(
511528
first(builder.cache.all::<compile::Assemble>()),
512529
&[
@@ -541,48 +558,6 @@ fn build_with_target_flag() {
541558
},
542559
]
543560
);
544-
545-
assert_eq!(
546-
first(builder.cache.all::<compile::Test>()),
547-
&[
548-
compile::Test {
549-
compiler: Compiler { host: a, stage: 0 },
550-
target: a,
551-
},
552-
compile::Test {
553-
compiler: Compiler { host: a, stage: 1 },
554-
target: a,
555-
},
556-
compile::Test {
557-
compiler: Compiler { host: a, stage: 2 },
558-
target: a,
559-
},
560-
compile::Test {
561-
compiler: Compiler { host: b, stage: 2 },
562-
target: a,
563-
},
564-
compile::Test {
565-
compiler: Compiler { host: a, stage: 1 },
566-
target: b,
567-
},
568-
compile::Test {
569-
compiler: Compiler { host: a, stage: 2 },
570-
target: b,
571-
},
572-
compile::Test {
573-
compiler: Compiler { host: b, stage: 2 },
574-
target: b,
575-
},
576-
compile::Test {
577-
compiler: Compiler { host: a, stage: 2 },
578-
target: c,
579-
},
580-
compile::Test {
581-
compiler: Compiler { host: b, stage: 2 },
582-
target: c,
583-
},
584-
]
585-
);
586561
}
587562

588563
#[test]

0 commit comments

Comments
 (0)