4
4
//! but we can't process `.rlib` and need source code instead. The source code
5
5
//! is typically installed with `rustup component add rust-src` command.
6
6
7
- use std:: {
8
- env, fs,
9
- ops:: { self , Not } ,
10
- path:: Path ,
11
- process:: Command ,
12
- } ;
7
+ use std:: { env, fs, ops:: Not , path:: Path , process:: Command } ;
13
8
14
9
use anyhow:: { format_err, Result } ;
15
- use base_db:: CrateName ;
16
10
use itertools:: Itertools ;
17
- use la_arena:: { Arena , Idx } ;
18
11
use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
19
12
use rustc_hash:: FxHashMap ;
20
13
use stdx:: format_to;
@@ -37,58 +30,9 @@ pub struct Sysroot {
37
30
pub enum RustLibSrcWorkspace {
38
31
Workspace ( CargoWorkspace ) ,
39
32
Json ( ProjectJson ) ,
40
- Stitched ( Stitched ) ,
41
33
Empty ,
42
34
}
43
35
44
- #[ derive( Debug , Clone , Eq , PartialEq ) ]
45
- pub struct Stitched {
46
- crates : Arena < RustLibSrcCrateData > ,
47
- }
48
-
49
- impl ops:: Index < RustLibSrcCrate > for Stitched {
50
- type Output = RustLibSrcCrateData ;
51
- fn index ( & self , index : RustLibSrcCrate ) -> & RustLibSrcCrateData {
52
- & self . crates [ index]
53
- }
54
- }
55
-
56
- impl Stitched {
57
- pub ( crate ) fn public_deps (
58
- & self ,
59
- ) -> impl Iterator < Item = ( CrateName , RustLibSrcCrate , bool ) > + ' _ {
60
- // core is added as a dependency before std in order to
61
- // mimic rustcs dependency order
62
- [ ( "core" , true ) , ( "alloc" , false ) , ( "std" , true ) , ( "test" , false ) ] . into_iter ( ) . filter_map (
63
- move |( name, prelude) | {
64
- Some ( ( CrateName :: new ( name) . unwrap ( ) , self . by_name ( name) ?, prelude) )
65
- } ,
66
- )
67
- }
68
-
69
- pub ( crate ) fn proc_macro ( & self ) -> Option < RustLibSrcCrate > {
70
- self . by_name ( "proc_macro" )
71
- }
72
-
73
- pub ( crate ) fn crates ( & self ) -> impl ExactSizeIterator < Item = RustLibSrcCrate > + ' _ {
74
- self . crates . iter ( ) . map ( |( id, _data) | id)
75
- }
76
-
77
- fn by_name ( & self , name : & str ) -> Option < RustLibSrcCrate > {
78
- let ( id, _data) = self . crates . iter ( ) . find ( |( _id, data) | data. name == name) ?;
79
- Some ( id)
80
- }
81
- }
82
-
83
- pub ( crate ) type RustLibSrcCrate = Idx < RustLibSrcCrateData > ;
84
-
85
- #[ derive( Debug , Clone , Eq , PartialEq ) ]
86
- pub ( crate ) struct RustLibSrcCrateData {
87
- pub ( crate ) name : String ,
88
- pub ( crate ) root : ManifestPath ,
89
- pub ( crate ) deps : Vec < RustLibSrcCrate > ,
90
- }
91
-
92
36
impl Sysroot {
93
37
pub const fn empty ( ) -> Sysroot {
94
38
Sysroot {
@@ -116,7 +60,6 @@ impl Sysroot {
116
60
match & self . workspace {
117
61
RustLibSrcWorkspace :: Workspace ( ws) => ws. packages ( ) . next ( ) . is_none ( ) ,
118
62
RustLibSrcWorkspace :: Json ( project_json) => project_json. n_crates ( ) == 0 ,
119
- RustLibSrcWorkspace :: Stitched ( stitched) => stitched. crates . is_empty ( ) ,
120
63
RustLibSrcWorkspace :: Empty => true ,
121
64
}
122
65
}
@@ -129,7 +72,6 @@ impl Sysroot {
129
72
match & self . workspace {
130
73
RustLibSrcWorkspace :: Workspace ( ws) => ws. packages ( ) . count ( ) ,
131
74
RustLibSrcWorkspace :: Json ( project_json) => project_json. n_crates ( ) ,
132
- RustLibSrcWorkspace :: Stitched ( c) => c. crates ( ) . count ( ) ,
133
75
RustLibSrcWorkspace :: Empty => 0 ,
134
76
}
135
77
}
@@ -258,51 +200,8 @@ impl Sysroot {
258
200
} else if let RustSourceWorkspaceConfig :: Json ( project_json) = sysroot_source_config {
259
201
return Some ( RustLibSrcWorkspace :: Json ( project_json. clone ( ) ) ) ;
260
202
}
261
- tracing:: debug!( "Stitching sysroot library: {src_root}" ) ;
262
-
263
- let mut stitched = Stitched { crates : Arena :: default ( ) } ;
264
-
265
- for path in SYSROOT_CRATES . trim ( ) . lines ( ) {
266
- let name = path. split ( '/' ) . last ( ) . unwrap ( ) ;
267
- let root = [ format ! ( "{path}/src/lib.rs" ) , format ! ( "lib{path}/lib.rs" ) ]
268
- . into_iter ( )
269
- . map ( |it| src_root. join ( it) )
270
- . filter_map ( |it| ManifestPath :: try_from ( it) . ok ( ) )
271
- . find ( |it| fs:: metadata ( it) . is_ok ( ) ) ;
272
-
273
- if let Some ( root) = root {
274
- stitched. crates . alloc ( RustLibSrcCrateData {
275
- name : name. into ( ) ,
276
- root,
277
- deps : Vec :: new ( ) ,
278
- } ) ;
279
- }
280
- }
281
203
282
- if let Some ( std) = stitched. by_name ( "std" ) {
283
- for dep in STD_DEPS . trim ( ) . lines ( ) {
284
- if let Some ( dep) = stitched. by_name ( dep) {
285
- stitched. crates [ std] . deps . push ( dep)
286
- }
287
- }
288
- }
289
-
290
- if let Some ( alloc) = stitched. by_name ( "alloc" ) {
291
- for dep in ALLOC_DEPS . trim ( ) . lines ( ) {
292
- if let Some ( dep) = stitched. by_name ( dep) {
293
- stitched. crates [ alloc] . deps . push ( dep)
294
- }
295
- }
296
- }
297
-
298
- if let Some ( proc_macro) = stitched. by_name ( "proc_macro" ) {
299
- for dep in PROC_MACRO_DEPS . trim ( ) . lines ( ) {
300
- if let Some ( dep) = stitched. by_name ( dep) {
301
- stitched. crates [ proc_macro] . deps . push ( dep)
302
- }
303
- }
304
- }
305
- Some ( RustLibSrcWorkspace :: Stitched ( stitched) )
204
+ return None ;
306
205
}
307
206
308
207
pub fn set_workspace ( & mut self , workspace : RustLibSrcWorkspace ) {
@@ -317,7 +216,6 @@ impl Sysroot {
317
216
. crates ( )
318
217
. filter_map ( |( _, krate) | krate. display_name . clone ( ) )
319
218
. any ( |name| name. canonical_name ( ) . as_str ( ) == "core" ) ,
320
- RustLibSrcWorkspace :: Stitched ( stitched) => stitched. by_name ( "core" ) . is_some ( ) ,
321
219
RustLibSrcWorkspace :: Empty => true ,
322
220
} ;
323
221
if !has_core {
@@ -493,33 +391,3 @@ fn get_rust_lib_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
493
391
None
494
392
}
495
393
}
496
-
497
- const SYSROOT_CRATES : & str = "
498
- alloc
499
- backtrace
500
- core
501
- panic_abort
502
- panic_unwind
503
- proc_macro
504
- profiler_builtins
505
- std
506
- stdarch/crates/std_detect
507
- test
508
- unwind" ;
509
-
510
- const ALLOC_DEPS : & str = "core" ;
511
-
512
- const STD_DEPS : & str = "
513
- alloc
514
- panic_unwind
515
- panic_abort
516
- core
517
- profiler_builtins
518
- unwind
519
- std_detect
520
- test" ;
521
-
522
- // core is required for our builtin derives to work in the proc_macro lib currently
523
- const PROC_MACRO_DEPS : & str = "
524
- std
525
- core" ;
0 commit comments