@@ -41,7 +41,7 @@ pub enum ProjectWorkspace {
41
41
Cargo {
42
42
cargo : CargoWorkspace ,
43
43
build_scripts : WorkspaceBuildScripts ,
44
- sysroot : Sysroot ,
44
+ sysroot : Option < Sysroot > ,
45
45
rustc : Option < CargoWorkspace > ,
46
46
/// Holds cfg flags for the current target. We get those by running
47
47
/// `rustc --print cfg`.
@@ -82,7 +82,7 @@ impl fmt::Debug for ProjectWorkspace {
82
82
. debug_struct ( "Cargo" )
83
83
. field ( "root" , & cargo. workspace_root ( ) . file_name ( ) )
84
84
. field ( "n_packages" , & cargo. packages ( ) . len ( ) )
85
- . field ( "n_sysroot_crates " , & sysroot. crates ( ) . len ( ) )
85
+ . field ( "sysroot " , & sysroot. is_some ( ) )
86
86
. field (
87
87
"n_rustc_compiler_crates" ,
88
88
& rustc. as_ref ( ) . map_or ( 0 , |rc| rc. packages ( ) . len ( ) ) ,
@@ -145,14 +145,14 @@ impl ProjectWorkspace {
145
145
let cargo = CargoWorkspace :: new ( meta) ;
146
146
147
147
let sysroot = if config. no_sysroot {
148
- Sysroot :: default ( )
148
+ None
149
149
} else {
150
- Sysroot :: discover ( cargo_toml. parent ( ) ) . with_context ( || {
150
+ Some ( Sysroot :: discover ( cargo_toml. parent ( ) ) . with_context ( || {
151
151
format ! (
152
152
"Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?" ,
153
153
cargo_toml. display( )
154
154
)
155
- } ) ?
155
+ } ) ?)
156
156
} ;
157
157
158
158
let rustc_dir = match & config. rustc_source {
@@ -194,7 +194,7 @@ impl ProjectWorkspace {
194
194
target : Option < & str > ,
195
195
) -> Result < ProjectWorkspace > {
196
196
let sysroot = match & project_json. sysroot_src {
197
- Some ( path) => Some ( Sysroot :: load ( path) ?) ,
197
+ Some ( path) => Some ( Sysroot :: load ( path. clone ( ) ) ?) ,
198
198
None => None ,
199
199
} ;
200
200
let rustc_cfg = rustc_cfg:: get ( None , target) ;
@@ -304,9 +304,9 @@ impl ProjectWorkspace {
304
304
}
305
305
PackageRoot { is_member, include, exclude }
306
306
} )
307
- . chain ( sysroot. crates ( ) . map ( |krate | PackageRoot {
307
+ . chain ( sysroot. into_iter ( ) . map ( |sysroot | PackageRoot {
308
308
is_member : false ,
309
- include : vec ! [ sysroot[ krate ] . root. parent ( ) . to_path_buf( ) ] ,
309
+ include : vec ! [ sysroot. root( ) . to_path_buf( ) ] ,
310
310
exclude : Vec :: new ( ) ,
311
311
} ) )
312
312
. chain ( rustc. into_iter ( ) . flat_map ( |rustc| {
@@ -338,8 +338,9 @@ impl ProjectWorkspace {
338
338
match self {
339
339
ProjectWorkspace :: Json { project, .. } => project. n_crates ( ) ,
340
340
ProjectWorkspace :: Cargo { cargo, sysroot, rustc, .. } => {
341
- let rustc_package_len = rustc. as_ref ( ) . map_or ( 0 , |rc| rc. packages ( ) . len ( ) ) ;
342
- cargo. packages ( ) . len ( ) + sysroot. crates ( ) . len ( ) + rustc_package_len
341
+ let rustc_package_len = rustc. as_ref ( ) . map_or ( 0 , |it| it. packages ( ) . len ( ) ) ;
342
+ let sysroot_package_len = sysroot. as_ref ( ) . map_or ( 0 , |it| it. crates ( ) . len ( ) ) ;
343
+ cargo. packages ( ) . len ( ) + sysroot_package_len + rustc_package_len
343
344
}
344
345
ProjectWorkspace :: DetachedFiles { sysroot, files, .. } => {
345
346
sysroot. crates ( ) . len ( ) + files. len ( )
@@ -380,7 +381,7 @@ impl ProjectWorkspace {
380
381
load,
381
382
cargo,
382
383
build_scripts,
383
- sysroot,
384
+ sysroot. as_ref ( ) ,
384
385
rustc,
385
386
) ,
386
387
ProjectWorkspace :: DetachedFiles { files, sysroot, rustc_cfg } => {
@@ -479,13 +480,15 @@ fn cargo_to_crate_graph(
479
480
load : & mut dyn FnMut ( & AbsPath ) -> Option < FileId > ,
480
481
cargo : & CargoWorkspace ,
481
482
build_scripts : & WorkspaceBuildScripts ,
482
- sysroot : & Sysroot ,
483
+ sysroot : Option < & Sysroot > ,
483
484
rustc : & Option < CargoWorkspace > ,
484
485
) -> CrateGraph {
485
486
let _p = profile:: span ( "cargo_to_crate_graph" ) ;
486
487
let mut crate_graph = CrateGraph :: default ( ) ;
487
- let ( public_deps, libproc_macro) =
488
- sysroot_to_crate_graph ( & mut crate_graph, sysroot, rustc_cfg. clone ( ) , load) ;
488
+ let ( public_deps, libproc_macro) = match sysroot {
489
+ Some ( sysroot) => sysroot_to_crate_graph ( & mut crate_graph, sysroot, rustc_cfg. clone ( ) , load) ,
490
+ None => ( Vec :: new ( ) , None ) ,
491
+ } ;
489
492
490
493
let mut cfg_options = CfgOptions :: default ( ) ;
491
494
cfg_options. extend ( rustc_cfg) ;
0 commit comments