@@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex};
66
77use crate :: core:: PackageId ;
88use crate :: core:: compiler:: compilation:: { self , UnitOutput } ;
9- use crate :: core:: compiler:: { self , Unit , artifact} ;
9+ use crate :: core:: compiler:: { self , Unit , UserIntent , artifact} ;
1010use crate :: util:: cache_lock:: CacheLockMode ;
1111use crate :: util:: errors:: CargoResult ;
1212use annotate_snippets:: { Level , Message } ;
@@ -352,11 +352,27 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
352352 #[ tracing:: instrument( skip_all) ]
353353 pub fn prepare_units ( & mut self ) -> CargoResult < ( ) > {
354354 let dest = self . bcx . profiles . get_dir_name ( ) ;
355- let host_layout = Layout :: new ( self . bcx . ws , None , & dest) ?;
355+ // We try to only lock the artifact-dir if we need to.
356+ // For example, `cargo check` does not write any files to the artifact-dir so we don't need
357+ // to lock it.
358+ let must_take_artifact_dir_lock = match self . bcx . build_config . intent {
359+ UserIntent :: Check { .. } => false ,
360+ UserIntent :: Build
361+ | UserIntent :: Test
362+ | UserIntent :: Doc { .. }
363+ | UserIntent :: Doctest
364+ | UserIntent :: Bench => true ,
365+ } ;
366+ let host_layout = Layout :: new ( self . bcx . ws , None , & dest, must_take_artifact_dir_lock) ?;
356367 let mut targets = HashMap :: new ( ) ;
357368 for kind in self . bcx . all_kinds . iter ( ) {
358369 if let CompileKind :: Target ( target) = * kind {
359- let layout = Layout :: new ( self . bcx . ws , Some ( target) , & dest) ?;
370+ let layout = Layout :: new (
371+ self . bcx . ws ,
372+ Some ( target) ,
373+ & dest,
374+ must_take_artifact_dir_lock,
375+ ) ?;
360376 targets. insert ( target, layout) ;
361377 }
362378 }
0 commit comments