/// `all_krates` should probably be removed at some point.
pub fn all_krates(mut self, name: &str) -> Self {
let mut set = BTreeSet::new();
- for krate in self.builder.in_tree_crates(name) {
+ for krate in self.builder.in_tree_crates(name, None) {
let path = krate.local_path(self.builder);
set.insert(path);
}
///
/// `make_run` will be called separately for each matching command-line path.
pub fn krate(mut self, name: &str) -> Self {
- for krate in self.builder.in_tree_crates(name) {
+ for krate in self.builder.in_tree_crates(name, None) {
let path = krate.local_path(self.builder);
self.paths.insert(PathSet::one(path));
}
Kind::Build => describe!(
compile::Std,
compile::Rustc,
+ compile::CodegenBackend,
compile::StartupObjects,
tool::BuildManifest,
tool::Rustbook,
tool::CargoMiri,
native::Lld
),
- Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => {
- describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy, check::Bootstrap)
- }
+ Kind::Check | Kind::Clippy { .. } | Kind::Fix | Kind::Format => describe!(
+ check::Std,
+ check::Rustc,
+ check::Rustdoc,
+ check::CodegenBackend,
+ check::Clippy,
+ check::Bootstrap
+ ),
Kind::Test => describe!(
crate::toolstate::ToolStateCheck,
test::ExpandYamlAnchors,
dist::RustDev,
dist::Extended,
dist::BuildManifest,
- dist::HashSign
),
Kind::Install => describe!(
install::Docs,
install::Src,
install::Rustc
),
- Kind::Run => describe!(run::ExpandYamlAnchors, run::BuildManifest,),
+ Kind::Run => describe!(run::ExpandYamlAnchors, run::BuildManifest),
}
}
pub fn new(build: &Build) -> Builder<'_> {
let (kind, paths) = match build.config.cmd {
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
- Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
- Subcommand::Clippy { ref paths } => (Kind::Clippy, &paths[..]),
+ Subcommand::Check { ref paths, all_targets: _ } => (Kind::Check, &paths[..]),
+ Subcommand::Clippy { ref paths, .. } => (Kind::Clippy, &paths[..]),
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
self.ensure(Libdir { compiler, target })
}
+ pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
+ self.sysroot_libdir(compiler, compiler.host).with_file_name("codegen-backends")
+ }
+
/// Returns the compiler's libdir where it stores the dynamic libraries that
/// it itself links against.
///
}
}
+ /// Gets the paths to all of the compiler's codegen backends.
+ fn codegen_backends(&self, compiler: Compiler) -> impl Iterator<Item = PathBuf> {
+ fs::read_dir(self.sysroot_codegen_backends(compiler))
+ .into_iter()
+ .flatten()
+ .filter_map(Result::ok)
+ .map(|entry| entry.path())
+ }
+
pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
self.ensure(tool::Rustdoc { compiler })
}
let mut cargo = Command::new(&self.initial_cargo);
let out_dir = self.stage_out(compiler, mode);
+ // Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
+ // so we need to explicitly clear out if they've been updated.
+ for backend in self.codegen_backends(compiler) {
+ self.clear_if_dirty(&out_dir, &backend);
+ }
+
if cmd == "doc" || cmd == "rustdoc" {
let my_out = match mode {
// This is the intended out directory for compiler documentation.
cargo.args(s.split_whitespace());
}
rustflags.env("RUSTFLAGS_BOOTSTRAP");
- rustflags.arg("--cfg=bootstrap");
+ if cmd == "clippy" {
+ // clippy overwrites sysroot if we pass it to cargo.
+ // Pass it directly to clippy instead.
+ // NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
+ // so it has no way of knowing the sysroot.
+ rustflags.arg("--sysroot");
+ rustflags.arg(
+ self.sysroot(compiler)
+ .as_os_str()
+ .to_str()
+ .expect("sysroot must be valid UTF-8"),
+ );
+ // Only run clippy on a very limited subset of crates (in particular, not build scripts).
+ cargo.arg("-Zunstable-options");
+ // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
+ let host_version = Command::new("rustc").arg("--version").output().map_err(|_| ());
+ let output = host_version.and_then(|output| {
+ if output.status.success() {
+ Ok(output)
+ } else {
+ Err(())
+ }
+ }).unwrap_or_else(|_| {
+ eprintln!(
+ "error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
+ );
+ eprintln!("help: try `rustup component add clippy`");
+ std::process::exit(1);
+ });
+ if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") {
+ rustflags.arg("--cfg=bootstrap");
+ }
+ } else {
+ rustflags.arg("--cfg=bootstrap");
+ }
}
if self.config.rust_new_symbol_mangling {
match mode {
Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {}
- Mode::Rustc | Mode::ToolRustc => {
+ Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {
// Build proc macros both for the host and the target
if target != compiler.host && cmd != "check" {
cargo.arg("-Zdual-proc-macros");
// problem, somehow -- not really clear why -- but we know that this
// fixes things.
Mode::ToolRustc => metadata.push_str("tool-rustc"),
+ // Same for codegen backends.
+ Mode::Codegen => metadata.push_str("codegen"),
_ => {}
}
cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata);
// src/bootstrap/bin/{rustc.rs,rustdoc.rs}
cargo
.env("RUSTBUILD_NATIVE_DIR", self.native_dir(target))
- .env("RUSTC", self.out.join("bootstrap/debug/rustc"))
.env("RUSTC_REAL", self.rustc(compiler))
.env("RUSTC_STAGE", stage.to_string())
.env("RUSTC_SYSROOT", &sysroot)
)
.env("RUSTC_ERROR_METADATA_DST", self.extended_error_dir())
.env("RUSTC_BREAK_ON_ICE", "1");
+ // Clippy support is a hack and uses the default `cargo-clippy` in path.
+ // Don't override RUSTC so that the `cargo-clippy` in path will be run.
+ if cmd != "clippy" {
+ cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc"));
+ }
// Dealing with rpath here is a little special, so let's go into some
// detail. First off, `-rpath` is a linker option on Unix platforms
}
let debuginfo_level = match mode {
- Mode::Rustc => self.config.rust_debuginfo_level_rustc,
+ Mode::Rustc | Mode::Codegen => self.config.rust_debuginfo_level_rustc,
Mode::Std => self.config.rust_debuginfo_level_std,
Mode::ToolBootstrap | Mode::ToolStd | Mode::ToolRustc => {
self.config.rust_debuginfo_level_tools
}
}
+ // Compile everything except libraries and proc macros with the more
+ // efficient initial-exec TLS model. This doesn't work with `dlopen`,
+ // so we can't use it by default in general, but we can use it for tools
+ // and our own internal libraries.
+ if !mode.must_support_dlopen() {
+ rustflags.arg("-Ztls-model=initial-exec");
+ }
+
if self.config.incremental {
cargo.env("CARGO_INCREMENTAL", "1");
} else {