rustbuild: Use an enum to indicate destination
Instead of using a `is_std: bool`, instead use a more well-typed and self-documenting enum to indicate the mode in which Cargo is being invoked.
This commit is contained in:
parent
ee6df13f0c
commit
0788cd23ea
|
@ -16,7 +16,7 @@ use std::process::Command;
|
|||
use build_helper::output;
|
||||
|
||||
use build::util::{exe, staticlib, libdir, mtime, is_dylib};
|
||||
use build::{Build, Compiler};
|
||||
use build::{Build, Compiler, Mode};
|
||||
|
||||
/// Build the standard library.
|
||||
///
|
||||
|
@ -39,9 +39,10 @@ pub fn std<'a>(build: &'a Build, stage: u32, target: &str,
|
|||
|
||||
build_startup_objects(build, target, &libdir);
|
||||
|
||||
let out_dir = build.cargo_out(stage, &host, true, target);
|
||||
let out_dir = build.cargo_out(stage, &host, Mode::Libstd, target);
|
||||
build.clear_if_dirty(&out_dir, &build.compiler_path(compiler));
|
||||
let mut cargo = build.cargo(stage, compiler, true, target, "build");
|
||||
let mut cargo = build.cargo(stage, compiler, Mode::Libstd, Some(target),
|
||||
"build");
|
||||
cargo.arg("--features").arg(build.std_features())
|
||||
.arg("--manifest-path")
|
||||
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"));
|
||||
|
@ -71,7 +72,7 @@ pub fn std_link(build: &Build,
|
|||
compiler: &Compiler,
|
||||
host: &str) {
|
||||
let libdir = build.sysroot_libdir(stage, host, target);
|
||||
let out_dir = build.cargo_out(stage, compiler.host, true, target);
|
||||
let out_dir = build.cargo_out(stage, compiler.host, Mode::Libstd, target);
|
||||
|
||||
// If we're linking one compiler host's output into another, then we weren't
|
||||
// called from the `std` method above. In that case we clean out what's
|
||||
|
@ -135,10 +136,11 @@ pub fn rustc<'a>(build: &'a Build, stage: u32, target: &str,
|
|||
println!("Building stage{} compiler artifacts ({} -> {})", stage,
|
||||
host, target);
|
||||
|
||||
let out_dir = build.cargo_out(stage, &host, false, target);
|
||||
let out_dir = build.cargo_out(stage, &host, Mode::Librustc, target);
|
||||
build.clear_if_dirty(&out_dir, &libstd_shim(build, stage, &host, target));
|
||||
|
||||
let mut cargo = build.cargo(stage, compiler, false, target, "build");
|
||||
let mut cargo = build.cargo(stage, compiler, Mode::Librustc, Some(target),
|
||||
"build");
|
||||
cargo.arg("--features").arg(build.rustc_features(stage))
|
||||
.arg("--manifest-path")
|
||||
.arg(build.src.join("src/rustc/Cargo.toml"));
|
||||
|
@ -200,14 +202,14 @@ pub fn rustc_link(build: &Build,
|
|||
compiler: &Compiler,
|
||||
host: &str) {
|
||||
let libdir = build.sysroot_libdir(stage, host, target);
|
||||
let out_dir = build.cargo_out(stage, compiler.host, false, target);
|
||||
let out_dir = build.cargo_out(stage, compiler.host, Mode::Librustc, target);
|
||||
add_to_sysroot(&out_dir, &libdir);
|
||||
}
|
||||
|
||||
/// Cargo's output path for the standard library in a given stage, compiled
|
||||
/// by a particular compiler for the specified target.
|
||||
fn libstd_shim(build: &Build, stage: u32, host: &str, target: &str) -> PathBuf {
|
||||
build.cargo_out(stage, host, true, target).join("libstd_shim.rlib")
|
||||
build.cargo_out(stage, host, Mode::Libstd, target).join("libstd_shim.rlib")
|
||||
}
|
||||
|
||||
fn compiler_file(compiler: &Path, file: &str) -> String {
|
||||
|
@ -239,7 +241,8 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
let out_dir = build.cargo_out(stage - 1, &build.config.build, false, host);
|
||||
let out_dir = build.cargo_out(stage - 1, &build.config.build,
|
||||
Mode::Librustc, host);
|
||||
|
||||
// Link the compiler binary itself into place
|
||||
let rustc = out_dir.join(exe("rustc", host));
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::path::Path;
|
|||
use std::fs::{self, File};
|
||||
use std::io::prelude::*;
|
||||
|
||||
use build::{Build, Compiler};
|
||||
use build::{Build, Compiler, Mode};
|
||||
use build::util::{up_to_date, cp_r};
|
||||
|
||||
pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) {
|
||||
|
@ -106,14 +106,14 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
|
|||
pub fn std(build: &Build, stage: u32, host: &str, out: &Path) {
|
||||
println!("Documenting stage{} std ({})", stage, host);
|
||||
let compiler = Compiler::new(stage, host);
|
||||
let out_dir = build.stage_out(stage, host, true)
|
||||
let out_dir = build.stage_out(stage, host, Mode::Libstd)
|
||||
.join(host).join("doc");
|
||||
let rustdoc = build.tool(&compiler, "rustdoc");
|
||||
if !up_to_date(&rustdoc, &out_dir.join("std/index.html")) {
|
||||
t!(fs::remove_dir_all(&out_dir));
|
||||
}
|
||||
|
||||
let mut cargo = build.cargo(stage, &compiler, true, host,
|
||||
let mut cargo = build.cargo(stage, &compiler, Mode::Libstd, Some(host),
|
||||
"doc");
|
||||
cargo.arg("--manifest-path")
|
||||
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"))
|
||||
|
@ -125,13 +125,13 @@ pub fn std(build: &Build, stage: u32, host: &str, out: &Path) {
|
|||
pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) {
|
||||
println!("Documenting stage{} compiler ({})", stage, host);
|
||||
let compiler = Compiler::new(stage, host);
|
||||
let out_dir = build.stage_out(stage, host, false)
|
||||
let out_dir = build.stage_out(stage, host, Mode::Librustc)
|
||||
.join(host).join("doc");
|
||||
let rustdoc = build.tool(&compiler, "rustdoc");
|
||||
if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) {
|
||||
t!(fs::remove_dir_all(&out_dir));
|
||||
}
|
||||
let mut cargo = build.cargo(stage, &compiler, false, host,
|
||||
let mut cargo = build.cargo(stage, &compiler, Mode::Librustc, Some(host),
|
||||
"doc");
|
||||
cargo.arg("--manifest-path")
|
||||
.arg(build.src.join("src/rustc/Cargo.toml"))
|
||||
|
|
|
@ -83,6 +83,12 @@ pub struct Build {
|
|||
compiler_rt_built: RefCell<HashMap<String, PathBuf>>,
|
||||
}
|
||||
|
||||
pub enum Mode {
|
||||
Libstd,
|
||||
Librustc,
|
||||
Tool,
|
||||
}
|
||||
|
||||
impl Build {
|
||||
pub fn new(flags: Flags, config: Config) -> Build {
|
||||
let cwd = t!(env::current_dir());
|
||||
|
@ -241,14 +247,17 @@ impl Build {
|
|||
/// Cargo for the specified stage, whether or not the standard library is
|
||||
/// being built, and using the specified compiler targeting `target`.
|
||||
// FIXME: aren't stage/compiler duplicated?
|
||||
fn cargo(&self, stage: u32, compiler: &Compiler, is_std: bool,
|
||||
target: &str, cmd: &str) -> Command {
|
||||
fn cargo(&self,
|
||||
stage: u32,
|
||||
compiler: &Compiler,
|
||||
mode: Mode,
|
||||
target: Option<&str>,
|
||||
cmd: &str) -> Command {
|
||||
let mut cargo = Command::new(&self.cargo);
|
||||
let host = compiler.host;
|
||||
let out_dir = self.stage_out(stage, host, is_std);
|
||||
let out_dir = self.stage_out(stage, host, mode);
|
||||
cargo.env("CARGO_TARGET_DIR", out_dir)
|
||||
.arg(cmd)
|
||||
.arg("--target").arg(target)
|
||||
.arg("-j").arg(self.jobs().to_string());
|
||||
|
||||
// Customize the compiler we're running. Specify the compiler to cargo
|
||||
|
@ -265,24 +274,28 @@ impl Build {
|
|||
.env("RUSTC_SNAPSHOT", &self.rustc)
|
||||
.env("RUSTC_SYSROOT", self.sysroot(stage, host))
|
||||
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir())
|
||||
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "))
|
||||
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
|
||||
.env("RUSTDOC", self.tool(compiler, "rustdoc"));
|
||||
|
||||
// Specify some variuos options for build scripts used throughout the
|
||||
// build.
|
||||
//
|
||||
// FIXME: the guard against msvc shouldn't need to be here
|
||||
if !target.contains("msvc") {
|
||||
cargo.env(format!("CC_{}", target), self.cc(target))
|
||||
.env(format!("AR_{}", target), self.ar(target))
|
||||
.env(format!("CFLAGS_{}", target), self.cflags(target));
|
||||
}
|
||||
if let Some(target) = target {
|
||||
cargo.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
|
||||
cargo.arg("--target").arg(target);
|
||||
|
||||
// Environment variables *required* needed throughout the build
|
||||
//
|
||||
// FIXME: should update code to not require this env vars
|
||||
cargo.env("CFG_COMPILER_HOST_TRIPLE", target);
|
||||
// Specify some various options for build scripts used throughout
|
||||
// the build.
|
||||
//
|
||||
// FIXME: the guard against msvc shouldn't need to be here
|
||||
if !target.contains("msvc") {
|
||||
cargo.env(format!("CC_{}", target), self.cc(target))
|
||||
.env(format!("AR_{}", target), self.ar(target))
|
||||
.env(format!("CFLAGS_{}", target), self.cflags(target));
|
||||
}
|
||||
|
||||
// Environment variables *required* needed throughout the build
|
||||
//
|
||||
// FIXME: should update code to not require this env vars
|
||||
cargo.env("CFG_COMPILER_HOST_TRIPLE", target);
|
||||
}
|
||||
|
||||
if self.config.verbose || self.flags.verbose {
|
||||
cargo.arg("-v");
|
||||
|
@ -306,7 +319,7 @@ impl Build {
|
|||
|
||||
/// Get the specified tool next to the specified compiler
|
||||
fn tool(&self, compiler: &Compiler, tool: &str) -> PathBuf {
|
||||
self.stage_out(compiler.stage, compiler.host, false)
|
||||
self.stage_out(compiler.stage, compiler.host, Mode::Tool)
|
||||
.join(self.cargo_dir())
|
||||
.join(exe(tool, compiler.host))
|
||||
}
|
||||
|
@ -319,8 +332,8 @@ impl Build {
|
|||
let host = compiler.host;
|
||||
let stage = compiler.stage;
|
||||
let paths = vec![
|
||||
self.cargo_out(stage, host, true, host).join("deps"),
|
||||
self.cargo_out(stage, host, false, host).join("deps"),
|
||||
self.cargo_out(stage, host, Mode::Libstd, host).join("deps"),
|
||||
self.cargo_out(stage, host, Mode::Librustc, host).join("deps"),
|
||||
];
|
||||
add_lib_path(paths, &mut cmd);
|
||||
return cmd
|
||||
|
@ -363,7 +376,7 @@ impl Build {
|
|||
|
||||
fn sysroot(&self, stage: u32, host: &str) -> PathBuf {
|
||||
if stage == 0 {
|
||||
self.stage_out(stage, host, false)
|
||||
self.stage_out(stage, host, Mode::Librustc)
|
||||
} else {
|
||||
self.out.join(host).join(format!("stage{}", stage))
|
||||
}
|
||||
|
@ -377,19 +390,21 @@ impl Build {
|
|||
/// Returns the root directory for all output generated in a particular
|
||||
/// stage when running with a particular host compiler.
|
||||
///
|
||||
/// The `is_std` flag indicates whether the root directory is for the
|
||||
/// bootstrap of the standard library or for the compiler.
|
||||
fn stage_out(&self, stage: u32, host: &str, is_std: bool) -> PathBuf {
|
||||
self.out.join(host)
|
||||
.join(format!("stage{}{}", stage, if is_std {"-std"} else {"-rustc"}))
|
||||
/// The mode indicates what the root directory is for.
|
||||
fn stage_out(&self, stage: u32, host: &str, mode: Mode) -> PathBuf {
|
||||
let suffix = match mode {
|
||||
Mode::Libstd => "-std",
|
||||
_ => "-rustc",
|
||||
};
|
||||
self.out.join(host).join(format!("stage{}{}", stage, suffix))
|
||||
}
|
||||
|
||||
/// Returns the root output directory for all Cargo output in a given stage,
|
||||
/// running a particular comipler, wehther or not we're building the
|
||||
/// standard library, and targeting the specified architecture.
|
||||
fn cargo_out(&self, stage: u32, host: &str, is_std: bool,
|
||||
fn cargo_out(&self, stage: u32, host: &str, mode: Mode,
|
||||
target: &str) -> PathBuf {
|
||||
self.stage_out(stage, host, is_std).join(target).join(self.cargo_dir())
|
||||
self.stage_out(stage, host, mode).join(target).join(self.cargo_dir())
|
||||
}
|
||||
|
||||
/// Root output directory for LLVM compiled for `target`
|
||||
|
|
Loading…
Reference in New Issue