Skip to content

Commit ca93c71

Browse files
committed
docs(layout): Updated layout module docs to document new layout
1 parent 4a930ce commit ca93c71

File tree

1 file changed

+141
-1
lines changed

1 file changed

+141
-1
lines changed

src/cargo/core/compiler/layout.rs

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
//! Management of the directory layout of a build
22
//!
33
//! The directory layout is a little tricky at times, hence a separate file to
4-
//! house this logic. The current layout looks like this:
4+
//! house this logic.
5+
//!
6+
//! As of early 2026, Cargo is restructuring the layout and supports 2 layouts.
7+
//! * the original layout organizing files by type
8+
//! * the new "build unit" based layout
9+
//!
10+
//! For more info the layout transition see: [#15010](https://github.com/rust-lang/cargo/issues/15010)
11+
//!
12+
//! ### original layout
513
//!
614
//! ```text
715
//! # This is the root directory for all output, the top-level package
@@ -98,6 +106,138 @@
98106
//! .metabuild/
99107
//! ```
100108
//!
109+
//! The new build unit based layout has separate structures for `artifact-dir` and `build-dir`.
110+
//! By default both of these point to `target` in the workspace root.
111+
//!
112+
//! ### artifact-dir layout
113+
//!
114+
//! The `artifact-dir` layout is consider part of the public API and
115+
//! cannot be easily changed.
116+
//!
117+
//! ```text
118+
//! <artifact-dir>/
119+
//!
120+
//! # All final artifacts are linked into this directory from the build-dir.
121+
//! # Note that named profiles will soon be included as separate directories
122+
//! # here. They have a restricted format, similar to Rust identifiers, so
123+
//! # Cargo-specific directories added in the future should use some prefix
124+
//! # like `.` to avoid name collisions.
125+
//! debug/ # or release/
126+
//!
127+
//! # File used to lock the directory to prevent multiple cargo processes
128+
//! # from using it at the same time.
129+
//! .cargo-lock
130+
//!
131+
//! # Root directory for all compiled examples.
132+
//! examples/
133+
//!
134+
//! # Output from rustdoc
135+
//! doc/
136+
//!
137+
//! # Output from `cargo package` to build a `.crate` file.
138+
//! package/
139+
//! ```
140+
//!
141+
//! ### build-dir layout
142+
//!
143+
//! The `build-dir` layout is considered an internal implementation detail of Cargo
144+
//! meaning that we can change this if needed. However, in reality many tools rely on
145+
//! implementation details of Cargo so breaking changes need to be done carefully.
146+
//!
147+
//! ```text
148+
//! <build-dir>/
149+
//!
150+
//! # Cache of `rustc -Vv` output for performance.
151+
//! .rustc-info.json
152+
//!
153+
//! # All final artifacts are linked into this directory from `deps`.
154+
//! # Note that named profiles will soon be included as separate directories
155+
//! # here. They have a restricted format, similar to Rust identifiers, so
156+
//! # Cargo-specific directories added in the future should use some prefix
157+
//! # like `.` to avoid name collisions.
158+
//! debug/ # or release/
159+
//!
160+
//! # File used to lock the directory to prevent multiple cargo processes
161+
//! # from using it at the same time.
162+
//! .cargo-lock
163+
//!
164+
//! # Root directory for all compiled examples.
165+
//! examples/
166+
//!
167+
//! # Directory used to store incremental data for the compiler (when
168+
//! # incremental is enabled.
169+
//! incremental/
170+
//!
171+
//! # Main directory for storing build unit related files.
172+
//! # Files are organized by Cargo build unit (`$pkgname/$META`) so that
173+
//! # related files are stored in a single directory.
174+
//! build/
175+
//!
176+
//! # This is the location at which the output of all files related to
177+
//! # a given build unit. These files are organized together so that we can
178+
//! # treat this directly like a single unit for locking and caching.
179+
//! $pkgname/
180+
//! $META/
181+
//! # This is the directory for the rustc artifacts of this unit except build
182+
//! # scripts, examples, and test and bench executables.
183+
//! deps/
184+
//!
185+
//! # Each artifact dependency gets in its own directory.
186+
//! /artifact/$pkgname-$META/$kind
187+
//!
188+
//! # Directory that holds all of the fingerprint files for the build unit.
189+
//! fingerprint/
190+
//! # Set of source filenames for this package.
191+
//! dep-lib-$targetname
192+
//! # Timestamp when this package was last built.
193+
//! invoked.timestamp
194+
//! # The fingerprint hash.
195+
//! lib-$targetname
196+
//! # Detailed information used for logging the reason why
197+
//! # something is being recompiled.
198+
//! lib-$targetname.json
199+
//! # The console output from the compiler. This is cached
200+
//! # so that warnings can be redisplayed for "fresh" units.
201+
//! output-lib-$targetname
202+
//!
203+
//! # If the unit is a build script compilation, the build script
204+
//! # binary will be stored here.
205+
//! build-script/
206+
//! # The build script executable (name may be changed by user).
207+
//! build-script-build-$META
208+
//! # Hard link to build-script-build-$META.
209+
//! build-script-build
210+
//! # Dependency information generated by rustc.
211+
//! build-script-build-$META.d
212+
//! # Debug information, depending on platform and profile
213+
//! # settings.
214+
//! <debug symbols>
215+
//!
216+
//! # If the unit is a build script execution (running the build script bin)
217+
//! # the output of that build will be stored here.
218+
//! build-script-execution/
219+
//! # Timestamp when the build script was last executed.
220+
//! invoked.timestamp
221+
//! # Directory where script can output files ($OUT_DIR).
222+
//! out/
223+
//! # Output from the build script.
224+
//! output
225+
//! # Path to `out`, used to help when the target directory is
226+
//! # moved.
227+
//! root-output
228+
//! # Stderr output from the build script.
229+
//! stderr
230+
//!
231+
//! # Output from rustdoc
232+
//! doc/
233+
//!
234+
//! # Used by `cargo package` and `cargo publish` to build a `.crate` file.
235+
//! package/
236+
//!
237+
//! # Experimental feature for generated build scripts.
238+
//! .metabuild/
239+
//! ```
240+
//!
101241
//! When cross-compiling, the layout is the same, except it appears in
102242
//! `target/$TRIPLE`.
103243

0 commit comments

Comments
 (0)