-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Do not lock the artifact-dir for check builds #16230
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
base: master
Are you sure you want to change the base?
Changes from all commits
da0dfd3
a1d20db
bd34162
9f5393a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex}; | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| use crate::core::PackageId; | ||||||||||||||||||||||||||
| use crate::core::compiler::compilation::{self, UnitOutput}; | ||||||||||||||||||||||||||
| use crate::core::compiler::{self, Unit, artifact}; | ||||||||||||||||||||||||||
| use crate::core::compiler::{self, Unit, UserIntent, artifact}; | ||||||||||||||||||||||||||
| use crate::util::cache_lock::CacheLockMode; | ||||||||||||||||||||||||||
| use crate::util::errors::CargoResult; | ||||||||||||||||||||||||||
| use annotate_snippets::{Level, Message}; | ||||||||||||||||||||||||||
|
|
@@ -352,11 +352,32 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> { | |||||||||||||||||||||||||
| #[tracing::instrument(skip_all)] | ||||||||||||||||||||||||||
| pub fn prepare_units(&mut self) -> CargoResult<()> { | ||||||||||||||||||||||||||
| let dest = self.bcx.profiles.get_dir_name(); | ||||||||||||||||||||||||||
| let host_layout = Layout::new(self.bcx.ws, None, &dest)?; | ||||||||||||||||||||||||||
| // We try to only lock the artifact-dir if we need to. | ||||||||||||||||||||||||||
| // For example, `cargo check` does not write any files to the artifact-dir so we don't need | ||||||||||||||||||||||||||
| // to lock it. | ||||||||||||||||||||||||||
| let must_take_artifact_dir_lock = match self.bcx.build_config.intent { | ||||||||||||||||||||||||||
|
Contributor
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. Instead of intent, can we check if artifacts are produced? Do we know that?
Member
Author
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. I checked and I think it may be possible to use some of the logic from Let me know if there is a better way to get this data.
Contributor
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. Hmm, that can get messy. We could create an However, this does highlight a need for either this or conditionally grabbing the lock (#16230 (comment)) cargo/src/cargo/core/compiler/build_runner/compilation_files.rs Lines 529 to 540 in 8c4a25c
We would have been writing out SBOMs without holding the lock. If we don't feel SBOMs are relevant for
Contributor
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. Note: if we change SBOMs, lets do that in its own PR and make a note against rust-lang/rfcs#3553 CC @arlosi |
||||||||||||||||||||||||||
| UserIntent::Check { .. } => { | ||||||||||||||||||||||||||
| // Generally cargo check does not need to take the artifact-dir lock but there is | ||||||||||||||||||||||||||
| // one exception: If check has `--timings` we still need to lock artifact-dir since | ||||||||||||||||||||||||||
| // we will output the report files. | ||||||||||||||||||||||||||
| !self.bcx.build_config.timing_outputs.is_empty() | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| UserIntent::Build | ||||||||||||||||||||||||||
| | UserIntent::Test | ||||||||||||||||||||||||||
| | UserIntent::Doc { .. } | ||||||||||||||||||||||||||
| | UserIntent::Doctest | ||||||||||||||||||||||||||
| | UserIntent::Bench => true, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| let host_layout = Layout::new(self.bcx.ws, None, &dest, must_take_artifact_dir_lock)?; | ||||||||||||||||||||||||||
| let mut targets = HashMap::new(); | ||||||||||||||||||||||||||
| for kind in self.bcx.all_kinds.iter() { | ||||||||||||||||||||||||||
| if let CompileKind::Target(target) = *kind { | ||||||||||||||||||||||||||
| let layout = Layout::new(self.bcx.ws, Some(target), &dest)?; | ||||||||||||||||||||||||||
| let layout = Layout::new( | ||||||||||||||||||||||||||
| self.bcx.ws, | ||||||||||||||||||||||||||
| Some(target), | ||||||||||||||||||||||||||
| &dest, | ||||||||||||||||||||||||||
| must_take_artifact_dir_lock, | ||||||||||||||||||||||||||
| )?; | ||||||||||||||||||||||||||
| targets.insert(target, layout); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -392,9 +413,11 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> { | |||||||||||||||||||||||||
| let files = self.files.as_ref().unwrap(); | ||||||||||||||||||||||||||
| for &kind in self.bcx.all_kinds.iter() { | ||||||||||||||||||||||||||
| let layout = files.layout(kind); | ||||||||||||||||||||||||||
| self.compilation | ||||||||||||||||||||||||||
| .root_output | ||||||||||||||||||||||||||
| .insert(kind, layout.artifact_dir().dest().to_path_buf()); | ||||||||||||||||||||||||||
| if let Some(artifact_dir) = layout.artifact_dir() { | ||||||||||||||||||||||||||
| self.compilation | ||||||||||||||||||||||||||
| .root_output | ||||||||||||||||||||||||||
| .insert(kind, artifact_dir.dest().to_path_buf()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if self.bcx.gctx.cli_unstable().build_dir_new_layout { | ||||||||||||||||||||||||||
| for (unit, _) in self.bcx.unit_graph.iter() { | ||||||||||||||||||||||||||
| let dep_dir = self.files().deps_dir(unit); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
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.
Probably not really on topic, but I recently felt it inconvenient that
CARGO_TARGET_TMPDIRis with build-dir. I usuallycd target/tmpto access test files but now I need to navigate to a shared build-dir directory.I wonder if we should have a project private directory under artifact directory, so that we only lock that for bins
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.
Thought came from me reading this thread #16230 (comment), but placeholder method looks nice also
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.
bin checks are never usable, forget about my comments