2017-07-04 19:41:43 -06:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
use Mode;
|
2017-07-05 10:54:19 -06:00
|
|
|
use Compiler;
|
2017-07-18 18:03:38 -06:00
|
|
|
use builder::{Step, ShouldRun, Builder};
|
2017-07-04 19:41:43 -06:00
|
|
|
use util::{exe, add_lib_path};
|
2017-07-20 06:27:13 -06:00
|
|
|
use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
|
2017-07-04 19:41:43 -06:00
|
|
|
use native;
|
|
|
|
use channel::GitInfo;
|
2017-07-13 18:48:44 -06:00
|
|
|
use cache::Interned;
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct CleanTools {
|
2017-07-04 19:41:43 -06:00
|
|
|
pub stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
pub target: Interned<String>,
|
2017-07-04 19:41:43 -06:00
|
|
|
pub mode: Mode,
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for CleanTools {
|
2017-07-04 19:41:43 -06:00
|
|
|
type Output = ();
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.never()
|
2017-07-14 06:30:16 -06:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06: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.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let build = builder.build;
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
|
|
|
let mode = self.mode;
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
let compiler = builder.compiler(stage, build.build);
|
2017-07-04 19:41:43 -06:00
|
|
|
|
|
|
|
let stamp = match mode {
|
2017-07-05 10:46:41 -06:00
|
|
|
Mode::Libstd => libstd_stamp(build, compiler, target),
|
|
|
|
Mode::Libtest => libtest_stamp(build, compiler, target),
|
|
|
|
Mode::Librustc => librustc_stamp(build, compiler, target),
|
2017-07-04 19:41:43 -06:00
|
|
|
_ => panic!(),
|
|
|
|
};
|
2017-07-05 10:46:41 -06:00
|
|
|
let out_dir = build.cargo_out(compiler, Mode::Tool, target);
|
2017-07-04 19:41:43 -06:00
|
|
|
build.clear_if_dirty(&out_dir, &stamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct ToolBuild {
|
2017-07-04 19:41:43 -06:00
|
|
|
pub stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
pub target: Interned<String>,
|
|
|
|
pub tool: &'static str,
|
2017-07-05 06:41:27 -06:00
|
|
|
pub mode: Mode,
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for ToolBuild {
|
2017-07-05 06:41:27 -06:00
|
|
|
type Output = PathBuf;
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.never()
|
2017-07-14 06:30:16 -06:00
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06: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.
|
2017-07-05 06:41:27 -06:00
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
2017-07-04 19:41:43 -06:00
|
|
|
let build = builder.build;
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
|
|
|
let tool = self.tool;
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
let compiler = builder.compiler(stage, build.build);
|
2017-07-05 06:41:27 -06:00
|
|
|
builder.ensure(CleanTools { stage, target, mode: self.mode });
|
|
|
|
match self.mode {
|
|
|
|
Mode::Libstd => builder.ensure(compile::Std { compiler, target }),
|
|
|
|
Mode::Libtest => builder.ensure(compile::Test { compiler, target }),
|
|
|
|
Mode::Librustc => builder.ensure(compile::Rustc { compiler, target }),
|
|
|
|
Mode::Tool => panic!("unexpected Mode::Tool for tool build")
|
|
|
|
}
|
|
|
|
|
2017-07-04 19:41:43 -06:00
|
|
|
let _folder = build.fold_output(|| format!("stage{}-{}", stage, tool));
|
|
|
|
println!("Building stage{} tool {} ({})", stage, tool, target);
|
|
|
|
|
2017-07-05 11:21:33 -06:00
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Tool, target, "build");
|
2017-07-04 19:41:43 -06:00
|
|
|
let dir = build.src.join("src/tools").join(tool);
|
|
|
|
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
if let Some(dir) = build.openssl_install_dir(target) {
|
|
|
|
cargo.env("OPENSSL_STATIC", "1");
|
|
|
|
cargo.env("OPENSSL_DIR", dir);
|
|
|
|
cargo.env("LIBZ_SYS_STATIC", "1");
|
|
|
|
}
|
|
|
|
|
|
|
|
cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel);
|
|
|
|
|
|
|
|
let info = GitInfo::new(&dir);
|
|
|
|
if let Some(sha) = info.sha() {
|
|
|
|
cargo.env("CFG_COMMIT_HASH", sha);
|
|
|
|
}
|
|
|
|
if let Some(sha_short) = info.sha_short() {
|
|
|
|
cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
|
|
|
|
}
|
|
|
|
if let Some(date) = info.commit_date() {
|
|
|
|
cargo.env("CFG_COMMIT_DATE", date);
|
|
|
|
}
|
|
|
|
|
|
|
|
build.run(&mut cargo);
|
2017-07-13 18:48:44 -06:00
|
|
|
build.cargo_out(compiler, Mode::Tool, target).join(exe(tool, &compiler.host))
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! tool {
|
|
|
|
($($name:ident, $path:expr, $tool_name:expr, $mode:expr;)+) => {
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub enum Tool {
|
|
|
|
$(
|
|
|
|
$name,
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Builder<'a> {
|
|
|
|
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
|
|
|
|
match tool {
|
|
|
|
$(Tool::$name =>
|
|
|
|
self.ensure($name {
|
|
|
|
stage: 0,
|
2017-07-13 18:48:44 -06:00
|
|
|
target: self.build.build,
|
2017-07-05 06:41:27 -06:00
|
|
|
}),
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct $name {
|
2017-07-05 06:41:27 -06:00
|
|
|
pub stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
pub target: Interned<String>,
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for $name {
|
2017-07-05 06:41:27 -06:00
|
|
|
type Output = PathBuf;
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.path($path)
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
fn make_run(
|
|
|
|
builder: &Builder,
|
|
|
|
_path: Option<&Path>,
|
|
|
|
_host: Interned<String>,
|
|
|
|
target: Interned<String>
|
|
|
|
) {
|
2017-07-05 06:41:27 -06:00
|
|
|
builder.ensure($name {
|
|
|
|
stage: builder.top_stage,
|
|
|
|
target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
builder.ensure(ToolBuild {
|
|
|
|
stage: self.stage,
|
|
|
|
target: self.target,
|
|
|
|
tool: $tool_name,
|
|
|
|
mode: $mode,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tool!(
|
|
|
|
Rustbook, "src/tools/rustbook", "rustbook", Mode::Librustc;
|
|
|
|
ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::Librustc;
|
2017-07-05 10:46:41 -06:00
|
|
|
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::Libstd;
|
2017-07-05 06:41:27 -06:00
|
|
|
Tidy, "src/tools/tidy", "tidy", Mode::Libstd;
|
|
|
|
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::Libstd;
|
|
|
|
CargoTest, "src/tools/cargotest", "cargotest", Mode::Libstd;
|
|
|
|
Compiletest, "src/tools/compiletest", "compiletest", Mode::Libtest;
|
2017-07-04 10:03:01 -06:00
|
|
|
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Librustc;
|
2017-07-05 06:41:27 -06:00
|
|
|
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::Libstd;
|
|
|
|
RustInstaller, "src/tools/rust-installer", "rust-installer", Mode::Libstd;
|
|
|
|
);
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct RemoteTestServer {
|
2017-07-12 18:52:31 -06:00
|
|
|
pub stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
pub target: Interned<String>,
|
2017-07-12 10:12:47 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for RemoteTestServer {
|
2017-07-12 10:12:47 -06:00
|
|
|
type Output = PathBuf;
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.path("src/tools/remote-test-server")
|
2017-07-12 10:12:47 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
fn make_run(
|
|
|
|
builder: &Builder,
|
|
|
|
_path: Option<&Path>,
|
|
|
|
_host: Interned<String>,
|
|
|
|
target: Interned<String>
|
|
|
|
) {
|
2017-07-12 10:12:47 -06:00
|
|
|
builder.ensure(RemoteTestServer {
|
2017-07-12 18:52:31 -06:00
|
|
|
stage: builder.top_stage,
|
2017-07-12 10:12:47 -06:00
|
|
|
target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
builder.ensure(ToolBuild {
|
|
|
|
stage: self.stage,
|
|
|
|
target: self.target,
|
|
|
|
tool: "remote-test-server",
|
|
|
|
mode: Mode::Libstd,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Cargo {
|
2017-07-05 06:41:27 -06:00
|
|
|
pub stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
pub target: Interned<String>,
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for Cargo {
|
2017-07-05 06:41:27 -06:00
|
|
|
type Output = PathBuf;
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 17:24:11 -06:00
|
|
|
let builder = run.builder;
|
|
|
|
run.path("src/tools/cargo").default_condition(builder.build.config.extended)
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
fn make_run(
|
|
|
|
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
|
|
|
|
) {
|
2017-07-05 06:41:27 -06:00
|
|
|
builder.ensure(Cargo {
|
|
|
|
stage: builder.top_stage,
|
|
|
|
target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
builder.ensure(native::Openssl {
|
|
|
|
target: self.target,
|
|
|
|
});
|
|
|
|
// Cargo depends on procedural macros, which requires a full host
|
|
|
|
// compiler to be available, so we need to depend on that.
|
2017-07-20 06:27:13 -06:00
|
|
|
builder.ensure(compile::Rustc {
|
|
|
|
compiler: builder.compiler(self.stage, builder.build.build),
|
2017-07-13 18:48:44 -06:00
|
|
|
target: builder.build.build,
|
2017-07-05 06:41:27 -06:00
|
|
|
});
|
|
|
|
builder.ensure(ToolBuild {
|
|
|
|
stage: self.stage,
|
|
|
|
target: self.target,
|
|
|
|
tool: "cargo",
|
|
|
|
mode: Mode::Libstd,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Rls {
|
2017-07-05 06:41:27 -06:00
|
|
|
pub stage: u32,
|
2017-07-13 18:48:44 -06:00
|
|
|
pub target: Interned<String>,
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for Rls {
|
2017-07-05 06:41:27 -06:00
|
|
|
type Output = PathBuf;
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
2017-07-18 18:03:38 -06:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 17:24:11 -06:00
|
|
|
let builder = run.builder;
|
|
|
|
run.path("src/tools/rls").default_condition(builder.build.config.extended)
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
fn make_run(
|
|
|
|
builder: &Builder, path: Option<&Path>, _host: Interned<String>, target: Interned<String>
|
|
|
|
) {
|
2017-07-20 06:27:13 -06:00
|
|
|
builder.ensure(Rls {
|
2017-07-05 06:41:27 -06:00
|
|
|
stage: builder.top_stage,
|
|
|
|
target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
builder.ensure(native::Openssl {
|
|
|
|
target: self.target,
|
|
|
|
});
|
|
|
|
// RLS depends on procedural macros, which requires a full host
|
|
|
|
// compiler to be available, so we need to depend on that.
|
2017-07-20 06:27:13 -06:00
|
|
|
builder.ensure(compile::Rustc {
|
|
|
|
compiler: builder.compiler(self.stage, builder.build.build),
|
2017-07-13 18:48:44 -06:00
|
|
|
target: builder.build.build,
|
2017-07-05 06:41:27 -06:00
|
|
|
});
|
|
|
|
builder.ensure(ToolBuild {
|
|
|
|
stage: self.stage,
|
|
|
|
target: self.target,
|
|
|
|
tool: "rls",
|
|
|
|
mode: Mode::Librustc,
|
|
|
|
})
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
}
|
2017-07-05 10:48:02 -06:00
|
|
|
|
|
|
|
impl<'a> Builder<'a> {
|
|
|
|
/// Get a `Command` which is ready to run `tool` in `stage` built for
|
|
|
|
/// `host`.
|
2017-07-05 10:54:19 -06:00
|
|
|
pub fn tool_cmd(&self, tool: Tool) -> Command {
|
|
|
|
let mut cmd = Command::new(self.tool_exe(tool));
|
2017-07-13 18:48:44 -06:00
|
|
|
let compiler = self.compiler(0, self.build.build);
|
2017-07-05 10:48:02 -06:00
|
|
|
self.prepare_tool_cmd(compiler, &mut cmd);
|
|
|
|
cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prepares the `cmd` provided to be able to run the `compiler` provided.
|
|
|
|
///
|
|
|
|
/// Notably this munges the dynamic library lookup path to point to the
|
|
|
|
/// right location to run `compiler`.
|
|
|
|
fn prepare_tool_cmd(&self, compiler: Compiler, cmd: &mut Command) {
|
2017-07-13 18:48:44 -06:00
|
|
|
let host = &compiler.host;
|
|
|
|
let mut paths: Vec<PathBuf> = vec![
|
|
|
|
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host)),
|
|
|
|
self.cargo_out(compiler, Mode::Tool, *host).join("deps"),
|
2017-07-05 10:48:02 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
// On MSVC a tool may invoke a C compiler (e.g. compiletest in run-make
|
|
|
|
// mode) and that C compiler may need some extra PATH modification. Do
|
|
|
|
// so here.
|
|
|
|
if compiler.host.contains("msvc") {
|
2017-07-05 10:54:19 -06:00
|
|
|
let curpaths = env::var_os("PATH").unwrap_or_default();
|
2017-07-05 10:48:02 -06:00
|
|
|
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
|
2017-07-13 18:48:44 -06:00
|
|
|
for &(ref k, ref v) in self.cc[&compiler.host].0.env() {
|
2017-07-05 10:48:02 -06:00
|
|
|
if k != "PATH" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for path in env::split_paths(v) {
|
|
|
|
if !curpaths.contains(&path) {
|
|
|
|
paths.push(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_lib_path(paths, cmd);
|
|
|
|
}
|
|
|
|
}
|