Skip to content

Commit

Permalink
Auto merge of #32544 - alexcrichton:rustbuild-dist-libtest, r=brson
Browse files Browse the repository at this point in the history
rustbuild: Fix dist for non-host targets

The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.

There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.

These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.

The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).

All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.

Closes #32523
  • Loading branch information
bors committed Apr 1, 2016
2 parents b0d3170 + 3d6340f commit c8b8eb1
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 42 deletions.
40 changes: 39 additions & 1 deletion src/bootstrap/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) {
}
}

/// Build libtest.
///
/// This will build libtest and supporting libraries for a particular stage of
/// the build using the `compiler` targeting the `target` architecture. The
/// artifacts created will also be linked into the sysroot directory.
pub fn test<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
println!("Building stage{} test artifacts ({} -> {})", compiler.stage,
compiler.host, target);
let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
build.clear_if_dirty(&out_dir, &libstd_shim(build, compiler, target));
let mut cargo = build.cargo(compiler, Mode::Libtest, target, "build");
cargo.arg("--manifest-path")
.arg(build.src.join("src/rustc/test_shim/Cargo.toml"));
build.run(&mut cargo);
test_link(build, target, compiler, compiler.host);
}

/// Link all libtest rlibs/dylibs into the sysroot location.
///
/// Links those artifacts generated in the given `stage` for `target` produced
/// by `compiler` into `host`'s sysroot.
pub fn test_link(build: &Build,
target: &str,
compiler: &Compiler,
host: &str) {
let target_compiler = Compiler::new(compiler.stage, host);
let libdir = build.sysroot_libdir(&target_compiler, target);
let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
add_to_sysroot(&out_dir, &libdir);
}


/// Build the compiler.
///
/// This will build the compiler for a particular stage of the build using
Expand All @@ -133,7 +165,7 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
compiler.stage, compiler.host, target);

let out_dir = build.cargo_out(compiler, Mode::Librustc, target);
build.clear_if_dirty(&out_dir, &libstd_shim(build, compiler, target));
build.clear_if_dirty(&out_dir, &libtest_shim(build, compiler, target));

let mut cargo = build.cargo(compiler, Mode::Librustc, target, "build");
cargo.arg("--features").arg(build.rustc_features())
Expand Down Expand Up @@ -202,6 +234,12 @@ fn libstd_shim(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
build.cargo_out(compiler, Mode::Libstd, target).join("libstd_shim.rlib")
}

/// Cargo's output path for libtest in a given stage, compiled by a particular
/// compiler for the specified target.
fn libtest_shim(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
build.cargo_out(compiler, Mode::Libtest, target).join("libtest_shim.rlib")
}

fn compiler_file(compiler: &Path, file: &str) -> String {
output(Command::new(compiler)
.arg(format!("-print-file-name={}", file))).trim().to_string()
Expand Down
16 changes: 16 additions & 0 deletions src/bootstrap/build/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ pub fn std(build: &Build, stage: u32, host: &str, out: &Path) {
cp_r(&out_dir, out)
}

pub fn test(build: &Build, stage: u32, host: &str, out: &Path) {
println!("Documenting stage{} test ({})", stage, host);
let compiler = Compiler::new(stage, host);
let out_dir = build.stage_out(&compiler, Mode::Libtest)
.join(host).join("doc");
let rustdoc = build.rustdoc(&compiler);

build.clear_if_dirty(&out_dir, &rustdoc);

let mut cargo = build.cargo(&compiler, Mode::Libtest, host, "doc");
cargo.arg("--manifest-path")
.arg(build.src.join("src/rustc/test_shim/Cargo.toml"));
build.run(&mut cargo);
cp_r(&out_dir, out)
}

pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) {
println!("Documenting stage{} compiler ({})", stage, host);
let compiler = Compiler::new(stage, host);
Expand Down
18 changes: 17 additions & 1 deletion src/bootstrap/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct Build {

pub enum Mode {
Libstd,
Libtest,
Librustc,
Tool,
}
Expand Down Expand Up @@ -141,9 +142,13 @@ impl Build {
return clean::clean(self);
}

self.verbose("finding compilers");
cc::find(self);
self.verbose("running sanity check");
sanity::check(self);
self.verbose("collecting channel variables");
channel::collect(self);
self.verbose("updating submodules");
self.update_submodules();

for target in step::all(self) {
Expand All @@ -158,12 +163,18 @@ impl Build {
Libstd { compiler } => {
compile::std(self, target.target, &compiler);
}
Libtest { compiler } => {
compile::test(self, target.target, &compiler);
}
Librustc { compiler } => {
compile::rustc(self, target.target, &compiler);
}
LibstdLink { compiler, host } => {
compile::std_link(self, target.target, &compiler, host);
}
LibtestLink { compiler, host } => {
compile::test_link(self, target.target, &compiler, host);
}
LibrustcLink { compiler, host } => {
compile::rustc_link(self, target.target, &compiler, host);
}
Expand Down Expand Up @@ -203,6 +214,9 @@ impl Build {
DocStd { stage } => {
doc::std(self, stage, target.target, &doc_out);
}
DocTest { stage } => {
doc::test(self, stage, target.target, &doc_out);
}
DocRustc { stage } => {
doc::rustc(self, stage, target.target, &doc_out);
}
Expand Down Expand Up @@ -360,6 +374,7 @@ impl Build {
let host = compiler.host;
let paths = vec![
self.cargo_out(compiler, Mode::Libstd, host).join("deps"),
self.cargo_out(compiler, Mode::Libtest, host).join("deps"),
self.cargo_out(compiler, Mode::Librustc, host).join("deps"),
];
add_lib_path(paths, &mut cmd);
Expand Down Expand Up @@ -414,7 +429,8 @@ impl Build {
fn stage_out(&self, compiler: &Compiler, mode: Mode) -> PathBuf {
let suffix = match mode {
Mode::Libstd => "-std",
_ => "-rustc",
Mode::Libtest => "-test",
Mode::Tool | Mode::Librustc => "-rustc",
};
self.out.join(compiler.host)
.join(format!("stage{}{}", compiler.stage, suffix))
Expand Down
37 changes: 25 additions & 12 deletions src/bootstrap/build/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ macro_rules! targets {
// compiler executable itself, not any of the support libraries
(rustc, Rustc { stage: u32 }),

// Steps for the two main cargo builds, one for the standard library
// and one for the compiler itself. These are parameterized over the
// stage output they're going to be placed in along with the
// compiler which is producing the copy of libstd or librustc
// Steps for the two main cargo builds. These are parameterized over
// the compiler which is producing the artifact.
(libstd, Libstd { compiler: Compiler<'a> }),
(libtest, Libtest { compiler: Compiler<'a> }),
(librustc, Librustc { compiler: Compiler<'a> }),

// Links the standard library/librustc produced by the compiler
// provided into the host's directory also provided.
// Links the target produced by the compiler provided into the
// host's directory also provided.
(libstd_link, LibstdLink {
compiler: Compiler<'a>,
host: &'a str
}),
(libtest_link, LibtestLink {
compiler: Compiler<'a>,
host: &'a str
}),
(librustc_link, LibrustcLink {
compiler: Compiler<'a>,
host: &'a str
Expand Down Expand Up @@ -67,6 +70,7 @@ macro_rules! targets {
(doc_style, DocStyle { stage: u32 }),
(doc_standalone, DocStandalone { stage: u32 }),
(doc_std, DocStd { stage: u32 }),
(doc_test, DocTest { stage: u32 }),
(doc_rustc, DocRustc { stage: u32 }),
(doc_error_index, DocErrorIndex { stage: u32 }),

Expand Down Expand Up @@ -162,10 +166,10 @@ fn top_level(build: &Build) -> Vec<Step> {

if host.target == build.config.build {
targets.push(host.target(target)
.libstd(host.compiler(stage)));
.libtest(host.compiler(stage)));
} else {
targets.push(host.target(target)
.libstd_link(t.compiler(stage), host.target));
.libtest_link(t.compiler(stage), host.target));
}
}
}
Expand Down Expand Up @@ -246,15 +250,21 @@ impl<'a> Step<'a> {
vec![self.librustc(compiler)]
}
Source::Librustc { compiler } => {
vec![self.libstd(compiler), self.llvm(())]
vec![self.libtest(compiler), self.llvm(())]
}
Source::Libtest { compiler } => {
vec![self.libstd(compiler)]
}
Source::Libstd { compiler } => {
vec![self.compiler_rt(()),
self.rustc(compiler.stage).target(compiler.host)]
}
Source::LibrustcLink { compiler, host } => {
vec![self.librustc(compiler),
self.libstd_link(compiler, host)]
self.libtest_link(compiler, host)]
}
Source::LibtestLink { compiler, host } => {
vec![self.libtest(compiler), self.libstd_link(compiler, host)]
}
Source::LibstdLink { compiler, host } => {
vec![self.libstd(compiler),
Expand All @@ -267,6 +277,9 @@ impl<'a> Step<'a> {
Source::DocStd { stage } => {
vec![self.libstd(self.compiler(stage))]
}
Source::DocTest { stage } => {
vec![self.libtest(self.compiler(stage))]
}
Source::DocBook { stage } |
Source::DocNomicon { stage } |
Source::DocStyle { stage } => {
Expand All @@ -279,7 +292,7 @@ impl<'a> Step<'a> {
vec![self.rustc(stage)]
}
Source::DocRustc { stage } => {
vec![self.doc_std(stage)]
vec![self.doc_test(stage)]
}
Source::Doc { stage } => {
vec![self.doc_book(stage), self.doc_nomicon(stage),
Expand Down Expand Up @@ -315,7 +328,7 @@ impl<'a> Step<'a> {
vec![self.rustc(stage)]
}
Source::DistStd { compiler } => {
vec![self.libstd(compiler)]
vec![self.libtest(compiler)]
}

Source::Dist { stage } => {
Expand Down
1 change: 1 addition & 0 deletions src/etc/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'src/libcore',
'src/libstd',
'src/rustc/std_shim',
'src/rustc/test_shim',
'src/test'
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ crate-type = ["dylib"]
arena = { path = "../libarena" }
flate = { path = "../libflate" }
fmt_macros = { path = "../libfmt_macros" }
getopts = { path = "../libgetopts" }
graphviz = { path = "../libgraphviz" }
log = { path = "../liblog" }
rbml = { path = "../librbml" }
Expand Down
1 change: 0 additions & 1 deletion src/librustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ crate-type = ["dylib"]
[dependencies]
arena = { path = "../libarena" }
flate = { path = "../libflate" }
getopts = { path = "../libgetopts" }
graphviz = { path = "../libgraphviz" }
log = { path = "../liblog" }
rustc = { path = "../librustc" }
Expand Down
1 change: 0 additions & 1 deletion src/librustc_trans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ crate-type = ["dylib"]
[dependencies]
arena = { path = "../libarena" }
flate = { path = "../libflate" }
getopts = { path = "../libgetopts" }
graphviz = { path = "../libgraphviz" }
log = { path = "../liblog" }
rustc = { path = "../librustc" }
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ crate-type = ["dylib"]

[dependencies]
arena = { path = "../libarena" }
getopts = { path = "../libgetopts" }
rustc = { path = "../librustc" }
rustc_back = { path = "../librustc_back" }
rustc_const_eval = { path = "../librustc_const_eval" }
Expand All @@ -23,7 +22,6 @@ rustc_resolve = { path = "../librustc_resolve" }
rustc_trans = { path = "../librustc_trans" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
test = { path = "../libtest" }
log = { path = "../liblog" }

[build-dependencies]
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ crate-type = ["dylib"]

[dependencies]
serialize = { path = "../libserialize" }
term = { path = "../libterm" }
log = { path = "../liblog" }
rustc_bitflags = { path = "../librustc_bitflags" }
Loading

0 comments on commit c8b8eb1

Please sign in to comment.