Skip to content

Commit b36f036

Browse files
committed
Added some docs
1 parent cf181ae commit b36f036

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/cargo/core/compiler/locking.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
//! This module handles the locking logic during compilation.
2+
//!
3+
//! The locking scheme is based on build unit level locking.
4+
//! Each build unit consists of a primary and secondary lock used to represent multiple lock states.
5+
//!
6+
//! | State | Primary | Secondary |
7+
//! |------------------------|-------------|-------------|
8+
//! | Building Exclusive | `exclusive` | `exclusive` |
9+
//! | Building Non-Exclusive | `shared` | `exclusive` |
10+
//! | Shared | `shared` | `none` |
11+
//!
12+
//! Generally a build unit will full the following flow:
13+
//! 1. Acquire a "building exclusive" lock for the current build unit.
14+
//! 2. Acquire "shared" locks on all dependency build units.
15+
//! 3. Begin building with rustc
16+
//! 4. If we are building a library, downgrade to a "building non-exclusive" lock when the `.rmeta` has been generated.
17+
//! 5. Once complete release all locks.
18+
//!
19+
//! The primary reason for the complexity here it to allow dependant crates to proceed with thier
20+
//! compilation as possible.
21+
//!
22+
//! [`CompilationLock`] is the primary interface for locking.
23+
124
use std::{
225
fs::{File, OpenOptions},
326
path::{Path, PathBuf},
@@ -46,6 +69,7 @@ impl CompilationLock {
4669
}
4770
}
4871

72+
/// A lock for a single build unit.
4973
struct UnitLock {
5074
primary: PathBuf,
5175
secondary: PathBuf,

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,11 @@ fn rustc(
363363
return Ok(Work::new(move |state| {
364364
if let Some(lock) = &mut lock {
365365
lock.lock();
366+
367+
// TODO: We need to revalidate the fingerprint here as another Cargo instance could
368+
// have already compiled the crate before we recv'd the lock.
369+
// For large crates re-compiling here would be quiet costly.
366370
}
367-
// let mut lock = lock.map(|v| v.lock());
368371

369372
// Artifacts are in a different location than typical units,
370373
// hence we must assure the crate- and target-dependent

0 commit comments

Comments
 (0)