2017-07-22 20:01:58 -06:00
|
|
|
use std::fs;
|
2017-07-04 19:41:43 -06:00
|
|
|
use std::env;
|
2018-05-04 03:20:29 -07:00
|
|
|
use std::iter;
|
2017-07-20 17:51:07 -06:00
|
|
|
use std::path::PathBuf;
|
2017-11-20 01:40:02 +08:00
|
|
|
use std::process::{Command, exit};
|
2018-07-05 19:02:43 +02:00
|
|
|
use std::collections::HashSet;
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2018-12-07 13:21:05 +01:00
|
|
|
use crate::Mode;
|
|
|
|
use crate::Compiler;
|
|
|
|
use crate::builder::{Step, RunConfig, ShouldRun, Builder};
|
|
|
|
use crate::util::{exe, add_lib_path};
|
|
|
|
use crate::compile;
|
|
|
|
use crate::native;
|
|
|
|
use crate::channel::GitInfo;
|
|
|
|
use crate::channel;
|
|
|
|
use crate::cache::Interned;
|
|
|
|
use crate::toolstate::ToolState;
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2018-07-26 12:36:58 +09:00
|
|
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub enum SourceType {
|
|
|
|
InTree,
|
|
|
|
Submodule,
|
|
|
|
}
|
|
|
|
|
2018-02-09 18:53:41 +01:00
|
|
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
2017-07-22 19:29:08 -06:00
|
|
|
struct ToolBuild {
|
|
|
|
compiler: Compiler,
|
|
|
|
target: Interned<String>,
|
|
|
|
tool: &'static str,
|
2017-09-01 20:46:51 -07:00
|
|
|
path: &'static str,
|
2017-07-22 19:29:08 -06:00
|
|
|
mode: Mode,
|
2018-07-23 13:08:05 +09:00
|
|
|
is_optional_tool: bool,
|
2018-07-26 12:36:58 +09:00
|
|
|
source_type: SourceType,
|
2018-02-09 18:53:41 +01:00
|
|
|
extra_features: Vec<String>,
|
2017-07-04 19:41:43 -06:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
impl Step for ToolBuild {
|
2017-10-19 17:30:37 -06:00
|
|
|
type Output = Option<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-10-19 17:30:37 -06:00
|
|
|
fn run(self, builder: &Builder) -> Option<PathBuf> {
|
2017-07-22 19:29:08 -06:00
|
|
|
let compiler = self.compiler;
|
2017-07-04 19:41:43 -06:00
|
|
|
let target = self.target;
|
|
|
|
let tool = self.tool;
|
2017-09-01 20:46:51 -07:00
|
|
|
let path = self.path;
|
2018-07-23 13:08:05 +09:00
|
|
|
let is_optional_tool = self.is_optional_tool;
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-07-05 06:41:27 -06:00
|
|
|
match self.mode {
|
2018-06-29 14:35:10 -07:00
|
|
|
Mode::ToolRustc => {
|
|
|
|
builder.ensure(compile::Rustc { compiler, target })
|
|
|
|
}
|
2018-07-02 09:33:16 -07:00
|
|
|
Mode::ToolStd => {
|
|
|
|
builder.ensure(compile::Std { compiler, target })
|
|
|
|
}
|
2018-06-29 14:35:10 -07:00
|
|
|
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
|
2018-05-19 23:04:41 +03:00
|
|
|
_ => panic!("unexpected Mode for tool build")
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2018-07-13 14:12:58 +09:00
|
|
|
let mut cargo = prepare_tool_cargo(
|
|
|
|
builder,
|
|
|
|
compiler,
|
|
|
|
self.mode,
|
|
|
|
target,
|
|
|
|
"build",
|
|
|
|
path,
|
2018-07-26 12:36:58 +09:00
|
|
|
self.source_type,
|
2018-10-08 10:39:09 -07:00
|
|
|
&self.extra_features,
|
2018-07-13 14:12:58 +09:00
|
|
|
);
|
2018-03-16 08:35:03 -07:00
|
|
|
|
2018-04-14 17:27:57 -06:00
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-{}", compiler.stage, tool));
|
|
|
|
builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target));
|
2018-03-15 10:58:02 -07:00
|
|
|
let mut duplicates = Vec::new();
|
2018-12-17 21:10:59 -08:00
|
|
|
let is_expected = compile::stream_cargo(builder, &mut cargo, &mut |msg| {
|
2018-03-15 10:58:02 -07:00
|
|
|
// Only care about big things like the RLS/Cargo for now
|
2018-07-05 18:48:56 +02:00
|
|
|
match tool {
|
|
|
|
| "rls"
|
|
|
|
| "cargo"
|
|
|
|
| "clippy-driver"
|
|
|
|
=> {}
|
|
|
|
|
|
|
|
_ => return,
|
2018-03-15 10:58:02 -07:00
|
|
|
}
|
|
|
|
let (id, features, filenames) = match msg {
|
|
|
|
compile::CargoMessage::CompilerArtifact {
|
|
|
|
package_id,
|
|
|
|
features,
|
|
|
|
filenames
|
|
|
|
} => {
|
|
|
|
(package_id, features, filenames)
|
|
|
|
}
|
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
let features = features.iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
for path in filenames {
|
|
|
|
let val = (tool, PathBuf::from(&*path), features.clone());
|
|
|
|
// we're only interested in deduplicating rlibs for now
|
|
|
|
if val.1.extension().and_then(|s| s.to_str()) != Some("rlib") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't worry about libs that turn out to be host dependencies
|
|
|
|
// or build scripts, we only care about target dependencies that
|
|
|
|
// are in `deps`.
|
|
|
|
if let Some(maybe_target) = val.1
|
|
|
|
.parent() // chop off file name
|
|
|
|
.and_then(|p| p.parent()) // chop off `deps`
|
|
|
|
.and_then(|p| p.parent()) // chop off `release`
|
|
|
|
.and_then(|p| p.file_name())
|
|
|
|
.and_then(|p| p.to_str())
|
|
|
|
{
|
|
|
|
if maybe_target != &*target {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 17:27:57 -06:00
|
|
|
let mut artifacts = builder.tool_artifacts.borrow_mut();
|
2018-03-15 10:58:02 -07:00
|
|
|
let prev_artifacts = artifacts
|
|
|
|
.entry(target)
|
2018-07-21 22:43:31 +03:00
|
|
|
.or_default();
|
2018-03-15 10:58:02 -07:00
|
|
|
if let Some(prev) = prev_artifacts.get(&*id) {
|
|
|
|
if prev.1 != val.1 {
|
|
|
|
duplicates.push((
|
|
|
|
id.to_string(),
|
|
|
|
val,
|
|
|
|
prev.clone(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
prev_artifacts.insert(id.to_string(), val);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-26 16:23:02 +02:00
|
|
|
if is_expected && !duplicates.is_empty() {
|
2018-12-17 10:23:04 -08:00
|
|
|
println!("duplicate artifacts found when compiling a tool, this \
|
2018-03-15 10:58:02 -07:00
|
|
|
typically means that something was recompiled because \
|
|
|
|
a transitive dependency has different features activated \
|
|
|
|
than in a previous build:\n");
|
2018-07-05 19:02:43 +02:00
|
|
|
println!("the following dependencies are duplicated although they \
|
|
|
|
have the same features enabled:");
|
2018-07-05 19:30:06 +02:00
|
|
|
for (id, cur, prev) in duplicates.drain_filter(|(_, cur, prev)| cur.2 == prev.2) {
|
2018-07-05 19:02:43 +02:00
|
|
|
println!(" {}", id);
|
2018-07-05 19:30:06 +02:00
|
|
|
// same features
|
|
|
|
println!(" `{}` ({:?})\n `{}` ({:?})", cur.0, cur.1, prev.0, prev.1);
|
2018-07-05 19:02:43 +02:00
|
|
|
}
|
|
|
|
println!("the following dependencies have different features:");
|
2018-03-15 10:58:02 -07:00
|
|
|
for (id, cur, prev) in duplicates {
|
|
|
|
println!(" {}", id);
|
2018-07-05 19:02:43 +02:00
|
|
|
let cur_features: HashSet<_> = cur.2.into_iter().collect();
|
|
|
|
let prev_features: HashSet<_> = prev.2.into_iter().collect();
|
|
|
|
println!(" `{}` additionally enabled features {:?} at {:?}",
|
2018-07-05 19:30:06 +02:00
|
|
|
cur.0, &cur_features - &prev_features, cur.1);
|
2018-07-05 19:02:43 +02:00
|
|
|
println!(" `{}` additionally enabled features {:?} at {:?}",
|
2018-07-05 19:30:06 +02:00
|
|
|
prev.0, &prev_features - &cur_features, prev.1);
|
2018-03-15 10:58:02 -07:00
|
|
|
}
|
2018-10-26 16:23:02 +02:00
|
|
|
println!();
|
2018-07-31 14:16:55 -07:00
|
|
|
println!("to fix this you will probably want to edit the local \
|
|
|
|
src/tools/rustc-workspace-hack/Cargo.toml crate, as \
|
|
|
|
that will update the dependency graph to ensure that \
|
|
|
|
these crates all share the same feature set");
|
2018-03-15 10:58:02 -07:00
|
|
|
panic!("tools should not compile multiple copies of the same crate");
|
|
|
|
}
|
|
|
|
|
2018-04-14 17:27:57 -06:00
|
|
|
builder.save_toolstate(tool, if is_expected {
|
2017-12-22 01:16:21 +08:00
|
|
|
ToolState::TestFail
|
2017-11-30 18:18:47 +08:00
|
|
|
} else {
|
2017-12-22 01:16:21 +08:00
|
|
|
ToolState::BuildFail
|
2017-11-30 18:18:47 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if !is_expected {
|
2018-07-23 13:08:05 +09:00
|
|
|
if !is_optional_tool {
|
2018-03-15 17:29:53 -06:00
|
|
|
exit(1);
|
2017-11-20 01:40:02 +08:00
|
|
|
} else {
|
2018-10-26 16:23:02 +02:00
|
|
|
None
|
2017-11-20 01:40:02 +08:00
|
|
|
}
|
2017-12-07 05:06:48 +08:00
|
|
|
} else {
|
2018-05-28 01:09:43 +03:00
|
|
|
let cargo_out = builder.cargo_out(compiler, self.mode, target)
|
2017-10-19 17:30:37 -06:00
|
|
|
.join(exe(tool, &compiler.host));
|
2018-04-14 17:27:57 -06:00
|
|
|
let bin = builder.tools_dir(compiler).join(exe(tool, &compiler.host));
|
|
|
|
builder.copy(&cargo_out, &bin);
|
2017-10-19 17:30:37 -06:00
|
|
|
Some(bin)
|
|
|
|
}
|
2017-08-03 16:06:20 -06:00
|
|
|
}
|
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-09-15 15:28:59 -07:00
|
|
|
pub fn prepare_tool_cargo(
|
2017-08-03 16:06:20 -06:00
|
|
|
builder: &Builder,
|
|
|
|
compiler: Compiler,
|
2018-05-28 01:09:43 +03:00
|
|
|
mode: Mode,
|
2017-08-03 16:06:20 -06:00
|
|
|
target: Interned<String>,
|
2017-09-15 15:28:59 -07:00
|
|
|
command: &'static str,
|
2017-09-01 20:46:51 -07:00
|
|
|
path: &'static str,
|
2018-07-26 12:36:58 +09:00
|
|
|
source_type: SourceType,
|
2018-10-08 10:39:09 -07:00
|
|
|
extra_features: &[String],
|
2017-08-03 16:06:20 -06:00
|
|
|
) -> Command {
|
2018-05-28 01:09:43 +03:00
|
|
|
let mut cargo = builder.cargo(compiler, mode, target, command);
|
2018-04-14 17:27:57 -06:00
|
|
|
let dir = builder.src.join(path);
|
2017-08-03 16:06:20 -06:00
|
|
|
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");
|
|
|
|
|
2018-07-26 12:36:58 +09:00
|
|
|
if source_type == SourceType::Submodule {
|
2018-07-23 13:08:05 +09:00
|
|
|
cargo.env("RUSTC_EXTERNAL_TOOL", "1");
|
2018-07-13 14:12:58 +09:00
|
|
|
}
|
|
|
|
|
2018-10-08 10:39:09 -07:00
|
|
|
let mut features = extra_features.iter().cloned().collect::<Vec<_>>();
|
|
|
|
if builder.build.config.cargo_native_static {
|
|
|
|
if path.ends_with("cargo") ||
|
|
|
|
path.ends_with("rls") ||
|
|
|
|
path.ends_with("clippy") ||
|
|
|
|
path.ends_with("rustfmt")
|
|
|
|
{
|
|
|
|
cargo.env("LIBZ_SYS_STATIC", "1");
|
|
|
|
features.push("rustc-workspace-hack/all-static".to_string());
|
|
|
|
}
|
2017-08-03 16:06:20 -06:00
|
|
|
}
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2017-09-22 21:34:27 -07:00
|
|
|
// if tools are using lzma we want to force the build script to build its
|
|
|
|
// own copy
|
|
|
|
cargo.env("LZMA_API_STATIC", "1");
|
|
|
|
|
2018-04-14 17:27:57 -06:00
|
|
|
cargo.env("CFG_RELEASE_CHANNEL", &builder.config.channel);
|
|
|
|
cargo.env("CFG_VERSION", builder.rust_version());
|
2018-11-21 14:27:30 +01:00
|
|
|
cargo.env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM);
|
2017-07-04 19:41:43 -06:00
|
|
|
|
2018-04-14 17:27:57 -06:00
|
|
|
let info = GitInfo::new(&builder.config, &dir);
|
2017-08-03 16:06:20 -06:00
|
|
|
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);
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
2018-10-26 16:23:02 +02:00
|
|
|
if !features.is_empty() {
|
2018-10-08 10:39:09 -07:00
|
|
|
cargo.arg("--features").arg(&features.join(", "));
|
|
|
|
}
|
2017-08-03 16:06:20 -06:00
|
|
|
cargo
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! tool {
|
2018-08-22 05:50:46 +03:00
|
|
|
($(
|
|
|
|
$name:ident, $path:expr, $tool_name:expr, $mode:expr
|
|
|
|
$(,llvm_tools = $llvm:expr)*
|
|
|
|
$(,is_external_tool = $external:expr)*
|
|
|
|
;
|
|
|
|
)+) => {
|
2018-07-21 15:19:39 -06:00
|
|
|
#[derive(Copy, PartialEq, Eq, Clone)]
|
2017-07-05 06:41:27 -06:00
|
|
|
pub enum Tool {
|
|
|
|
$(
|
|
|
|
$name,
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:09:43 +03:00
|
|
|
impl Tool {
|
|
|
|
pub fn get_mode(&self) -> Mode {
|
|
|
|
let mode = match self {
|
|
|
|
$(Tool::$name => $mode,)+
|
|
|
|
};
|
|
|
|
mode
|
|
|
|
}
|
2018-06-09 15:48:44 +08:00
|
|
|
|
|
|
|
/// Whether this tool requires LLVM to run
|
|
|
|
pub fn uses_llvm_tools(&self) -> bool {
|
|
|
|
match self {
|
2018-06-22 19:42:22 -06:00
|
|
|
$(Tool::$name => false $(|| $llvm)*,)+
|
2018-06-09 15:48:44 +08:00
|
|
|
}
|
|
|
|
}
|
2018-05-28 01:09:43 +03:00
|
|
|
}
|
|
|
|
|
2017-07-05 06:41:27 -06:00
|
|
|
impl<'a> Builder<'a> {
|
|
|
|
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
|
2017-09-15 09:34:17 -07:00
|
|
|
let stage = self.tool_default_stage(tool);
|
2017-07-05 06:41:27 -06:00
|
|
|
match tool {
|
|
|
|
$(Tool::$name =>
|
|
|
|
self.ensure($name {
|
2018-04-14 17:27:57 -06:00
|
|
|
compiler: self.compiler(stage, self.config.build),
|
|
|
|
target: self.config.build,
|
2017-07-05 06:41:27 -06:00
|
|
|
}),
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
2017-09-15 09:34:17 -07:00
|
|
|
|
|
|
|
pub fn tool_default_stage(&self, tool: Tool) -> u32 {
|
2017-10-21 16:47:18 +01:00
|
|
|
// Compile the error-index in the same stage as rustdoc to avoid
|
|
|
|
// recompiling rustdoc twice if we can. Otherwise compile
|
|
|
|
// everything else in stage0 as there's no need to rebootstrap
|
|
|
|
// everything.
|
2017-09-15 09:34:17 -07:00
|
|
|
match tool {
|
2017-10-21 16:47:18 +01:00
|
|
|
Tool::ErrorIndex if self.top_stage >= 2 => self.top_stage,
|
2017-09-15 09:34:17 -07:00
|
|
|
_ => 0,
|
|
|
|
}
|
|
|
|
}
|
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-22 19:29:08 -06:00
|
|
|
pub compiler: Compiler,
|
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-20 17:51:07 -06:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure($name {
|
2018-04-14 17:27:57 -06:00
|
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
2017-07-20 17:51:07 -06:00
|
|
|
target: run.target,
|
2017-07-05 06:41:27 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
builder.ensure(ToolBuild {
|
2017-07-22 19:29:08 -06:00
|
|
|
compiler: self.compiler,
|
2017-07-05 06:41:27 -06:00
|
|
|
target: self.target,
|
|
|
|
tool: $tool_name,
|
|
|
|
mode: $mode,
|
2017-09-01 20:46:51 -07:00
|
|
|
path: $path,
|
2018-07-23 13:08:05 +09:00
|
|
|
is_optional_tool: false,
|
2018-07-26 12:36:58 +09:00
|
|
|
source_type: if false $(|| $external)* {
|
|
|
|
SourceType::Submodule
|
|
|
|
} else {
|
|
|
|
SourceType::InTree
|
|
|
|
},
|
2018-02-09 18:53:41 +01:00
|
|
|
extra_features: Vec::new(),
|
2017-12-07 05:06:48 +08:00
|
|
|
}).expect("expected to build -- essential tool")
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tool!(
|
2018-06-29 14:35:10 -07:00
|
|
|
Rustbook, "src/tools/rustbook", "rustbook", Mode::ToolBootstrap;
|
2018-05-19 23:04:41 +03:00
|
|
|
ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::ToolRustc;
|
2018-06-29 14:35:10 -07:00
|
|
|
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolBootstrap;
|
|
|
|
Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
|
|
|
|
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolBootstrap;
|
2018-11-24 09:31:01 +02:00
|
|
|
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap;
|
|
|
|
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true;
|
2018-06-29 14:35:10 -07:00
|
|
|
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
|
|
|
|
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
|
2018-07-23 13:08:05 +09:00
|
|
|
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap,
|
2018-07-26 12:36:58 +09:00
|
|
|
is_external_tool = true;
|
2018-06-29 14:35:10 -07:00
|
|
|
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolBootstrap;
|
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 RemoteTestServer {
|
2017-07-22 19:29:08 -06:00
|
|
|
pub compiler: Compiler,
|
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-20 17:51:07 -06:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(RemoteTestServer {
|
2018-04-14 17:27:57 -06:00
|
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
2017-07-20 17:51:07 -06:00
|
|
|
target: run.target,
|
2017-07-12 10:12:47 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
builder.ensure(ToolBuild {
|
2017-07-22 19:29:08 -06:00
|
|
|
compiler: self.compiler,
|
2017-07-12 10:12:47 -06:00
|
|
|
target: self.target,
|
|
|
|
tool: "remote-test-server",
|
2018-07-02 09:33:16 -07:00
|
|
|
mode: Mode::ToolStd,
|
2017-09-01 20:46:51 -07:00
|
|
|
path: "src/tools/remote-test-server",
|
2018-07-23 13:08:05 +09:00
|
|
|
is_optional_tool: false,
|
2018-07-26 12:36:58 +09:00
|
|
|
source_type: SourceType::InTree,
|
2018-02-09 18:53:41 +01:00
|
|
|
extra_features: Vec::new(),
|
2017-12-07 05:06:48 +08:00
|
|
|
}).expect("expected to build -- essential tool")
|
2017-07-12 10:12:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 20:01:58 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Rustdoc {
|
2017-08-04 16:13:01 -06:00
|
|
|
pub host: Interned<String>,
|
2017-07-22 20:01:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for Rustdoc {
|
|
|
|
type Output = PathBuf;
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.path("src/tools/rustdoc")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Rustdoc {
|
2017-08-04 16:13:01 -06:00
|
|
|
host: run.host,
|
2017-07-22 20:01:58 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
2017-08-04 16:13:01 -06:00
|
|
|
let target_compiler = builder.compiler(builder.top_stage, self.host);
|
2017-08-03 16:06:20 -06:00
|
|
|
let target = target_compiler.host;
|
2017-07-22 20:01:58 -06:00
|
|
|
let build_compiler = if target_compiler.stage == 0 {
|
2018-04-14 17:27:57 -06:00
|
|
|
builder.compiler(0, builder.config.build)
|
2017-08-03 19:08:20 -06:00
|
|
|
} else if target_compiler.stage >= 2 {
|
|
|
|
// Past stage 2, we consider the compiler to be ABI-compatible and hence capable of
|
|
|
|
// building rustdoc itself.
|
2018-04-14 17:27:57 -06:00
|
|
|
builder.compiler(target_compiler.stage, builder.config.build)
|
2017-07-22 20:01:58 -06:00
|
|
|
} else {
|
2017-07-25 18:04:33 -06:00
|
|
|
// 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.
|
2018-04-14 17:27:57 -06:00
|
|
|
builder.compiler(target_compiler.stage - 1, builder.config.build)
|
2017-07-22 20:01:58 -06:00
|
|
|
};
|
|
|
|
|
2017-08-03 16:06:20 -06:00
|
|
|
builder.ensure(compile::Rustc { compiler: build_compiler, target });
|
2018-03-19 10:58:30 -07:00
|
|
|
builder.ensure(compile::Rustc {
|
|
|
|
compiler: build_compiler,
|
2018-04-14 17:27:57 -06:00
|
|
|
target: builder.config.build,
|
2018-03-19 10:58:30 -07:00
|
|
|
});
|
2017-08-03 16:06:20 -06:00
|
|
|
|
2018-07-13 14:12:58 +09:00
|
|
|
let mut cargo = prepare_tool_cargo(
|
|
|
|
builder,
|
|
|
|
build_compiler,
|
|
|
|
Mode::ToolRustc,
|
|
|
|
target,
|
|
|
|
"build",
|
|
|
|
"src/tools/rustdoc",
|
2018-07-26 12:36:58 +09:00
|
|
|
SourceType::InTree,
|
2018-10-08 10:39:09 -07:00
|
|
|
&[],
|
2018-07-13 14:12:58 +09:00
|
|
|
);
|
2017-09-24 08:50:27 -06:00
|
|
|
|
|
|
|
// Most tools don't get debuginfo, but rustdoc should.
|
|
|
|
cargo.env("RUSTC_DEBUGINFO", builder.config.rust_debuginfo.to_string())
|
|
|
|
.env("RUSTC_DEBUGINFO_LINES", builder.config.rust_debuginfo_lines.to_string());
|
|
|
|
|
2018-04-14 17:27:57 -06:00
|
|
|
let _folder = builder.fold_output(|| format!("stage{}-rustdoc", target_compiler.stage));
|
|
|
|
builder.info(&format!("Building rustdoc for stage{} ({})",
|
2018-03-28 17:25:09 +02:00
|
|
|
target_compiler.stage, target_compiler.host));
|
2018-04-14 17:27:57 -06:00
|
|
|
builder.run(&mut cargo);
|
2018-03-16 08:35:03 -07:00
|
|
|
|
2017-08-13 05:07:01 +05:00
|
|
|
// Cargo adds a number of paths to the dylib search path on windows, which results in
|
|
|
|
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
|
|
|
|
// rustdoc a different name.
|
2018-05-19 23:04:41 +03:00
|
|
|
let tool_rustdoc = builder.cargo_out(build_compiler, Mode::ToolRustc, target)
|
2018-05-11 20:51:05 -06:00
|
|
|
.join(exe("rustdoc_tool_binary", &target_compiler.host));
|
2017-07-22 20:01:58 -06:00
|
|
|
|
|
|
|
// 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);
|
2018-04-14 17:27:57 -06:00
|
|
|
builder.copy(&tool_rustdoc, &bin_rustdoc);
|
2017-07-22 20:01:58 -06:00
|
|
|
bin_rustdoc
|
|
|
|
} else {
|
|
|
|
tool_rustdoc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 18:48:44 -06:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Cargo {
|
2017-07-22 19:29:08 -06:00
|
|
|
pub compiler: Compiler,
|
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;
|
2018-04-14 17:27:57 -06:00
|
|
|
run.path("src/tools/cargo").default_condition(builder.config.extended)
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
|
2017-07-20 17:51:07 -06:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Cargo {
|
2018-04-14 17:27:57 -06:00
|
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
2017-07-20 17:51:07 -06:00
|
|
|
target: run.target,
|
2017-07-05 06:41:27 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) -> PathBuf {
|
|
|
|
// 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 {
|
2017-07-22 19:29:08 -06:00
|
|
|
compiler: self.compiler,
|
2018-04-14 17:27:57 -06:00
|
|
|
target: builder.config.build,
|
2017-07-05 06:41:27 -06:00
|
|
|
});
|
|
|
|
builder.ensure(ToolBuild {
|
2017-07-22 19:29:08 -06:00
|
|
|
compiler: self.compiler,
|
2017-07-05 06:41:27 -06:00
|
|
|
target: self.target,
|
|
|
|
tool: "cargo",
|
2018-05-19 23:04:41 +03:00
|
|
|
mode: Mode::ToolRustc,
|
2017-09-01 20:46:51 -07:00
|
|
|
path: "src/tools/cargo",
|
2018-07-23 13:08:05 +09:00
|
|
|
is_optional_tool: false,
|
2018-07-26 12:36:58 +09:00
|
|
|
source_type: SourceType::Submodule,
|
2018-02-09 18:53:41 +01:00
|
|
|
extra_features: Vec::new(),
|
2017-12-07 05:06:48 +08:00
|
|
|
}).expect("expected to build -- essential tool")
|
2017-07-05 06:41:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:17:39 +01:00
|
|
|
macro_rules! tool_extended {
|
|
|
|
(($sel:ident, $builder:ident),
|
|
|
|
$($name:ident,
|
|
|
|
$toolstate:ident,
|
|
|
|
$path:expr,
|
|
|
|
$tool_name:expr,
|
|
|
|
$extra_deps:block;)+) => {
|
|
|
|
$(
|
2018-02-09 18:53:41 +01:00
|
|
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
2017-11-15 11:17:39 +01:00
|
|
|
pub struct $name {
|
|
|
|
pub compiler: Compiler,
|
|
|
|
pub target: Interned<String>,
|
2018-02-09 18:53:41 +01:00
|
|
|
pub extra_features: Vec<String>,
|
2017-11-15 11:17:39 +01:00
|
|
|
}
|
2017-08-15 14:27:20 +02:00
|
|
|
|
2017-11-15 11:17:39 +01:00
|
|
|
impl Step for $name {
|
|
|
|
type Output = Option<PathBuf>;
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
2017-08-15 14:27:20 +02:00
|
|
|
|
2017-11-15 11:17:39 +01:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
let builder = run.builder;
|
2018-04-14 17:27:57 -06:00
|
|
|
run.path($path).default_condition(builder.config.extended)
|
2017-11-15 11:17:39 +01:00
|
|
|
}
|
2017-08-15 14:27:20 +02:00
|
|
|
|
2017-11-15 11:17:39 +01:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure($name {
|
2018-04-14 17:27:57 -06:00
|
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
2017-11-15 11:17:39 +01:00
|
|
|
target: run.target,
|
2018-02-09 18:53:41 +01:00
|
|
|
extra_features: Vec::new(),
|
2017-11-15 11:17:39 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-09 18:53:41 +01:00
|
|
|
#[allow(unused_mut)]
|
|
|
|
fn run(mut $sel, $builder: &Builder) -> Option<PathBuf> {
|
2017-11-15 11:17:39 +01:00
|
|
|
$extra_deps
|
|
|
|
$builder.ensure(ToolBuild {
|
|
|
|
compiler: $sel.compiler,
|
|
|
|
target: $sel.target,
|
|
|
|
tool: $tool_name,
|
2018-05-19 23:04:41 +03:00
|
|
|
mode: Mode::ToolRustc,
|
2017-11-15 11:17:39 +01:00
|
|
|
path: $path,
|
2018-02-09 18:53:41 +01:00
|
|
|
extra_features: $sel.extra_features,
|
2018-07-23 13:08:05 +09:00
|
|
|
is_optional_tool: true,
|
2018-07-26 12:36:58 +09:00
|
|
|
source_type: SourceType::Submodule,
|
2017-11-15 11:17:39 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
2017-08-15 14:27:20 +02:00
|
|
|
}
|
2017-11-15 11:17:39 +01:00
|
|
|
}
|
2017-08-15 14:27:20 +02:00
|
|
|
|
2017-11-15 11:17:39 +01:00
|
|
|
tool_extended!((self, builder),
|
2017-11-15 11:21:21 +01:00
|
|
|
Cargofmt, rustfmt, "src/tools/rustfmt", "cargo-fmt", {};
|
2018-07-09 10:15:30 +02:00
|
|
|
CargoClippy, clippy, "src/tools/clippy", "cargo-clippy", {
|
|
|
|
// Clippy depends on procedural macros (serde), which requires a full host
|
|
|
|
// compiler to be available, so we need to depend on that.
|
|
|
|
builder.ensure(compile::Rustc {
|
|
|
|
compiler: self.compiler,
|
|
|
|
target: builder.config.build,
|
|
|
|
});
|
|
|
|
};
|
2017-11-15 11:17:39 +01:00
|
|
|
Clippy, clippy, "src/tools/clippy", "clippy-driver", {
|
2017-08-15 14:27:20 +02:00
|
|
|
// Clippy depends on procedural macros (serde), which requires a full host
|
|
|
|
// compiler to be available, so we need to depend on that.
|
|
|
|
builder.ensure(compile::Rustc {
|
|
|
|
compiler: self.compiler,
|
2018-04-14 17:27:57 -06:00
|
|
|
target: builder.config.build,
|
2017-08-15 14:27:20 +02:00
|
|
|
});
|
2017-11-15 11:17:39 +01:00
|
|
|
};
|
|
|
|
Miri, miri, "src/tools/miri", "miri", {};
|
|
|
|
Rls, rls, "src/tools/rls", "rls", {
|
2018-07-09 10:04:28 +02:00
|
|
|
let clippy = builder.ensure(Clippy {
|
|
|
|
compiler: self.compiler,
|
|
|
|
target: self.target,
|
|
|
|
extra_features: Vec::new(),
|
|
|
|
});
|
2018-07-11 10:35:09 +02:00
|
|
|
if clippy.is_some() {
|
2018-07-09 10:04:28 +02:00
|
|
|
self.extra_features.push("clippy".to_owned());
|
|
|
|
}
|
2017-07-05 06:41:27 -06:00
|
|
|
// 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 {
|
2017-07-22 19:29:08 -06:00
|
|
|
compiler: self.compiler,
|
2018-04-14 17:27:57 -06:00
|
|
|
target: builder.config.build,
|
2017-07-05 06:41:27 -06:00
|
|
|
});
|
2017-11-15 11:17:39 +01:00
|
|
|
};
|
|
|
|
Rustfmt, rustfmt, "src/tools/rustfmt", "rustfmt", {};
|
|
|
|
);
|
2017-08-28 16:54:50 +02: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));
|
2018-04-14 17:27:57 -06:00
|
|
|
let compiler = self.compiler(self.tool_default_stage(tool), self.config.build);
|
2018-06-09 15:48:44 +08:00
|
|
|
self.prepare_tool_cmd(compiler, tool, &mut cmd);
|
2017-07-05 10:48:02 -06:00
|
|
|
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`.
|
2018-06-09 15:48:44 +08:00
|
|
|
fn prepare_tool_cmd(&self, compiler: Compiler, tool: Tool, cmd: &mut Command) {
|
2017-07-13 18:48:44 -06:00
|
|
|
let host = &compiler.host;
|
2018-05-04 03:20:29 -07:00
|
|
|
let mut lib_paths: Vec<PathBuf> = vec![
|
2018-07-21 15:19:39 -06:00
|
|
|
if compiler.stage == 0 && tool != Tool::ErrorIndex {
|
2018-06-29 14:35:10 -07:00
|
|
|
self.build.rustc_snapshot_libdir()
|
|
|
|
} else {
|
|
|
|
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host))
|
|
|
|
},
|
2018-06-09 15:48:44 +08:00
|
|
|
self.cargo_out(compiler, tool.get_mode(), *host).join("deps"),
|
2017-07-05 10:48:02 -06:00
|
|
|
];
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
// On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
|
2017-07-05 10:48:02 -06:00
|
|
|
// 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-10-10 23:06:22 +03:00
|
|
|
for &(ref k, ref v) in self.cc[&compiler.host].env() {
|
2017-07-05 10:48:02 -06:00
|
|
|
if k != "PATH" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for path in env::split_paths(v) {
|
|
|
|
if !curpaths.contains(&path) {
|
2018-05-04 03:20:29 -07:00
|
|
|
lib_paths.push(path);
|
2017-07-05 10:48:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-04 03:20:29 -07:00
|
|
|
|
|
|
|
// Add the llvm/bin directory to PATH since it contains lots of
|
|
|
|
// useful, platform-independent tools
|
2018-06-09 15:48:44 +08:00
|
|
|
if tool.uses_llvm_tools() {
|
|
|
|
if let Some(llvm_bin_path) = self.llvm_bin_path() {
|
|
|
|
if host.contains("windows") {
|
|
|
|
// On Windows, PATH and the dynamic library path are the same,
|
|
|
|
// so we just add the LLVM bin path to lib_path
|
|
|
|
lib_paths.push(llvm_bin_path);
|
|
|
|
} else {
|
|
|
|
let old_path = env::var_os("PATH").unwrap_or_default();
|
|
|
|
let new_path = env::join_paths(iter::once(llvm_bin_path)
|
|
|
|
.chain(env::split_paths(&old_path)))
|
|
|
|
.expect("Could not add LLVM bin path to PATH");
|
|
|
|
cmd.env("PATH", new_path);
|
|
|
|
}
|
2018-05-04 03:20:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
add_lib_path(lib_paths, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn llvm_bin_path(&self) -> Option<PathBuf> {
|
|
|
|
if self.config.llvm_enabled && !self.config.dry_run {
|
|
|
|
let llvm_config = self.ensure(native::Llvm {
|
|
|
|
target: self.config.build,
|
|
|
|
emscripten: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add the llvm/bin directory to PATH since it contains lots of
|
|
|
|
// useful, platform-independent tools
|
|
|
|
let llvm_bin_path = llvm_config.parent()
|
|
|
|
.expect("Expected llvm-config to be contained in directory");
|
|
|
|
assert!(llvm_bin_path.is_dir());
|
|
|
|
Some(llvm_bin_path.to_path_buf())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2017-07-05 10:48:02 -06:00
|
|
|
}
|
|
|
|
}
|