2015-11-19 15:20:12 -08:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-02 15:16:15 -07:00
|
|
|
//! Implementation of compiling various phases of the compiler and standard
|
|
|
|
//! library.
|
|
|
|
//!
|
|
|
|
//! This module contains some of the real meat in the rustbuild build system
|
|
|
|
//! which is where Cargo is used to compiler the standard library, libtest, and
|
|
|
|
//! compiler. This module is also responsible for assembling the sysroot as it
|
|
|
|
//! goes along from the output of the previous stage.
|
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
use std::collections::HashMap;
|
2016-09-12 21:46:35 -07:00
|
|
|
use std::fs::{self, File};
|
2015-11-19 15:20:12 -08:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
use build_helper::output;
|
2016-09-12 21:46:35 -07:00
|
|
|
use filetime::FileTime;
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2016-09-28 20:55:26 +00:00
|
|
|
use util::{exe, libdir, mtime, is_dylib, copy};
|
2016-07-05 21:58:20 -07:00
|
|
|
use {Build, Compiler, Mode};
|
2015-11-19 15:20:12 -08:00
|
|
|
|
|
|
|
/// Build the standard library.
|
|
|
|
///
|
|
|
|
/// This will build the standard library 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.
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
pub fn std(build: &Build, target: &str, compiler: &Compiler) {
|
2016-03-11 17:30:16 -08:00
|
|
|
let libdir = build.sysroot_libdir(compiler, target);
|
2015-11-19 15:20:12 -08:00
|
|
|
t!(fs::create_dir_all(&libdir));
|
|
|
|
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
|
|
|
|
compiler.host, target);
|
|
|
|
|
2016-03-11 17:30:16 -08:00
|
|
|
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
|
2015-11-19 15:20:12 -08:00
|
|
|
build.clear_if_dirty(&out_dir, &build.compiler_path(compiler));
|
2016-03-11 17:30:16 -08:00
|
|
|
let mut cargo = build.cargo(compiler, Mode::Libstd, target, "build");
|
2015-11-19 15:20:12 -08:00
|
|
|
cargo.arg("--features").arg(build.std_features())
|
|
|
|
.arg("--manifest-path")
|
|
|
|
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"));
|
|
|
|
|
|
|
|
if let Some(target) = build.config.target_config.get(target) {
|
|
|
|
if let Some(ref jemalloc) = target.jemalloc {
|
|
|
|
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 01:04:41 -05:00
|
|
|
if target.contains("musl") {
|
2016-09-06 21:49:02 -05:00
|
|
|
if let Some(p) = build.musl_root(target) {
|
2015-11-19 15:20:12 -08:00
|
|
|
cargo.env("MUSL_ROOT", p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build.run(&mut cargo);
|
2016-12-31 17:42:40 -08:00
|
|
|
update_mtime(build, &libstd_stamp(build, &compiler, target));
|
2016-02-24 23:50:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Link all libstd rlibs/dylibs into the sysroot location.
|
|
|
|
///
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
/// Links those artifacts generated by `compiler` to a the `stage` compiler's
|
|
|
|
/// sysroot for the specified `host` and `target`.
|
|
|
|
///
|
|
|
|
/// Note that this assumes that `compiler` has already generated the libstd
|
|
|
|
/// libraries for `target`, and this method will find them in the relevant
|
|
|
|
/// output directory.
|
2016-02-24 23:50:32 -08:00
|
|
|
pub fn std_link(build: &Build,
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
compiler: &Compiler,
|
|
|
|
target_compiler: &Compiler,
|
|
|
|
target: &str) {
|
|
|
|
println!("Copying stage{} std from stage{} ({} -> {} / {})",
|
|
|
|
target_compiler.stage,
|
|
|
|
compiler.stage,
|
|
|
|
compiler.host,
|
|
|
|
target_compiler.host,
|
|
|
|
target);
|
2016-03-11 17:30:16 -08:00
|
|
|
let libdir = build.sysroot_libdir(&target_compiler, target);
|
2016-10-21 13:18:09 -07:00
|
|
|
let out_dir = build.cargo_out(&compiler, Mode::Libstd, target);
|
2016-02-24 23:50:32 -08:00
|
|
|
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
t!(fs::create_dir_all(&libdir));
|
2015-11-19 15:20:12 -08:00
|
|
|
add_to_sysroot(&out_dir, &libdir);
|
2016-03-06 08:19:51 -05:00
|
|
|
|
2016-04-27 18:02:31 -07:00
|
|
|
if target.contains("musl") && !target.contains("mips") {
|
2016-10-04 20:17:53 -05:00
|
|
|
copy_musl_third_party_objects(build, target, &libdir);
|
2016-03-06 08:19:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Copies the crt(1,i,n).o startup objects
|
|
|
|
///
|
|
|
|
/// Only required for musl targets that statically link to libc
|
2016-10-04 20:17:53 -05:00
|
|
|
fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) {
|
2016-03-06 08:19:51 -05:00
|
|
|
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
|
2016-10-04 20:17:53 -05:00
|
|
|
copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
|
2016-03-06 08:19:51 -05:00
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Build and prepare startup objects like rsbegin.o and rsend.o
|
|
|
|
///
|
|
|
|
/// These are primarily used on Windows right now for linking executables/dlls.
|
|
|
|
/// They don't require any library support as they're just plain old object
|
|
|
|
/// files, so we just use the nightly snapshot compiler to always build them (as
|
|
|
|
/// no other compilers are guaranteed to be available).
|
2016-12-29 18:17:31 -08:00
|
|
|
pub fn build_startup_objects(build: &Build, for_compiler: &Compiler, target: &str) {
|
2015-11-19 15:20:12 -08:00
|
|
|
if !target.contains("pc-windows-gnu") {
|
|
|
|
return
|
|
|
|
}
|
2016-12-29 18:17:31 -08:00
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
let compiler = Compiler::new(0, &build.config.build);
|
2016-09-12 22:40:14 -07:00
|
|
|
let compiler_path = build.compiler_path(&compiler);
|
2016-12-29 18:17:31 -08:00
|
|
|
let into = build.sysroot_libdir(for_compiler, target);
|
|
|
|
t!(fs::create_dir_all(&into));
|
2015-11-19 15:20:12 -08:00
|
|
|
|
|
|
|
for file in t!(fs::read_dir(build.src.join("src/rtstartup"))) {
|
|
|
|
let file = t!(file);
|
2016-09-12 22:40:14 -07:00
|
|
|
let mut cmd = Command::new(&compiler_path);
|
2016-11-16 09:19:02 -08:00
|
|
|
build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
|
|
|
|
.arg("--target").arg(target)
|
2016-09-12 22:40:14 -07:00
|
|
|
.arg("--emit=obj")
|
2016-12-29 18:17:31 -08:00
|
|
|
.arg("--out-dir").arg(&into)
|
2016-09-12 22:40:14 -07:00
|
|
|
.arg(file.path()));
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for obj in ["crt2.o", "dllcrt2.o"].iter() {
|
2016-04-05 10:00:25 -07:00
|
|
|
copy(&compiler_file(build.cc(target), obj), &into.join(obj));
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
2016-03-27 22:28:10 -07:00
|
|
|
/// 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.
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
pub fn test(build: &Build, target: &str, compiler: &Compiler) {
|
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
2016-03-27 22:28:10 -07:00
|
|
|
println!("Building stage{} test artifacts ({} -> {})", compiler.stage,
|
|
|
|
compiler.host, target);
|
|
|
|
let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
|
2016-09-12 21:46:35 -07:00
|
|
|
build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target));
|
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
2016-03-27 22:28:10 -07:00
|
|
|
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);
|
2016-12-31 17:42:40 -08:00
|
|
|
update_mtime(build, &libtest_stamp(build, compiler, target));
|
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
2016-03-27 22:28:10 -07:00
|
|
|
}
|
|
|
|
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
/// Same as `std_link`, only for libtest
|
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
2016-03-27 22:28:10 -07:00
|
|
|
pub fn test_link(build: &Build,
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
compiler: &Compiler,
|
|
|
|
target_compiler: &Compiler,
|
|
|
|
target: &str) {
|
2016-12-29 18:17:31 -08:00
|
|
|
println!("Copying stage{} test from stage{} ({} -> {} / {})",
|
|
|
|
target_compiler.stage,
|
|
|
|
compiler.stage,
|
|
|
|
compiler.host,
|
|
|
|
target_compiler.host,
|
|
|
|
target);
|
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
2016-03-27 22:28:10 -07:00
|
|
|
let libdir = build.sysroot_libdir(&target_compiler, target);
|
2016-10-21 13:18:09 -07:00
|
|
|
let out_dir = build.cargo_out(&compiler, Mode::Libtest, target);
|
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
2016-03-27 22:28:10 -07:00
|
|
|
add_to_sysroot(&out_dir, &libdir);
|
|
|
|
}
|
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
/// Build the compiler.
|
|
|
|
///
|
|
|
|
/// This will build the compiler 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.
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
pub fn rustc(build: &Build, target: &str, compiler: &Compiler) {
|
2016-03-11 17:30:16 -08:00
|
|
|
println!("Building stage{} compiler artifacts ({} -> {})",
|
|
|
|
compiler.stage, compiler.host, target);
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2016-03-11 17:30:16 -08:00
|
|
|
let out_dir = build.cargo_out(compiler, Mode::Librustc, target);
|
2016-09-12 21:46:35 -07:00
|
|
|
build.clear_if_dirty(&out_dir, &libtest_stamp(build, compiler, target));
|
2015-11-19 15:20:12 -08:00
|
|
|
|
2016-03-11 17:30:16 -08:00
|
|
|
let mut cargo = build.cargo(compiler, Mode::Librustc, target, "build");
|
2016-03-07 23:21:05 -08:00
|
|
|
cargo.arg("--features").arg(build.rustc_features())
|
2015-11-19 15:20:12 -08:00
|
|
|
.arg("--manifest-path")
|
|
|
|
.arg(build.src.join("src/rustc/Cargo.toml"));
|
|
|
|
|
|
|
|
// Set some configuration variables picked up by build scripts and
|
|
|
|
// the compiler alike
|
|
|
|
cargo.env("CFG_RELEASE", &build.release)
|
|
|
|
.env("CFG_RELEASE_CHANNEL", &build.config.channel)
|
|
|
|
.env("CFG_VERSION", &build.version)
|
2016-12-28 09:18:54 -08:00
|
|
|
.env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(PathBuf::new()))
|
2015-11-19 15:20:12 -08:00
|
|
|
.env("CFG_LIBDIR_RELATIVE", "lib");
|
|
|
|
|
2017-01-10 20:01:54 -08:00
|
|
|
// If we're not building a compiler with debugging information then remove
|
|
|
|
// these two env vars which would be set otherwise.
|
|
|
|
if build.config.rust_debuginfo_only_std {
|
|
|
|
cargo.env_remove("RUSTC_DEBUGINFO");
|
|
|
|
cargo.env_remove("RUSTC_DEBUGINFO_LINES");
|
|
|
|
}
|
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
if let Some(ref ver_date) = build.ver_date {
|
|
|
|
cargo.env("CFG_VER_DATE", ver_date);
|
|
|
|
}
|
|
|
|
if let Some(ref ver_hash) = build.ver_hash {
|
|
|
|
cargo.env("CFG_VER_HASH", ver_hash);
|
|
|
|
}
|
|
|
|
if !build.unstable_features {
|
|
|
|
cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
|
|
|
|
}
|
2016-07-29 23:09:32 +10:00
|
|
|
// Flag that rust llvm is in use
|
2016-08-06 15:54:28 +10:00
|
|
|
if build.is_rust_llvm(target) {
|
2016-07-29 23:09:32 +10:00
|
|
|
cargo.env("LLVM_RUSTLLVM", "1");
|
|
|
|
}
|
2016-04-05 11:34:23 -07:00
|
|
|
cargo.env("LLVM_CONFIG", build.llvm_config(target));
|
2016-08-31 19:10:24 -04:00
|
|
|
let target_config = build.config.target_config.get(target);
|
|
|
|
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
|
|
|
|
cargo.env("CFG_LLVM_ROOT", s);
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
if build.config.llvm_static_stdcpp {
|
|
|
|
cargo.env("LLVM_STATIC_STDCPP",
|
|
|
|
compiler_file(build.cxx(target), "libstdc++.a"));
|
|
|
|
}
|
2016-11-16 23:28:14 -08:00
|
|
|
if build.config.llvm_link_shared {
|
|
|
|
cargo.env("LLVM_LINK_SHARED", "1");
|
|
|
|
}
|
2015-11-19 15:20:12 -08:00
|
|
|
if let Some(ref s) = build.config.rustc_default_linker {
|
|
|
|
cargo.env("CFG_DEFAULT_LINKER", s);
|
|
|
|
}
|
|
|
|
if let Some(ref s) = build.config.rustc_default_ar {
|
|
|
|
cargo.env("CFG_DEFAULT_AR", s);
|
|
|
|
}
|
|
|
|
build.run(&mut cargo);
|
2016-02-24 23:50:32 -08:00
|
|
|
}
|
|
|
|
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
/// Same as `std_link`, only for librustc
|
2016-02-24 23:50:32 -08:00
|
|
|
pub fn rustc_link(build: &Build,
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
compiler: &Compiler,
|
|
|
|
target_compiler: &Compiler,
|
|
|
|
target: &str) {
|
2016-12-29 18:17:31 -08:00
|
|
|
println!("Copying stage{} rustc from stage{} ({} -> {} / {})",
|
|
|
|
target_compiler.stage,
|
|
|
|
compiler.stage,
|
|
|
|
compiler.host,
|
|
|
|
target_compiler.host,
|
|
|
|
target);
|
2016-03-11 17:30:16 -08:00
|
|
|
let libdir = build.sysroot_libdir(&target_compiler, target);
|
2016-10-21 13:18:09 -07:00
|
|
|
let out_dir = build.cargo_out(&compiler, Mode::Librustc, target);
|
2016-02-24 23:50:32 -08:00
|
|
|
add_to_sysroot(&out_dir, &libdir);
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Cargo's output path for the standard library in a given stage, compiled
|
|
|
|
/// by a particular compiler for the specified target.
|
2016-09-12 21:46:35 -07:00
|
|
|
fn libstd_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
|
|
|
|
build.cargo_out(compiler, Mode::Libstd, target).join(".libstd.stamp")
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
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
2016-03-27 22:28:10 -07:00
|
|
|
/// Cargo's output path for libtest in a given stage, compiled by a particular
|
|
|
|
/// compiler for the specified target.
|
2016-09-12 21:46:35 -07:00
|
|
|
fn libtest_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
|
|
|
|
build.cargo_out(compiler, Mode::Libtest, target).join(".libtest.stamp")
|
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
2016-03-27 22:28:10 -07:00
|
|
|
}
|
|
|
|
|
2016-04-05 10:00:25 -07:00
|
|
|
fn compiler_file(compiler: &Path, file: &str) -> PathBuf {
|
|
|
|
let out = output(Command::new(compiler)
|
|
|
|
.arg(format!("-print-file-name={}", file)));
|
|
|
|
PathBuf::from(out.trim())
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
pub fn create_sysroot(build: &Build, compiler: &Compiler) {
|
|
|
|
let sysroot = build.sysroot(compiler);
|
|
|
|
let _ = fs::remove_dir_all(&sysroot);
|
|
|
|
t!(fs::create_dir_all(&sysroot));
|
|
|
|
}
|
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
/// Prepare a new compiler from the artifacts in `stage`
|
|
|
|
///
|
2016-02-24 19:03:48 -08:00
|
|
|
/// This will assemble a compiler in `build/$host/stage$stage`. The compiler
|
|
|
|
/// must have been previously produced by the `stage - 1` build.config.build
|
|
|
|
/// compiler.
|
|
|
|
pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
|
2016-10-21 13:18:09 -07:00
|
|
|
// nothing to do in stage0
|
|
|
|
if stage == 0 {
|
|
|
|
return
|
|
|
|
}
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
|
|
|
|
println!("Copying stage{} compiler ({})", stage, host);
|
|
|
|
|
2016-03-11 17:30:16 -08:00
|
|
|
// The compiler that we're assembling
|
|
|
|
let target_compiler = Compiler::new(stage, host);
|
|
|
|
|
|
|
|
// The compiler that compiled the compiler we're assembling
|
|
|
|
let build_compiler = Compiler::new(stage - 1, &build.config.build);
|
2016-02-24 19:03:48 -08:00
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
// Link in all dylibs to the libdir
|
rustbuild: Compile rustc twice, not thrice
This commit switches the rustbuild build system to compiling the
compiler twice for a normal bootstrap rather than the historical three
times.
Rust is a bootstrapped language which means that a previous version of
the compiler is used to build the next version of the compiler. Over
time, however, we change many parts of compiler artifacts such as the
metadata format, symbol names, etc. These changes make artifacts from
one compiler incompatible from another compiler. Consequently if a
compiler wants to be able to use some artifacts then it itself must have
compiled the artifacts.
Historically the rustc build system has achieved this by compiling the
compiler three times:
* An older compiler (stage0) is downloaded to kick off the chain.
* This compiler now compiles a new compiler (stage1)
* The stage1 compiler then compiles another compiler (stage2)
* Finally, the stage2 compiler needs libraries to link against, so it
compiles all the libraries again.
This entire process amounts in compiling the compiler three times.
Additionally, this process always guarantees that the Rust source tree
can compile itself because the stage2 compiler (created by a freshly
created compiler) would successfully compile itself again. This
property, ensuring Rust can compile itself, is quite important!
In general, though, this third compilation is not required for general
purpose development on the compiler. The third compiler (stage2) can
reuse the libraries that were created during the second compile. In
other words, the second compilation can produce both a compiler and the
libraries that compiler will use. These artifacts *must* be compatible
due to the way plugins work today anyway, and they were created by the
same source code so they *should* be compatible as well.
So given all that, this commit switches the default build process to
only compile the compiler three times, avoiding this third compilation
by copying artifacts from the previous one. Along the way a new entry in
the Travis matrix was also added to ensure that our full bootstrap can
succeed. This entry does not run tests, though, as it should not be
necessary.
To restore the old behavior of a full bootstrap (three compiles) you can
either pass:
./configure --enable-full-bootstrap
or if you're using config.toml:
[build]
full-bootstrap = true
Overall this will hopefully be an easy 33% win in build times of the
compiler. If we do 33% less work we should be 33% faster! This in turn
should affect cycle times and such on Travis and AppVeyor positively as
well as making it easier to work on the compiler itself.
2016-12-25 15:20:33 -08:00
|
|
|
let sysroot = build.sysroot(&target_compiler);
|
2015-11-19 15:20:12 -08:00
|
|
|
let sysroot_libdir = sysroot.join(libdir(host));
|
|
|
|
t!(fs::create_dir_all(&sysroot_libdir));
|
2016-03-11 17:30:16 -08:00
|
|
|
let src_libdir = build.sysroot_libdir(&build_compiler, host);
|
2015-11-19 15:20:12 -08:00
|
|
|
for f in t!(fs::read_dir(&src_libdir)).map(|f| t!(f)) {
|
|
|
|
let filename = f.file_name().into_string().unwrap();
|
|
|
|
if is_dylib(&filename) {
|
2016-04-05 10:00:25 -07:00
|
|
|
copy(&f.path(), &sysroot_libdir.join(&filename));
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 17:30:16 -08:00
|
|
|
let out_dir = build.cargo_out(&build_compiler, Mode::Librustc, host);
|
2016-02-24 19:03:48 -08:00
|
|
|
|
2015-11-19 15:20:12 -08:00
|
|
|
// Link the compiler binary itself into place
|
2016-02-24 19:03:48 -08:00
|
|
|
let rustc = out_dir.join(exe("rustc", host));
|
2015-11-19 15:20:12 -08:00
|
|
|
let bindir = sysroot.join("bin");
|
|
|
|
t!(fs::create_dir_all(&bindir));
|
2016-02-24 19:03:48 -08:00
|
|
|
let compiler = build.compiler_path(&Compiler::new(stage, host));
|
2015-11-19 15:20:12 -08:00
|
|
|
let _ = fs::remove_file(&compiler);
|
2016-04-05 10:00:25 -07:00
|
|
|
copy(&rustc, &compiler);
|
2015-11-19 15:20:12 -08:00
|
|
|
|
|
|
|
// See if rustdoc exists to link it into place
|
2016-02-24 19:03:48 -08:00
|
|
|
let rustdoc = exe("rustdoc", host);
|
|
|
|
let rustdoc_src = out_dir.join(&rustdoc);
|
|
|
|
let rustdoc_dst = bindir.join(&rustdoc);
|
2015-11-19 15:20:12 -08:00
|
|
|
if fs::metadata(&rustdoc_src).is_ok() {
|
|
|
|
let _ = fs::remove_file(&rustdoc_dst);
|
2016-04-05 10:00:25 -07:00
|
|
|
copy(&rustdoc_src, &rustdoc_dst);
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Link some files into a rustc sysroot.
|
|
|
|
///
|
|
|
|
/// For a particular stage this will link all of the contents of `out_dir`
|
|
|
|
/// into the sysroot of the `host` compiler, assuming the artifacts are
|
|
|
|
/// compiled for the specified `target`.
|
|
|
|
fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) {
|
|
|
|
// Collect the set of all files in the dependencies directory, keyed
|
|
|
|
// off the name of the library. We assume everything is of the form
|
|
|
|
// `foo-<hash>.{rlib,so,...}`, and there could be multiple different
|
|
|
|
// `<hash>` values for the same name (of old builds).
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
for file in t!(fs::read_dir(out_dir.join("deps"))).map(|f| t!(f)) {
|
|
|
|
let filename = file.file_name().into_string().unwrap();
|
|
|
|
|
|
|
|
// We're only interested in linking rlibs + dylibs, other things like
|
|
|
|
// unit tests don't get linked in
|
|
|
|
if !filename.ends_with(".rlib") &&
|
|
|
|
!filename.ends_with(".lib") &&
|
|
|
|
!is_dylib(&filename) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
let file = file.path();
|
|
|
|
let dash = filename.find("-").unwrap();
|
|
|
|
let key = (filename[..dash].to_string(),
|
|
|
|
file.extension().unwrap().to_owned());
|
|
|
|
map.entry(key).or_insert(Vec::new())
|
|
|
|
.push(file.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
// For all hash values found, pick the most recent one to move into the
|
|
|
|
// sysroot, that should be the one we just built.
|
|
|
|
for (_, paths) in map {
|
|
|
|
let (_, path) = paths.iter().map(|path| {
|
|
|
|
(mtime(&path).seconds(), path)
|
|
|
|
}).max().unwrap();
|
2016-04-05 10:00:25 -07:00
|
|
|
copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
|
2015-11-19 15:20:12 -08:00
|
|
|
}
|
|
|
|
}
|
2016-03-07 22:32:37 -08:00
|
|
|
|
|
|
|
/// Build a tool in `src/tools`
|
|
|
|
///
|
|
|
|
/// This will build the specified tool with the specified `host` compiler in
|
|
|
|
/// `stage` into the normal cargo output directory.
|
|
|
|
pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) {
|
|
|
|
println!("Building stage{} tool {} ({})", stage, tool, host);
|
|
|
|
|
|
|
|
let compiler = Compiler::new(stage, host);
|
|
|
|
|
|
|
|
// FIXME: need to clear out previous tool and ideally deps, may require
|
|
|
|
// isolating output directories or require a pseudo shim step to
|
|
|
|
// clear out all the info.
|
|
|
|
//
|
|
|
|
// Maybe when libstd is compiled it should clear out the rustc of the
|
|
|
|
// corresponding stage?
|
|
|
|
// let out_dir = build.cargo_out(stage, &host, Mode::Librustc, target);
|
2016-09-12 21:46:35 -07:00
|
|
|
// build.clear_if_dirty(&out_dir, &libstd_stamp(build, stage, &host, target));
|
2016-03-07 22:32:37 -08:00
|
|
|
|
2016-03-11 17:30:16 -08:00
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Tool, host, "build");
|
2016-03-07 22:32:37 -08:00
|
|
|
cargo.arg("--manifest-path")
|
|
|
|
.arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool)));
|
2016-12-28 15:01:21 -08:00
|
|
|
|
|
|
|
// We don't want to build tools dynamically as they'll be running across
|
|
|
|
// stages and such and it's just easier if they're not dynamically linked.
|
|
|
|
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
|
|
|
|
|
2016-03-07 22:32:37 -08:00
|
|
|
build.run(&mut cargo);
|
|
|
|
}
|
2016-09-12 21:46:35 -07:00
|
|
|
|
|
|
|
/// Updates the mtime of a stamp file if necessary, only changing it if it's
|
2016-12-31 17:42:40 -08:00
|
|
|
/// older than some other library file in the same directory.
|
2016-09-12 21:46:35 -07:00
|
|
|
///
|
|
|
|
/// We don't know what file Cargo is going to output (because there's a hash in
|
|
|
|
/// the file name) but we know where it's going to put it. We use this helper to
|
|
|
|
/// detect changes to that output file by looking at the modification time for
|
|
|
|
/// all files in a directory and updating the stamp if any are newer.
|
2016-12-31 17:42:40 -08:00
|
|
|
///
|
|
|
|
/// Note that we only consider Rust libraries as that's what we're interested in
|
|
|
|
/// propagating changes from. Files like executables are tracked elsewhere.
|
|
|
|
fn update_mtime(build: &Build, path: &Path) {
|
|
|
|
let entries = match path.parent().unwrap().join("deps").read_dir() {
|
|
|
|
Ok(entries) => entries,
|
|
|
|
Err(_) => return,
|
|
|
|
};
|
|
|
|
let files = entries.map(|e| t!(e)).filter(|e| t!(e.file_type()).is_file());
|
|
|
|
let files = files.filter(|e| {
|
|
|
|
let filename = e.file_name();
|
|
|
|
let filename = filename.to_str().unwrap();
|
|
|
|
filename.ends_with(".rlib") ||
|
|
|
|
filename.ends_with(".lib") ||
|
|
|
|
is_dylib(&filename)
|
|
|
|
});
|
|
|
|
let max = files.max_by_key(|entry| {
|
|
|
|
let meta = t!(entry.metadata());
|
|
|
|
FileTime::from_last_modification_time(&meta)
|
|
|
|
});
|
|
|
|
let max = match max {
|
|
|
|
Some(max) => max,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
if mtime(&max.path()) > mtime(path) {
|
|
|
|
build.verbose(&format!("updating {:?} as {:?} changed", path, max.path()));
|
|
|
|
t!(File::create(path));
|
2016-09-12 21:46:35 -07:00
|
|
|
}
|
|
|
|
}
|