-use std::fs;
+use std::collections::HashSet;
use std::env;
+use std::fs;
use std::path::PathBuf;
-use std::process::{Command, exit};
-use std::collections::HashSet;
+use std::process::{exit, Command};
use build_helper::t;
-use crate::Mode;
-use crate::Compiler;
-use crate::builder::{Step, RunConfig, ShouldRun, Builder, Cargo as CargoCommand};
-use crate::util::{exe, add_lib_path, CiEnv};
-use crate::compile;
-use crate::channel::GitInfo;
-use crate::channel;
+use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
use crate::cache::Interned;
+use crate::channel;
+use crate::channel::GitInfo;
+use crate::compile;
use crate::toolstate::ToolState;
+use crate::util::{add_lib_path, exe, CiEnv};
+use crate::Compiler;
+use crate::Mode;
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum SourceType {
let is_optional_tool = self.is_optional_tool;
match self.mode {
- Mode::ToolRustc => {
- builder.ensure(compile::Rustc { compiler, target })
- }
- Mode::ToolStd => {
- builder.ensure(compile::Std { compiler, target })
- }
+ Mode::ToolRustc => builder.ensure(compile::Rustc { compiler, target }),
+ Mode::ToolStd => builder.ensure(compile::Std { compiler, target }),
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
- _ => panic!("unexpected Mode for tool build")
+ _ => panic!("unexpected Mode for tool build"),
}
let cargo = prepare_tool_cargo(
let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |msg| {
// Only care about big things like the RLS/Cargo for now
match tool {
- | "rls"
- | "cargo"
- | "clippy-driver"
- | "miri"
- | "rustfmt"
- => {}
+ "rls" | "cargo" | "clippy-driver" | "miri" | "rustfmt" => {}
_ => return,
}
features,
filenames,
target: _,
- } => {
- (package_id, features, filenames)
- }
+ } => (package_id, features, filenames),
_ => return,
};
let features = features.iter().map(|s| s.to_string()).collect::<Vec<_>>();
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
+ continue;
}
// Don't worry about compiles that turn out to be host
// already listed then we need to see if we reused the same
// artifact or produced a duplicate.
let mut artifacts = builder.tool_artifacts.borrow_mut();
- let prev_artifacts = artifacts
- .entry(target)
- .or_default();
+ let prev_artifacts = artifacts.entry(target).or_default();
let prev = match prev_artifacts.get(&*id) {
Some(prev) => prev,
None => {
// ... and otherwise this looks like we duplicated some sort of
// compilation, so record it to generate an error later.
- duplicates.push((
- id.to_string(),
- val,
- prev.clone(),
- ));
+ duplicates.push((id.to_string(), val, prev.clone()));
}
});
if is_expected && !duplicates.is_empty() {
- println!("duplicate artifacts found when compiling a tool, this \
+ println!(
+ "duplicate artifacts found when compiling a tool, this \
typically means that something was recompiled because \
a transitive dependency has different features activated \
- than in a previous build:\n");
- println!("the following dependencies are duplicated although they \
- have the same features enabled:");
+ than in a previous build:\n"
+ );
+ println!(
+ "the following dependencies are duplicated although they \
+ have the same features enabled:"
+ );
for (id, cur, prev) in duplicates.drain_filter(|(_, cur, prev)| cur.2 == prev.2) {
println!(" {}", id);
// same features
println!(" {}", id);
let cur_features: HashSet<_> = cur.2.into_iter().collect();
let prev_features: HashSet<_> = prev.2.into_iter().collect();
- println!(" `{}` additionally enabled features {:?} at {:?}",
- cur.0, &cur_features - &prev_features, cur.1);
- println!(" `{}` additionally enabled features {:?} at {:?}",
- prev.0, &prev_features - &cur_features, prev.1);
+ println!(
+ " `{}` additionally enabled features {:?} at {:?}",
+ cur.0,
+ &cur_features - &prev_features,
+ cur.1
+ );
+ println!(
+ " `{}` additionally enabled features {:?} at {:?}",
+ prev.0,
+ &prev_features - &cur_features,
+ prev.1
+ );
}
println!();
- println!("to fix this you will probably want to edit the local \
+ 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");
+ these crates all share the same feature set"
+ );
panic!("tools should not compile multiple copies of the same crate");
}
- builder.save_toolstate(tool, if is_expected {
- ToolState::TestFail
- } else {
- ToolState::BuildFail
- });
+ builder.save_toolstate(
+ tool,
+ if is_expected { ToolState::TestFail } else { ToolState::BuildFail },
+ );
if !is_expected {
if !is_optional_tool {
None
}
} else {
- let cargo_out = builder.cargo_out(compiler, self.mode, target)
- .join(exe(tool, &compiler.host));
+ let cargo_out =
+ builder.cargo_out(compiler, self.mode, target).join(exe(tool, &compiler.host));
let bin = builder.tools_dir(compiler).join(exe(tool, &compiler.host));
builder.copy(&cargo_out, &bin);
Some(bin)
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("miri") ||
- path.ends_with("rustbook") ||
- path.ends_with("rustfmt")
+ if path.ends_with("cargo")
+ || path.ends_with("rls")
+ || path.ends_with("clippy")
+ || path.ends_with("miri")
+ || path.ends_with("rustbook")
+ || path.ends_with("rustfmt")
{
cargo.env("LIBZ_SYS_STATIC", "1");
features.push("rustc-workspace-hack/all-static".to_string());
macro_rules! bootstrap_tool {
($(
$name:ident, $path:expr, $tool_name:expr
- $(,llvm_tools = $llvm:expr)*
$(,is_external_tool = $external:expr)*
+ $(,is_unstable_tool = $unstable:expr)*
$(,features = $features:expr)*
;
)+) => {
)+
}
- impl Tool {
- /// Whether this tool requires LLVM to run
- pub fn uses_llvm_tools(&self) -> bool {
- match self {
- $(Tool::$name => false $(|| $llvm)*,)+
- }
- }
- }
-
impl<'a> Builder<'a> {
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
match tool {
compiler: self.compiler,
target: self.target,
tool: $tool_name,
- mode: Mode::ToolBootstrap,
+ mode: if false $(|| $unstable)* {
+ // use in-tree libraries for unstable features
+ Mode::ToolStd
+ } else {
+ Mode::ToolBootstrap
+ },
path: $path,
is_optional_tool: false,
source_type: if false $(|| $external)* {
Tidy, "src/tools/tidy", "tidy";
Linkchecker, "src/tools/linkchecker", "linkchecker";
CargoTest, "src/tools/cargotest", "cargotest";
- Compiletest, "src/tools/compiletest", "compiletest", llvm_tools = true;
+ Compiletest, "src/tools/compiletest", "compiletest", is_unstable_tool = true;
BuildManifest, "src/tools/build-manifest", "build-manifest";
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
impl ErrorIndex {
pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
- let mut cmd = Command::new(builder.ensure(ErrorIndex {
- compiler
- }));
+ let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler }));
add_lib_path(
vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
&mut cmd,
// Compile the error-index in the same stage as rustdoc to avoid
// recompiling rustdoc twice if we can.
let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 };
- run.builder.ensure(ErrorIndex {
- compiler: run.builder.compiler(stage, run.builder.config.build),
- });
+ run.builder
+ .ensure(ErrorIndex { compiler: run.builder.compiler(stage, run.builder.config.build) });
}
fn run(self, builder: &Builder<'_>) -> PathBuf {
- builder.ensure(ToolBuild {
- compiler: self.compiler,
- target: self.compiler.host,
- tool: "error_index_generator",
- mode: Mode::ToolRustc,
- path: "src/tools/error_index_generator",
- is_optional_tool: false,
- source_type: SourceType::InTree,
- extra_features: Vec::new(),
- }).expect("expected to build -- essential tool")
+ builder
+ .ensure(ToolBuild {
+ compiler: self.compiler,
+ target: self.compiler.host,
+ tool: "error_index_generator",
+ mode: Mode::ToolRustc,
+ path: "src/tools/error_index_generator",
+ is_optional_tool: false,
+ source_type: SourceType::InTree,
+ extra_features: Vec::new(),
+ })
+ .expect("expected to build -- essential tool")
}
}
}
fn run(self, builder: &Builder<'_>) -> PathBuf {
- builder.ensure(ToolBuild {
- compiler: self.compiler,
- target: self.target,
- tool: "remote-test-server",
- mode: Mode::ToolStd,
- path: "src/tools/remote-test-server",
- is_optional_tool: false,
- source_type: SourceType::InTree,
- extra_features: Vec::new(),
- }).expect("expected to build -- essential tool")
+ builder
+ .ensure(ToolBuild {
+ compiler: self.compiler,
+ target: self.target,
+ tool: "remote-test-server",
+ mode: Mode::ToolStd,
+ path: "src/tools/remote-test-server",
+ is_optional_tool: false,
+ source_type: SourceType::InTree,
+ extra_features: Vec::new(),
+ })
+ .expect("expected to build -- essential tool")
}
}
}
fn make_run(run: RunConfig<'_>) {
- run.builder.ensure(Rustdoc {
- compiler: run.builder.compiler(run.builder.top_stage, run.host),
- });
+ run.builder
+ .ensure(Rustdoc { compiler: run.builder.compiler(run.builder.top_stage, run.host) });
}
fn run(self, builder: &Builder<'_>) -> PathBuf {
&[],
);
- builder.info(&format!("Building rustdoc for stage{} ({})",
- target_compiler.stage, target_compiler.host));
+ builder.info(&format!(
+ "Building rustdoc for stage{} ({})",
+ target_compiler.stage, target_compiler.host
+ ));
builder.run(&mut cargo.into());
// 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.
- let tool_rustdoc = builder.cargo_out(build_compiler, Mode::ToolRustc, target)
+ let tool_rustdoc = builder
+ .cargo_out(build_compiler, Mode::ToolRustc, target)
.join(exe("rustdoc_tool_binary", &target_compiler.host));
// don't create a stage0-sysroot/bin directory.
}
fn run(self, builder: &Builder<'_>) -> PathBuf {
- builder.ensure(ToolBuild {
- compiler: self.compiler,
- target: self.target,
- tool: "cargo",
- mode: Mode::ToolRustc,
- path: "src/tools/cargo",
- is_optional_tool: false,
- source_type: SourceType::Submodule,
- extra_features: Vec::new(),
- }).expect("expected to build -- essential tool")
+ builder
+ .ensure(ToolBuild {
+ compiler: self.compiler,
+ target: self.target,
+ tool: "cargo",
+ mode: Mode::ToolRustc,
+ path: "src/tools/cargo",
+ is_optional_tool: false,
+ source_type: SourceType::Submodule,
+ extra_features: Vec::new(),
+ })
+ .expect("expected to build -- essential tool")
}
}
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
for &(ref k, ref v) in self.cc[&compiler.host].env() {
if k != "PATH" {
- continue
+ continue;
}
for path in env::split_paths(v) {
if !curpaths.contains(&path) {