-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrap: Allow cleaning individual crates #106168
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ use std::time::{Duration, Instant}; | |
|
||
use crate::cache::{Cache, Interned, INTERNER}; | ||
use crate::config::{SplitDebuginfo, TargetSelection}; | ||
use crate::dist; | ||
use crate::doc; | ||
use crate::flags::{Color, Subcommand}; | ||
use crate::install; | ||
|
@@ -25,6 +24,7 @@ use crate::tool::{self, SourceType}; | |
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir, output, t}; | ||
use crate::EXTRA_CHECK_CFGS; | ||
use crate::{check, compile, Crate}; | ||
use crate::{clean, dist}; | ||
use crate::{Build, CLang, DocTests, GitRepo, Mode}; | ||
|
||
pub use crate::Compiler; | ||
|
@@ -96,6 +96,17 @@ impl RunConfig<'_> { | |
pub fn build_triple(&self) -> TargetSelection { | ||
self.builder.build.build | ||
} | ||
|
||
/// Return a `-p=x -p=y` string suitable for passing to a cargo invocation. | ||
pub fn cargo_crates_in_set(&self) -> Interned<Vec<String>> { | ||
let mut crates = Vec::new(); | ||
for krate in &self.paths { | ||
let path = krate.assert_single_path(); | ||
let crate_name = self.builder.crate_paths[&path.path]; | ||
crates.push(format!("-p={crate_name}")); | ||
} | ||
INTERNER.intern_list(crates) | ||
} | ||
} | ||
|
||
struct StepDescription { | ||
|
@@ -764,8 +775,9 @@ impl<'a> Builder<'a> { | |
run::GenerateCopyright, | ||
), | ||
Kind::Setup => describe!(setup::Profile), | ||
// These commands either don't use paths, or they're special-cased in Build::build() | ||
Kind::Clean | Kind::Format => vec![], | ||
Kind::Clean => describe!(clean::CleanAll, clean::Rustc, clean::Std), | ||
// special-cased in Build::build() | ||
Kind::Format => vec![], | ||
} | ||
} | ||
|
||
|
@@ -827,14 +839,12 @@ impl<'a> Builder<'a> { | |
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]), | ||
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]), | ||
Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]), | ||
Subcommand::Clean { ref paths, .. } => (Kind::Clean, &paths[..]), | ||
Subcommand::Format { .. } => (Kind::Format, &[][..]), | ||
Subcommand::Setup { profile: ref path } => ( | ||
Kind::Setup, | ||
path.as_ref().map_or([].as_slice(), |path| std::slice::from_ref(path)), | ||
), | ||
Subcommand::Clean { .. } => { | ||
panic!() | ||
} | ||
}; | ||
|
||
Self::new_internal(build, kind, paths.to_owned()) | ||
|
@@ -1077,6 +1087,62 @@ impl<'a> Builder<'a> { | |
None | ||
} | ||
|
||
/// Like `cargo`, but only passes flags that are valid for all commands. | ||
pub fn bare_cargo( | ||
&self, | ||
compiler: Compiler, | ||
mode: Mode, | ||
target: TargetSelection, | ||
cmd: &str, | ||
) -> Command { | ||
Comment on lines
+1090
to
+1097
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved from |
||
let mut cargo = Command::new(&self.initial_cargo); | ||
// Run cargo from the source root so it can find .cargo/config. | ||
// This matters when using vendoring and the working directory is outside the repository. | ||
cargo.current_dir(&self.src); | ||
|
||
let out_dir = self.stage_out(compiler, mode); | ||
cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd); | ||
|
||
// Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger` | ||
// from out of tree it shouldn't matter, since x.py is only used for | ||
// building in-tree. | ||
let color_logs = ["RUSTDOC_LOG_COLOR", "RUSTC_LOG_COLOR", "RUST_LOG_COLOR"]; | ||
match self.build.config.color { | ||
Color::Always => { | ||
cargo.arg("--color=always"); | ||
for log in &color_logs { | ||
cargo.env(log, "always"); | ||
} | ||
} | ||
Color::Never => { | ||
cargo.arg("--color=never"); | ||
for log in &color_logs { | ||
cargo.env(log, "never"); | ||
} | ||
} | ||
Color::Auto => {} // nothing to do | ||
} | ||
|
||
if cmd != "install" { | ||
cargo.arg("--target").arg(target.rustc_target_arg()); | ||
} else { | ||
assert_eq!(target, compiler.host); | ||
} | ||
|
||
if self.config.rust_optimize { | ||
// FIXME: cargo bench/install do not accept `--release` | ||
if cmd != "bench" && cmd != "install" { | ||
cargo.arg("--release"); | ||
} | ||
} | ||
|
||
// Remove make-related flags to ensure Cargo can correctly set things up | ||
cargo.env_remove("MAKEFLAGS"); | ||
cargo.env_remove("MFLAGS"); | ||
|
||
cargo | ||
} | ||
|
||
/// Prepares an invocation of `cargo` to be run. | ||
/// | ||
/// This will create a `Command` that represents a pending execution of | ||
|
@@ -1092,11 +1158,8 @@ impl<'a> Builder<'a> { | |
target: TargetSelection, | ||
cmd: &str, | ||
) -> Cargo { | ||
let mut cargo = Command::new(&self.initial_cargo); | ||
let mut cargo = self.bare_cargo(compiler, mode, target, cmd); | ||
let out_dir = self.stage_out(compiler, mode); | ||
// Run cargo from the source root so it can find .cargo/config. | ||
// This matters when using vendoring and the working directory is outside the repository. | ||
cargo.current_dir(&self.src); | ||
|
||
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo, | ||
// so we need to explicitly clear out if they've been updated. | ||
|
@@ -1121,8 +1184,6 @@ impl<'a> Builder<'a> { | |
self.clear_if_dirty(&my_out, &rustdoc); | ||
} | ||
|
||
cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd); | ||
|
||
let profile_var = |name: &str| { | ||
let profile = if self.config.rust_optimize { "RELEASE" } else { "DEV" }; | ||
format!("CARGO_PROFILE_{}_{}", profile, name) | ||
|
@@ -1135,32 +1196,6 @@ impl<'a> Builder<'a> { | |
cargo.env("REAL_LIBRARY_PATH", e); | ||
} | ||
|
||
// Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger` | ||
// from out of tree it shouldn't matter, since x.py is only used for | ||
// building in-tree. | ||
let color_logs = ["RUSTDOC_LOG_COLOR", "RUSTC_LOG_COLOR", "RUST_LOG_COLOR"]; | ||
match self.build.config.color { | ||
Color::Always => { | ||
cargo.arg("--color=always"); | ||
for log in &color_logs { | ||
cargo.env(log, "always"); | ||
} | ||
} | ||
Color::Never => { | ||
cargo.arg("--color=never"); | ||
for log in &color_logs { | ||
cargo.env(log, "never"); | ||
} | ||
} | ||
Color::Auto => {} // nothing to do | ||
} | ||
|
||
if cmd != "install" { | ||
cargo.arg("--target").arg(target.rustc_target_arg()); | ||
} else { | ||
assert_eq!(target, compiler.host); | ||
} | ||
|
||
// Set a flag for `check`/`clippy`/`fix`, so that certain build | ||
// scripts can do less work (i.e. not building/requiring LLVM). | ||
if cmd == "check" || cmd == "clippy" || cmd == "fix" { | ||
|
@@ -1341,9 +1376,6 @@ impl<'a> Builder<'a> { | |
} | ||
|
||
cargo.arg("-j").arg(self.jobs().to_string()); | ||
// Remove make-related flags to ensure Cargo can correctly set things up | ||
cargo.env_remove("MAKEFLAGS"); | ||
cargo.env_remove("MFLAGS"); | ||
|
||
// FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005 | ||
// Force cargo to output binaries with disambiguating hashes in the name | ||
|
@@ -1827,13 +1859,6 @@ impl<'a> Builder<'a> { | |
} | ||
} | ||
|
||
if self.config.rust_optimize { | ||
// FIXME: cargo bench/install do not accept `--release` | ||
if cmd != "bench" && cmd != "install" { | ||
cargo.arg("--release"); | ||
} | ||
} | ||
|
||
if self.config.locked_deps { | ||
cargo.arg("--locked"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from
compile.rs
below without changes.