88//! # places all of its output here.
99//! target/
1010//!
11- //! # This is the root directory for all output of *dependencies*
12- //! deps/
11+ //! # Cache of `rustc -Vv` output for performance.
12+ //! .rustc-info.json
1313//!
14- //! # Root directory for all compiled examples
15- //! examples/
14+ //! # All final artifacts are linked into this directory from `deps`.
15+ //! debug/ # or release/
16+ //!
17+ //! # File used to lock the directory to prevent multiple cargo processes
18+ //! # from using it at the same time.
19+ //! .cargo-lock
20+ //!
21+ //! # Hidden directory that holds all of the fingerprint files for all
22+ //! # packages
23+ //! .fingerprint/
24+ //! # Each package is in a separate directory.
25+ //! $pkgname-$META/
26+ //! # Set of source filenames for this package.
27+ //! dep-lib-$pkgname-$META
28+ //! # Timestamp when this package was last built.
29+ //! invoked.timestamp
30+ //! # The fingerprint hash.
31+ //! lib-$pkgname-$META
32+ //! # Detailed information used for logging the reason why
33+ //! # something is being recompiled.
34+ //! lib-$pkgname-$META.json
35+ //!
36+ //! # This is the root directory for all rustc artifacts except build
37+ //! # scripts, examples, and test and bench executables. Almost every
38+ //! # artifact should have a metadata hash added to its filename to
39+ //! # prevent collisions. One notable exception is dynamic libraries.
40+ //! deps/
41+ //!
42+ //! # Root directory for all compiled examples.
43+ //! examples/
44+ //!
45+ //! # Directory used to store incremental data for the compiler (when
46+ //! # incremental is enabled.
47+ //! incremental/
1648//!
1749//! # This is the location at which the output of all custom build
18- //! # commands are rooted
50+ //! # commands are rooted.
1951//! build/
2052//!
2153//! # Each package gets its own directory where its build script and
2254//! # script output are placed
23- //! $pkg1/
24- //! $pkg2/
25- //! $pkg3/
55+ //! $pkgname-$META/ # For the build script itself.
56+ //! # The build script executable (name may be changed by user).
57+ //! build-script-build-$META
58+ //! # Hard link to build-script-build-$META.
59+ //! build-script-build
60+ //! # Dependency information generated by rustc.
61+ //! build-script-build-$META.d
62+ //! # Debug information, depending on platform and profile
63+ //! # settings.
64+ //! <debug symbols>
2665//!
27- //! # Each directory package has a `out` directory where output
28- //! # is placed.
66+ //! # The package shows up twice with two different metadata hashes.
67+ //! $pkgname-$META/ # For the output of the build script.
68+ //! # Timestamp when the build script was last executed.
69+ //! invoked.timestamp
70+ //! # Directory where script can output files ($OUT_DIR).
2971//! out/
72+ //! # Output from the build script.
73+ //! output
74+ //! # Path to `out`, used to help when the target directory is
75+ //! # moved.
76+ //! root-output
77+ //! # Stderr output from the build script.
78+ //! stderr
79+ //!
80+ //! # Output from rustdoc
81+ //! doc/
3082//!
31- //! # This is the location at which the output of all old custom build
32- //! # commands are rooted
33- //! native/
34- //!
35- //! # Each package gets its own directory for where its output is
36- //! # placed. We can't track exactly what's getting put in here, so
37- //! # we just assume that all relevant output is in these
38- //! # directories.
39- //! $pkg1/
40- //! $pkg2/
41- //! $pkg3/
42- //!
43- //! # Directory used to store incremental data for the compiler (when
44- //! # incremental is enabled.
45- //! incremental/
46- //!
47- //! # Hidden directory that holds all of the fingerprint files for all
48- //! # packages
49- //! .fingerprint/
83+ //! # Used by `cargo package` and `cargo publish` to build a `.crate` file.
84+ //! package/
85+ //!
86+ //! # Experimental feature for generated build scripts.
87+ //! .metabuild/
5088//! ```
89+ //!
90+ //! When cross-compiling, the layout is the same, except it appears in
91+ //! `target/$TRIPLE`.
5192
5293use std:: fs;
5394use std:: io;
5495use std:: path:: { Path , PathBuf } ;
5596
5697use crate :: core:: Workspace ;
57- use crate :: util:: { CargoResult , Config , FileLock , Filesystem } ;
98+ use crate :: util:: { CargoResult , FileLock } ;
5899
59100/// Contains the paths of all target output locations.
60101///
61102/// See module docs for more information.
62103pub struct Layout {
104+ /// The root directory: `/path/to/target`.
105+ /// If cross compiling: `/path/to/target/$TRIPLE`.
63106 root : PathBuf ,
107+ /// The final artifact destination: `$root/debug` (or `release`).
108+ dest : PathBuf ,
109+ /// The directory with rustc artifacts: `$dest/deps`
64110 deps : PathBuf ,
65- native : PathBuf ,
111+ /// The directory for build scripts: `$dest/build`
66112 build : PathBuf ,
113+ /// The directory for incremental files: `$dest/incremental`
67114 incremental : PathBuf ,
115+ /// The directory for fingerprints: `$dest/.fingerprint`
68116 fingerprint : PathBuf ,
117+ /// The directory for examples: `$dest/examples`
69118 examples : PathBuf ,
70- /// The lock file for a build, will be unlocked when this struct is `drop`ped.
119+ /// The directory for rustdoc output: `$root/doc`
120+ doc : PathBuf ,
121+ /// The lockfile for a build (`.cargo-lock`). Will be unlocked when this
122+ /// struct is `drop`ped.
71123 _lock : FileLock ,
72124}
73125
74126pub fn is_bad_artifact_name ( name : & str ) -> bool {
75- [ "deps" , "examples" , "build" , "native" , " incremental"]
127+ [ "deps" , "examples" , "build" , "incremental" ]
76128 . iter ( )
77129 . any ( |& reserved| reserved == name)
78130}
@@ -82,63 +134,57 @@ impl Layout {
82134 ///
83135 /// This function will block if the directory is already locked.
84136 ///
85- /// Differs from `at` in that this calculates the root path from the workspace target directory,
86- /// adding the target triple and the profile ( debug, release, ...) .
137+ /// `dest` should be the final artifact directory name. Currently either
138+ /// " debug" or "release" .
87139 pub fn new ( ws : & Workspace < ' _ > , triple : Option < & str > , dest : & str ) -> CargoResult < Layout > {
88- let mut path = ws. target_dir ( ) ;
140+ let mut root = ws. target_dir ( ) ;
89141 // Flexible target specifications often point at json files, so interpret
90142 // the target triple as a Path and then just use the file stem as the
91143 // component for the directory name in that case.
92144 if let Some ( triple) = triple {
93145 let triple = Path :: new ( triple) ;
94146 if triple. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "json" ) {
95- path . push (
147+ root . push (
96148 triple
97149 . file_stem ( )
98150 . ok_or_else ( || failure:: format_err!( "invalid target" ) ) ?,
99151 ) ;
100152 } else {
101- path . push ( triple) ;
153+ root . push ( triple) ;
102154 }
103155 }
104- path. push ( dest) ;
105- Layout :: at ( ws. config ( ) , path)
106- }
107-
108- /// Calculate the paths for build output, lock the build directory, and return as a Layout.
109- ///
110- /// This function will block if the directory is already locked.
111- pub fn at ( config : & Config , root : Filesystem ) -> CargoResult < Layout > {
156+ let dest = root. join ( dest) ;
112157 // If the root directory doesn't already exist go ahead and create it
113158 // here. Use this opportunity to exclude it from backups as well if the
114159 // system supports it since this is a freshly created folder.
115- if !root . as_path_unlocked ( ) . exists ( ) {
116- root . create_dir ( ) ?;
117- exclude_from_backups ( root . as_path_unlocked ( ) ) ;
160+ if !dest . as_path_unlocked ( ) . exists ( ) {
161+ dest . create_dir ( ) ?;
162+ exclude_from_backups ( dest . as_path_unlocked ( ) ) ;
118163 }
119164
120165 // For now we don't do any more finer-grained locking on the artifact
121166 // directory, so just lock the entire thing for the duration of this
122167 // compile.
123- let lock = root . open_rw ( ".cargo-lock" , config, "build directory" ) ?;
168+ let lock = dest . open_rw ( ".cargo-lock" , ws . config ( ) , "build directory" ) ?;
124169 let root = root. into_path_unlocked ( ) ;
170+ let dest = dest. into_path_unlocked ( ) ;
125171
126172 Ok ( Layout {
127- deps : root . join ( "deps" ) ,
128- native : root . join ( "native " ) ,
129- build : root . join ( "build " ) ,
130- incremental : root . join ( "incremental " ) ,
131- fingerprint : root . join ( ".fingerprint " ) ,
132- examples : root. join ( "examples " ) ,
173+ deps : dest . join ( "deps" ) ,
174+ build : dest . join ( "build " ) ,
175+ incremental : dest . join ( "incremental " ) ,
176+ fingerprint : dest . join ( ".fingerprint " ) ,
177+ examples : dest . join ( "examples " ) ,
178+ doc : root. join ( "doc " ) ,
133179 root,
180+ dest,
134181 _lock : lock,
135182 } )
136183 }
137184
138185 /// Makes sure all directories stored in the Layout exist on the filesystem.
139186 pub fn prepare ( & mut self ) -> io:: Result < ( ) > {
140187 mkdir ( & self . deps ) ?;
141- mkdir ( & self . native ) ?;
142188 mkdir ( & self . incremental ) ?;
143189 mkdir ( & self . fingerprint ) ?;
144190 mkdir ( & self . examples ) ?;
@@ -154,9 +200,9 @@ impl Layout {
154200 }
155201 }
156202
157- /// Fetch the root path.
203+ /// Fetch the destination path for final artifacts (`/…/target/debug`) .
158204 pub fn dest ( & self ) -> & Path {
159- & self . root
205+ & self . dest
160206 }
161207 /// Fetch the deps path.
162208 pub fn deps ( & self ) -> & Path {
@@ -166,7 +212,11 @@ impl Layout {
166212 pub fn examples ( & self ) -> & Path {
167213 & self . examples
168214 }
169- /// Fetch the root path.
215+ /// Fetch the doc path.
216+ pub fn doc ( & self ) -> & Path {
217+ & self . doc
218+ }
219+ /// Fetch the root path (`/…/target`).
170220 pub fn root ( & self ) -> & Path {
171221 & self . root
172222 }
@@ -178,7 +228,7 @@ impl Layout {
178228 pub fn fingerprint ( & self ) -> & Path {
179229 & self . fingerprint
180230 }
181- /// Fetch the build path.
231+ /// Fetch the build script path.
182232 pub fn build ( & self ) -> & Path {
183233 & self . build
184234 }
0 commit comments