8
8
//! # places all of its output here.
9
9
//! target/
10
10
//!
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
13
13
//!
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/
16
48
//!
17
49
//! # This is the location at which the output of all custom build
18
- //! # commands are rooted
50
+ //! # commands are rooted.
19
51
//! build/
20
52
//!
21
53
//! # Each package gets its own directory where its build script and
22
54
//! # 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>
26
65
//!
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).
29
71
//! 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/
30
82
//!
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/
50
88
//! ```
89
+ //!
90
+ //! When cross-compiling, the layout is the same, except it appears in
91
+ //! `target/$TRIPLE`.
51
92
52
93
use std:: fs;
53
94
use std:: io;
54
95
use std:: path:: { Path , PathBuf } ;
55
96
56
97
use crate :: core:: Workspace ;
57
- use crate :: util:: { CargoResult , Config , FileLock , Filesystem } ;
98
+ use crate :: util:: { CargoResult , FileLock } ;
58
99
59
100
/// Contains the paths of all target output locations.
60
101
///
61
102
/// See module docs for more information.
62
103
pub struct Layout {
104
+ /// The root directory: `/path/to/target`.
105
+ /// If cross compiling: `/path/to/target/$TRIPLE`.
63
106
root : PathBuf ,
107
+ /// The final artifact destination: `$root/debug` (or `release`).
108
+ dest : PathBuf ,
109
+ /// The directory with rustc artifacts: `$dest/deps`
64
110
deps : PathBuf ,
65
- native : PathBuf ,
111
+ /// The directory for build scripts: `$dest/build`
66
112
build : PathBuf ,
113
+ /// The directory for incremental files: `$dest/incremental`
67
114
incremental : PathBuf ,
115
+ /// The directory for fingerprints: `$dest/.fingerprint`
68
116
fingerprint : PathBuf ,
117
+ /// The directory for examples: `$dest/examples`
69
118
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.
71
123
_lock : FileLock ,
72
124
}
73
125
74
126
pub fn is_bad_artifact_name ( name : & str ) -> bool {
75
- [ "deps" , "examples" , "build" , "native" , " incremental"]
127
+ [ "deps" , "examples" , "build" , "incremental" ]
76
128
. iter ( )
77
129
. any ( |& reserved| reserved == name)
78
130
}
@@ -82,63 +134,57 @@ impl Layout {
82
134
///
83
135
/// This function will block if the directory is already locked.
84
136
///
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" .
87
139
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 ( ) ;
89
141
// Flexible target specifications often point at json files, so interpret
90
142
// the target triple as a Path and then just use the file stem as the
91
143
// component for the directory name in that case.
92
144
if let Some ( triple) = triple {
93
145
let triple = Path :: new ( triple) ;
94
146
if triple. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "json" ) {
95
- path . push (
147
+ root . push (
96
148
triple
97
149
. file_stem ( )
98
150
. ok_or_else ( || failure:: format_err!( "invalid target" ) ) ?,
99
151
) ;
100
152
} else {
101
- path . push ( triple) ;
153
+ root . push ( triple) ;
102
154
}
103
155
}
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) ;
112
157
// If the root directory doesn't already exist go ahead and create it
113
158
// here. Use this opportunity to exclude it from backups as well if the
114
159
// 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 ( ) ) ;
118
163
}
119
164
120
165
// For now we don't do any more finer-grained locking on the artifact
121
166
// directory, so just lock the entire thing for the duration of this
122
167
// compile.
123
- let lock = root . open_rw ( ".cargo-lock" , config, "build directory" ) ?;
168
+ let lock = dest . open_rw ( ".cargo-lock" , ws . config ( ) , "build directory" ) ?;
124
169
let root = root. into_path_unlocked ( ) ;
170
+ let dest = dest. into_path_unlocked ( ) ;
125
171
126
172
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 " ) ,
133
179
root,
180
+ dest,
134
181
_lock : lock,
135
182
} )
136
183
}
137
184
138
185
/// Makes sure all directories stored in the Layout exist on the filesystem.
139
186
pub fn prepare ( & mut self ) -> io:: Result < ( ) > {
140
187
mkdir ( & self . deps ) ?;
141
- mkdir ( & self . native ) ?;
142
188
mkdir ( & self . incremental ) ?;
143
189
mkdir ( & self . fingerprint ) ?;
144
190
mkdir ( & self . examples ) ?;
@@ -154,9 +200,9 @@ impl Layout {
154
200
}
155
201
}
156
202
157
- /// Fetch the root path.
203
+ /// Fetch the destination path for final artifacts (`/…/target/debug`) .
158
204
pub fn dest ( & self ) -> & Path {
159
- & self . root
205
+ & self . dest
160
206
}
161
207
/// Fetch the deps path.
162
208
pub fn deps ( & self ) -> & Path {
@@ -166,7 +212,11 @@ impl Layout {
166
212
pub fn examples ( & self ) -> & Path {
167
213
& self . examples
168
214
}
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`).
170
220
pub fn root ( & self ) -> & Path {
171
221
& self . root
172
222
}
@@ -178,7 +228,7 @@ impl Layout {
178
228
pub fn fingerprint ( & self ) -> & Path {
179
229
& self . fingerprint
180
230
}
181
- /// Fetch the build path.
231
+ /// Fetch the build script path.
182
232
pub fn build ( & self ) -> & Path {
183
233
& self . build
184
234
}
0 commit comments