Skip to content

Commit

Permalink
bootstrap: Merge the libtest build step with libstd
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Aug 19, 2019
1 parent 29a5403 commit 72470e3
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 496 deletions.
33 changes: 29 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1138,10 +1138,12 @@ dependencies = [

[[package]]
name = "getopts"
version = "0.2.19"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450"
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
dependencies = [
"rustc-std-workspace-core",
"rustc-std-workspace-std",
"unicode-width",
]

Expand Down Expand Up @@ -2364,6 +2366,9 @@ dependencies = [
[[package]]
name = "proc_macro"
version = "0.0.0"
dependencies = [
"std",
]

[[package]]
name = "profiler_builtins"
Expand Down Expand Up @@ -3052,6 +3057,13 @@ dependencies = [
"core",
]

[[package]]
name = "rustc-std-workspace-std"
version = "1.0.0"
dependencies = [
"std",
]

[[package]]
name = "rustc-workspace-hack"
version = "1.0.0"
Expand Down Expand Up @@ -4039,6 +4051,10 @@ dependencies = [
[[package]]
name = "term"
version = "0.0.0"
dependencies = [
"core",
"std",
]

[[package]]
name = "term"
Expand Down Expand Up @@ -4085,8 +4101,12 @@ dependencies = [
name = "test"
version = "0.0.0"
dependencies = [
"core",
"getopts",
"libc",
"panic_unwind",
"proc_macro",
"std",
"term 0.0.0",
]

Expand Down Expand Up @@ -4463,9 +4483,14 @@ checksum = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"

[[package]]
name = "unicode-width"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
checksum = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
dependencies = [
"compiler_builtins",
"rustc-std-workspace-core",
"rustc-std-workspace-std",
]

[[package]]
name = "unicode-xid"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
# here
rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
rustc-std-workspace-alloc = { path = 'src/tools/rustc-std-workspace-alloc' }
rustc-std-workspace-std = { path = 'src/tools/rustc-std-workspace-std' }

[patch."https://github.com/rust-lang/rust-clippy"]
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
12 changes: 3 additions & 9 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ impl<'a> Builder<'a> {
match kind {
Kind::Build => describe!(
compile::Std,
compile::Test,
compile::Rustc,
compile::CodegenBackend,
compile::StartupObjects,
Expand All @@ -363,7 +362,6 @@ impl<'a> Builder<'a> {
),
Kind::Check | Kind::Clippy | Kind::Fix => describe!(
check::Std,
check::Test,
check::Rustc,
check::CodegenBackend,
check::Rustdoc
Expand Down Expand Up @@ -425,8 +423,6 @@ impl<'a> Builder<'a> {
doc::TheBook,
doc::Standalone,
doc::Std,
doc::Test,
doc::WhitelistedRustc,
doc::Rustc,
doc::Rustdoc,
doc::ErrorIndex,
Expand Down Expand Up @@ -795,7 +791,7 @@ impl<'a> Builder<'a> {
}

match mode {
Mode::Std | Mode::Test | Mode::ToolBootstrap | Mode::ToolStd | Mode::ToolTest=> {},
Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {},
Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {
// Build proc macros both for the host and the target
if target != compiler.host && cmd != "check" {
Expand Down Expand Up @@ -846,7 +842,6 @@ impl<'a> Builder<'a> {
// things still build right, please do!
match mode {
Mode::Std => metadata.push_str("std"),
Mode::Test => metadata.push_str("test"),
_ => {},
}
cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata);
Expand Down Expand Up @@ -943,9 +938,9 @@ impl<'a> Builder<'a> {

let debuginfo_level = match mode {
Mode::Rustc | Mode::Codegen => self.config.rust_debuginfo_level_rustc,
Mode::Std | Mode::Test => self.config.rust_debuginfo_level_std,
Mode::Std => self.config.rust_debuginfo_level_std,
Mode::ToolBootstrap | Mode::ToolStd |
Mode::ToolTest | Mode::ToolRustc => self.config.rust_debuginfo_level_tools,
Mode::ToolRustc => self.config.rust_debuginfo_level_tools,
};
cargo.env("RUSTC_DEBUGINFO_LEVEL", debuginfo_level.to_string());

Expand Down Expand Up @@ -1145,7 +1140,6 @@ impl<'a> Builder<'a> {

match (mode, self.config.rust_codegen_units_std, self.config.rust_codegen_units) {
(Mode::Std, Some(n), _) |
(Mode::Test, Some(n), _) |
(_, _, Some(n)) => {
cargo.env("RUSTC_CODEGEN_UNITS", n.to_string());
}
Expand Down
153 changes: 64 additions & 89 deletions src/bootstrap/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,27 +365,6 @@ fn dist_with_same_targets_and_hosts() {
},
]
);
assert_eq!(
first(builder.cache.all::<compile::Test>()),
&[
compile::Test {
compiler: Compiler { host: a, stage: 0 },
target: a,
},
compile::Test {
compiler: Compiler { host: a, stage: 1 },
target: a,
},
compile::Test {
compiler: Compiler { host: a, stage: 2 },
target: a,
},
compile::Test {
compiler: Compiler { host: a, stage: 1 },
target: b,
},
]
);
assert_eq!(
first(builder.cache.all::<compile::Assemble>()),
&[
Expand Down Expand Up @@ -415,7 +394,47 @@ fn build_default() {
let b = INTERNER.intern_str("B");
let c = INTERNER.intern_str("C");

assert!(!builder.cache.all::<compile::Std>().is_empty());
assert_eq!(
first(builder.cache.all::<compile::Std>()),
&[
compile::Std {
compiler: Compiler { host: a, stage: 0 },
target: a,
},
compile::Std {
compiler: Compiler { host: a, stage: 1 },
target: a,
},
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: a,
},
compile::Std {
compiler: Compiler { host: b, stage: 2 },
target: a,
},
compile::Std {
compiler: Compiler { host: a, stage: 1 },
target: b,
},
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: b,
},
compile::Std {
compiler: Compiler { host: b, stage: 2 },
target: b,
},
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: c,
},
compile::Std {
compiler: Compiler { host: b, stage: 2 },
target: c,
},
]
);
assert!(!builder.cache.all::<compile::Assemble>().is_empty());
assert_eq!(
first(builder.cache.all::<compile::Rustc>()),
Expand Down Expand Up @@ -450,63 +469,61 @@ fn build_default() {
},
]
);
}

#[test]
fn build_with_target_flag() {
let mut config = configure(&["B"], &["C"]);
config.skip_only_host_steps = true;
let build = Build::new(config);
let mut builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);

let a = INTERNER.intern_str("A");
let b = INTERNER.intern_str("B");
let c = INTERNER.intern_str("C");

assert_eq!(
first(builder.cache.all::<compile::Test>()),
first(builder.cache.all::<compile::Std>()),
&[
compile::Test {
compile::Std {
compiler: Compiler { host: a, stage: 0 },
target: a,
},
compile::Test {
compile::Std {
compiler: Compiler { host: a, stage: 1 },
target: a,
},
compile::Test {
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: a,
},
compile::Test {
compile::Std {
compiler: Compiler { host: b, stage: 2 },
target: a,
},
compile::Test {
compile::Std {
compiler: Compiler { host: a, stage: 1 },
target: b,
},
compile::Test {
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: b,
},
compile::Test {
compile::Std {
compiler: Compiler { host: b, stage: 2 },
target: b,
},
compile::Test {
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: c,
},
compile::Test {
compile::Std {
compiler: Compiler { host: b, stage: 2 },
target: c,
},
]
);
}

#[test]
fn build_with_target_flag() {
let mut config = configure(&["B"], &["C"]);
config.skip_only_host_steps = true;
let build = Build::new(config);
let mut builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);

let a = INTERNER.intern_str("A");
let b = INTERNER.intern_str("B");
let c = INTERNER.intern_str("C");

assert!(!builder.cache.all::<compile::Std>().is_empty());
assert_eq!(
first(builder.cache.all::<compile::Assemble>()),
&[
Expand Down Expand Up @@ -541,48 +558,6 @@ fn build_with_target_flag() {
},
]
);

assert_eq!(
first(builder.cache.all::<compile::Test>()),
&[
compile::Test {
compiler: Compiler { host: a, stage: 0 },
target: a,
},
compile::Test {
compiler: Compiler { host: a, stage: 1 },
target: a,
},
compile::Test {
compiler: Compiler { host: a, stage: 2 },
target: a,
},
compile::Test {
compiler: Compiler { host: b, stage: 2 },
target: a,
},
compile::Test {
compiler: Compiler { host: a, stage: 1 },
target: b,
},
compile::Test {
compiler: Compiler { host: a, stage: 2 },
target: b,
},
compile::Test {
compiler: Compiler { host: b, stage: 2 },
target: b,
},
compile::Test {
compiler: Compiler { host: a, stage: 2 },
target: c,
},
compile::Test {
compiler: Compiler { host: b, stage: 2 },
target: c,
},
]
);
}

#[test]
Expand Down
Loading

0 comments on commit 72470e3

Please sign in to comment.