// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::fs;
use std::env;
-use std::path::{Path, PathBuf};
+use std::path::PathBuf;
use std::process::Command;
use Mode;
use Compiler;
-use builder::{Step, Builder};
-use util::{exe, add_lib_path};
-use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp, Rustc};
+use builder::{Step, RunConfig, ShouldRun, Builder};
+use util::{copy, exe, add_lib_path};
+use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
use native;
use channel::GitInfo;
+use cache::Interned;
-//// ========================================================================
-//// Build tools
-////
-//// Tools used during the build system but not shipped
-//// "pseudo rule" which represents completely cleaning out the tools dir in
-//// one stage. This needs to happen whenever a dependency changes (e.g.
-//// libstd, libtest, librustc) and all of the tool compilations above will
-//// be sequenced after this rule.
-//rules.build("maybe-clean-tools", "path/to/nowhere")
-// .after("librustc-tool")
-// .after("libtest-tool")
-// .after("libstd-tool");
-//
-//rules.build("librustc-tool", "path/to/nowhere")
-// .dep(|s| s.name("librustc"))
-// .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Librustc));
-//rules.build("libtest-tool", "path/to/nowhere")
-// .dep(|s| s.name("libtest"))
-// .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Libtest));
-//rules.build("libstd-tool", "path/to/nowhere")
-// .dep(|s| s.name("libstd"))
-// .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Libstd));
-//
-
-#[derive(Serialize)]
-pub struct CleanTools<'a> {
- pub stage: u32,
- pub target: &'a str,
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct CleanTools {
+ pub compiler: Compiler,
+ pub target: Interned<String>,
pub mode: Mode,
}
-impl<'a> Step<'a> for CleanTools<'a> {
- type Id = CleanTools<'static>;
+impl Step for CleanTools {
type Output = ();
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ run.never()
+ }
+
/// 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 compiler = self.compiler;
let target = self.target;
let mode = self.mode;
- let compiler = builder.compiler(stage, &build.build);
-
let stamp = match mode {
Mode::Libstd => libstd_stamp(build, compiler, target),
Mode::Libtest => libtest_stamp(build, compiler, target),
}
}
-#[derive(Serialize)]
-pub struct ToolBuild<'a> {
- pub stage: u32,
- pub target: &'a str,
- pub tool: &'a str,
- pub mode: Mode,
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+struct ToolBuild {
+ compiler: Compiler,
+ target: Interned<String>,
+ tool: &'static str,
+ mode: Mode,
}
-impl<'a> Step<'a> for ToolBuild<'a> {
- type Id = ToolBuild<'static>;
+impl Step for ToolBuild {
type Output = PathBuf;
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ run.never()
+ }
+
/// 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) -> PathBuf {
let build = builder.build;
- let stage = self.stage;
+ let compiler = self.compiler;
let target = self.target;
let tool = self.tool;
- let compiler = builder.compiler(stage, &build.build);
- 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::Tool => panic!("unexpected Mode::Tool for tool build")
}
- let _folder = build.fold_output(|| format!("stage{}-{}", stage, tool));
- println!("Building stage{} tool {} ({})", stage, tool, target);
+ let _folder = build.fold_output(|| format!("stage{}-{}", compiler.stage, tool));
+ println!("Building stage{} tool {} ({})", compiler.stage, tool, target);
- let mut cargo = builder.cargo(compiler, Mode::Tool, target, "build");
- 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");
- }
+ let mut cargo = prepare_tool_cargo(builder, compiler, target, tool);
+ build.run(&mut cargo);
+ build.cargo_out(compiler, Mode::Tool, target).join(exe(tool, &compiler.host))
+ }
+}
- cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel);
+fn prepare_tool_cargo(
+ builder: &Builder,
+ compiler: Compiler,
+ target: Interned<String>,
+ tool: &'static str,
+) -> Command {
+ let build = builder.build;
+ let mut cargo = builder.cargo(compiler, Mode::Tool, target, "build");
+ 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");
+ }
- 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);
- }
+ cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel);
- build.run(&mut cargo);
- build.cargo_out(compiler, Mode::Tool, target).join(exe(tool, compiler.host))
+ let info = GitInfo::new(&build.config, &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);
+ }
+ cargo
}
macro_rules! tool {
match tool {
$(Tool::$name =>
self.ensure($name {
- stage: 0,
- target: &self.build.build,
+ compiler: self.compiler(0, self.build.build),
+ target: self.build.build,
}),
)+
}
}
$(
- #[derive(Serialize)]
- pub struct $name<'a> {
- pub stage: u32,
- pub target: &'a str,
+ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+ pub struct $name {
+ pub compiler: Compiler,
+ pub target: Interned<String>,
}
- impl<'a> Step<'a> for $name<'a> {
- type Id = $name<'static>;
+ impl Step for $name {
type Output = PathBuf;
- fn should_run(_builder: &Builder, path: &Path) -> bool {
- path.ends_with($path)
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ run.path($path)
}
- fn make_run(builder: &Builder, _path: Option<&Path>, _host: &str, target: &str) {
- builder.ensure($name {
- stage: builder.top_stage,
- target,
+ fn make_run(run: RunConfig) {
+ run.builder.ensure($name {
+ compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
+ target: run.target,
});
}
fn run(self, builder: &Builder) -> PathBuf {
builder.ensure(ToolBuild {
- stage: self.stage,
+ compiler: self.compiler,
target: self.target,
tool: $tool_name,
mode: $mode,
}
tool!(
- // rules.build("tool-rustbook", "src/tools/rustbook")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("librustc-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "rustbook"));
Rustbook, "src/tools/rustbook", "rustbook", Mode::Librustc;
- // rules.build("tool-error-index", "src/tools/error_index_generator")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("librustc-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "error_index_generator"));
ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::Librustc;
- // rules.build("tool-unstable-book-gen", "src/tools/unstable-book-gen")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "unstable-book-gen"));
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::Libstd;
- // rules.build("tool-tidy", "src/tools/tidy")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "tidy"));
Tidy, "src/tools/tidy", "tidy", Mode::Libstd;
- // rules.build("tool-linkchecker", "src/tools/linkchecker")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "linkchecker"));
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::Libstd;
- // rules.build("tool-cargotest", "src/tools/cargotest")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "cargotest"));
CargoTest, "src/tools/cargotest", "cargotest", Mode::Libstd;
- // rules.build("tool-compiletest", "src/tools/compiletest")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libtest-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "compiletest"));
Compiletest, "src/tools/compiletest", "compiletest", Mode::Libtest;
- // rules.build("tool-build-manifest", "src/tools/build-manifest")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "build-manifest"));
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Librustc;
- // rules.build("tool-remote-test-client", "src/tools/remote-test-client")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "remote-test-client"));
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::Libstd;
- // rules.build("tool-rust-installer", "src/tools/rust-installer")
- // .dep(|s| s.name("maybe-clean-tools"))
- // .dep(|s| s.name("libstd-tool"))
- // .run(move |s| compile::tool(build, s.stage, s.target, "rust-installer"));
RustInstaller, "src/tools/rust-installer", "rust-installer", Mode::Libstd;
);
-#[derive(Serialize)]
-pub struct RemoteTestServer<'a> {
- pub stage: u32,
- pub target: &'a str,
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct RemoteTestServer {
+ pub compiler: Compiler,
+ pub target: Interned<String>,
}
-impl<'a> Step<'a> for RemoteTestServer<'a> {
- type Id = RemoteTestServer<'static>;
+impl Step for RemoteTestServer {
type Output = PathBuf;
- fn should_run(_builder: &Builder, path: &Path) -> bool {
- path.ends_with("src/tools/remote-test-server")
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ run.path("src/tools/remote-test-server")
}
- fn make_run(builder: &Builder, _path: Option<&Path>, _host: &str, target: &str) {
- builder.ensure(RemoteTestServer {
- stage: builder.top_stage,
- target,
+ fn make_run(run: RunConfig) {
+ run.builder.ensure(RemoteTestServer {
+ compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
+ target: run.target,
});
}
fn run(self, builder: &Builder) -> PathBuf {
builder.ensure(ToolBuild {
- stage: self.stage,
+ compiler: self.compiler,
target: self.target,
tool: "remote-test-server",
mode: Mode::Libstd,
}
}
-// rules.build("tool-cargo", "src/tools/cargo")
-// .host(true)
-// .default(build.config.extended)
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .dep(|s| s.stage(0).host(s.target).name("openssl"))
-// .dep(move |s| {
-// // Cargo depends on procedural macros, which requires a full host
-// // compiler to be available, so we need to depend on that.
-// s.name("librustc-link")
-// .target(&build.build)
-// .host(&build.build)
-// })
-// .run(move |s| compile::tool(build, s.stage, s.target, "cargo"));
-#[derive(Serialize)]
-pub struct Cargo<'a> {
- pub stage: u32,
- pub target: &'a str,
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct Rustdoc {
+ pub host: Interned<String>,
}
-impl<'a> Step<'a> for Cargo<'a> {
- type Id = Cargo<'static>;
+impl Step for Rustdoc {
type Output = PathBuf;
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;
- fn should_run(_builder: &Builder, path: &Path) -> bool {
- path.ends_with("src/tools/cargo")
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ run.path("src/tools/rustdoc")
}
- fn make_run(builder: &Builder, path: Option<&Path>, _host: &str, target: &str) {
- if path.is_none() && !builder.build.config.extended {
- return;
+ fn make_run(run: RunConfig) {
+ run.builder.ensure(Rustdoc {
+ host: run.host,
+ });
+ }
+
+ fn run(self, builder: &Builder) -> PathBuf {
+ let build = builder.build;
+ let target_compiler = builder.compiler(builder.top_stage, self.host);
+ let target = target_compiler.host;
+ let build_compiler = if target_compiler.stage == 0 {
+ builder.compiler(0, builder.build.build)
+ } else if target_compiler.stage >= 2 {
+ // Past stage 2, we consider the compiler to be ABI-compatible and hence capable of
+ // building rustdoc itself.
+ target_compiler
+ } else {
+ // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
+ // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
+ // compilers, which isn't what we want.
+ builder.compiler(target_compiler.stage - 1, builder.build.build)
+ };
+
+ builder.ensure(compile::Rustc { compiler: build_compiler, target });
+
+ let _folder = build.fold_output(|| format!("stage{}-rustdoc", target_compiler.stage));
+ println!("Building rustdoc for stage{} ({})", target_compiler.stage, target_compiler.host);
+
+ let mut cargo = prepare_tool_cargo(builder, build_compiler, target, "rustdoc");
+ build.run(&mut cargo);
+ let tool_rustdoc = build.cargo_out(build_compiler, Mode::Tool, target)
+ .join(exe("rustdoc", &target_compiler.host));
+
+ // don't create a stage0-sysroot/bin directory.
+ if target_compiler.stage > 0 {
+ let sysroot = builder.sysroot(target_compiler);
+ let bindir = sysroot.join("bin");
+ t!(fs::create_dir_all(&bindir));
+ let bin_rustdoc = bindir.join(exe("rustdoc", &*target_compiler.host));
+ let _ = fs::remove_file(&bin_rustdoc);
+ copy(&tool_rustdoc, &bin_rustdoc);
+ bin_rustdoc
+ } else {
+ tool_rustdoc
}
- builder.ensure(Cargo {
- stage: builder.top_stage,
- target,
+ }
+}
+
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct Cargo {
+ pub compiler: Compiler,
+ pub target: Interned<String>,
+}
+
+impl Step for Cargo {
+ type Output = PathBuf;
+ const DEFAULT: bool = true;
+ const ONLY_HOSTS: bool = true;
+
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ let builder = run.builder;
+ run.path("src/tools/cargo").default_condition(builder.build.config.extended)
+ }
+
+ fn make_run(run: RunConfig) {
+ run.builder.ensure(Cargo {
+ compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
+ target: run.target,
});
}
});
// Cargo depends on procedural macros, which requires a full host
// compiler to be available, so we need to depend on that.
- builder.ensure(Rustc {
- compiler: builder.compiler(builder.top_stage, &builder.build.build),
- target: &builder.build.build,
+ builder.ensure(compile::Rustc {
+ compiler: self.compiler,
+ target: builder.build.build,
});
builder.ensure(ToolBuild {
- stage: self.stage,
+ compiler: self.compiler,
target: self.target,
tool: "cargo",
- mode: Mode::Libstd,
+ mode: Mode::Librustc,
})
}
}
-// rules.build("tool-rls", "src/tools/rls")
-// .host(true)
-// .default(build.config.extended)
-// .dep(|s| s.name("librustc-tool"))
-// .dep(|s| s.stage(0).host(s.target).name("openssl"))
-// .dep(move |s| {
-// // rls, like cargo, uses procedural macros
-// s.name("librustc-link")
-// .target(&build.build)
-// .host(&build.build)
-// })
-// .run(move |s| compile::tool(build, s.stage, s.target, "rls"));
-//
-#[derive(Serialize)]
-pub struct Rls<'a> {
- pub stage: u32,
- pub target: &'a str,
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct Rls {
+ pub compiler: Compiler,
+ pub target: Interned<String>,
}
-impl<'a> Step<'a> for Rls<'a> {
- type Id = Rls<'static>;
+impl Step for Rls {
type Output = PathBuf;
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;
- fn should_run(_builder: &Builder, path: &Path) -> bool {
- path.ends_with("src/tools/rls")
+ fn should_run(run: ShouldRun) -> ShouldRun {
+ let builder = run.builder;
+ run.path("src/tools/rls").default_condition(builder.build.config.extended)
}
- fn make_run(builder: &Builder, path: Option<&Path>, _host: &str, target: &str) {
- if path.is_none() && !builder.build.config.extended {
- return;
- }
- builder.ensure(Cargo {
- stage: builder.top_stage,
- target,
+ fn make_run(run: RunConfig) {
+ run.builder.ensure(Rls {
+ compiler: run.builder.compiler(run.builder.top_stage, run.builder.build.build),
+ target: run.target,
});
}
});
// RLS depends on procedural macros, which requires a full host
// compiler to be available, so we need to depend on that.
- builder.ensure(Rustc {
- compiler: builder.compiler(builder.top_stage, &builder.build.build),
- target: &builder.build.build,
+ builder.ensure(compile::Rustc {
+ compiler: self.compiler,
+ target: builder.build.build,
});
builder.ensure(ToolBuild {
- stage: self.stage,
+ compiler: self.compiler,
target: self.target,
tool: "rls",
mode: Mode::Librustc,
/// `host`.
pub fn tool_cmd(&self, tool: Tool) -> Command {
let mut cmd = Command::new(self.tool_exe(tool));
- let compiler = self.compiler(0, &self.build.build);
+ let compiler = self.compiler(0, self.build.build);
self.prepare_tool_cmd(compiler, &mut cmd);
cmd
}
/// 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) {
- let host = compiler.host;
- let mut paths = vec![
- self.sysroot_libdir(compiler, compiler.host),
- self.cargo_out(compiler, Mode::Tool, host).join("deps"),
+ 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"),
];
// On MSVC a tool may invoke a C compiler (e.g. compiletest in run-make
if compiler.host.contains("msvc") {
let curpaths = env::var_os("PATH").unwrap_or_default();
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
- for &(ref k, ref v) in self.cc[compiler.host].0.env() {
+ for &(ref k, ref v) in self.cc[&compiler.host].0.env() {
if k != "PATH" {
continue
}