1212//! .rustc-info.json
1313//!
1414//! # All final artifacts are linked into this directory from `deps`.
15+ //! # Note that named profiles will soon be included as separate directories
16+ //! # here. They have a restricted format, similar to Rust identifiers, so
17+ //! # Cargo-specific directories added in the future should use some prefix
18+ //! # like `.` to avoid name collisions.
1519//! debug/ # or release/
1620//!
1721//! # File used to lock the directory to prevent multiple cargo processes
4650//! # incremental is enabled.
4751//! incremental/
4852//!
53+ //! # The sysroot for -Zbuild-std builds. This only appears in
54+ //! # target-triple directories (not host), and only if -Zbuild-std is
55+ //! # enabled.
56+ //! .sysroot/
57+ //!
4958//! # This is the location at which the output of all custom build
5059//! # commands are rooted.
5160//! build/
@@ -116,6 +125,10 @@ pub struct Layout {
116125 examples : PathBuf ,
117126 /// The directory for rustdoc output: `$root/doc`
118127 doc : PathBuf ,
128+ /// The local sysroot for the build-std feature.
129+ sysroot : Option < PathBuf > ,
130+ /// The "lib" directory within `sysroot`.
131+ sysroot_libdir : Option < PathBuf > ,
119132 /// The lockfile for a build (`.cargo-lock`). Will be unlocked when this
120133 /// struct is `drop`ped.
121134 _lock : FileLock ,
@@ -139,18 +152,21 @@ impl Layout {
139152 // Flexible target specifications often point at json files, so interpret
140153 // the target triple as a Path and then just use the file stem as the
141154 // component for the directory name in that case.
142- if let Some ( triple) = triple {
143- let triple = Path :: new ( triple) ;
144- if triple. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "json" ) {
145- root. push (
146- triple
147- . file_stem ( )
155+ let triple_path = if let Some ( s) = triple {
156+ let p = Path :: new ( s) ;
157+ let tp = if p. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "json" ) {
158+ Path :: new (
159+ p. file_stem ( )
148160 . ok_or_else ( || failure:: format_err!( "invalid target" ) ) ?,
149- ) ;
161+ )
150162 } else {
151- root. push ( triple) ;
152- }
153- }
163+ p
164+ } ;
165+ root. push ( tp) ;
166+ Some ( tp)
167+ } else {
168+ None
169+ } ;
154170 let dest = root. join ( dest) ;
155171 // If the root directory doesn't already exist go ahead and create it
156172 // here. Use this opportunity to exclude it from backups as well if the
@@ -167,6 +183,17 @@ impl Layout {
167183 let root = root. into_path_unlocked ( ) ;
168184 let dest = dest. into_path_unlocked ( ) ;
169185
186+ // Compute the sysroot path for the build-std feature.
187+ let build_std = ws. config ( ) . cli_unstable ( ) . build_std . as_ref ( ) ;
188+ let ( sysroot, sysroot_libdir) = if let Some ( tp) = build_std. and ( triple_path) {
189+ // This uses a leading dot to avoid collision with named profiles.
190+ let sysroot = dest. join ( ".sysroot" ) ;
191+ let sysroot_libdir = sysroot. join ( "lib" ) . join ( "rustlib" ) . join ( tp) . join ( "lib" ) ;
192+ ( Some ( sysroot) , Some ( sysroot_libdir) )
193+ } else {
194+ ( None , None )
195+ } ;
196+
170197 Ok ( Layout {
171198 deps : dest. join ( "deps" ) ,
172199 build : dest. join ( "build" ) ,
@@ -176,6 +203,8 @@ impl Layout {
176203 doc : root. join ( "doc" ) ,
177204 root,
178205 dest,
206+ sysroot,
207+ sysroot_libdir,
179208 _lock : lock,
180209 } )
181210 }
@@ -223,6 +252,16 @@ impl Layout {
223252 pub fn build ( & self ) -> & Path {
224253 & self . build
225254 }
255+ /// The local sysroot for the build-std feature.
256+ ///
257+ /// Returns None if build-std is not enabled or this is the Host layout.
258+ pub fn sysroot ( & self ) -> Option < & Path > {
259+ self . sysroot . as_ref ( ) . map ( |p| p. as_ref ( ) )
260+ }
261+ /// The "lib" directory within `sysroot`.
262+ pub fn sysroot_libdir ( & self ) -> Option < & Path > {
263+ self . sysroot_libdir . as_ref ( ) . map ( |p| p. as_ref ( ) )
264+ }
226265}
227266
228267#[ cfg( not( target_os = "macos" ) ) ]
0 commit comments