about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-03-27 22:28:10 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-04-01 10:18:36 -0700
commit3d6340ffe2a57614f88ea04c85dfc60707c95135 (patch)
tree962609b17477b835df9d4988b8d37113298860a9 /src/bootstrap
parentabb3a107e45b93ca5332ab11bfa6cc8d5a882fb4 (diff)
downloadrust-3d6340ffe2a57614f88ea04c85dfc60707c95135.tar.gz
rust-3d6340ffe2a57614f88ea04c85dfc60707c95135.zip
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
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/build/compile.rs40
-rw-r--r--src/bootstrap/build/doc.rs16
-rw-r--r--src/bootstrap/build/mod.rs18
-rw-r--r--src/bootstrap/build/step.rs37
4 files changed, 97 insertions, 14 deletions
diff --git a/src/bootstrap/build/compile.rs b/src/bootstrap/build/compile.rs
index 95555aa3796..dee586c7699 100644
--- a/src/bootstrap/build/compile.rs
+++ b/src/bootstrap/build/compile.rs
@@ -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
@@ -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())
@@ -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()
diff --git a/src/bootstrap/build/doc.rs b/src/bootstrap/build/doc.rs
index d8b02dce222..50c0c56807b 100644
--- a/src/bootstrap/build/doc.rs
+++ b/src/bootstrap/build/doc.rs
@@ -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);
diff --git a/src/bootstrap/build/mod.rs b/src/bootstrap/build/mod.rs
index 3427feeca6e..bd217940bfb 100644
--- a/src/bootstrap/build/mod.rs
+++ b/src/bootstrap/build/mod.rs
@@ -88,6 +88,7 @@ pub struct Build {
 
 pub enum Mode {
     Libstd,
+    Libtest,
     Librustc,
     Tool,
 }
@@ -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) {
@@ -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);
                 }
@@ -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);
                 }
@@ -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);
@@ -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))
diff --git a/src/bootstrap/build/step.rs b/src/bootstrap/build/step.rs
index 107b0688b68..4e3aacd3720 100644
--- a/src/bootstrap/build/step.rs
+++ b/src/bootstrap/build/step.rs
@@ -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
@@ -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 }),
 
@@ -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));
                 }
             }
         }
@@ -246,7 +250,10 @@ 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(()),
@@ -254,7 +261,10 @@ impl<'a> Step<'a> {
             }
             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),
@@ -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 } => {
@@ -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),
@@ -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 } => {