@@ -13,9 +13,11 @@ use serde_derive::Serialize;
13
13
use std:: collections:: { BTreeMap , BTreeSet } ;
14
14
use std:: io;
15
15
use std:: path:: Path ;
16
+ use std:: process:: Command ;
16
17
18
+ use crate :: core:: build_steps:: compile:: { stream_cargo, CargoMessage } ;
19
+ use crate :: core:: builder:: Builder ;
17
20
use crate :: core:: metadata:: { project_metadata, workspace_members, Dependency } ;
18
- use crate :: Config ;
19
21
20
22
#[ derive( Debug , Serialize ) ]
21
23
/// FIXME(before-merge): doc-comment
@@ -47,8 +49,9 @@ struct Dep {
47
49
}
48
50
49
51
impl RustAnalyzerProject {
50
- #[ allow( dead_code) ] // FIXME(before-merge): remove this
51
- pub ( crate ) fn collect_ra_project_data ( config : & Config ) -> Self {
52
+ pub ( crate ) fn collect_ra_project_data ( builder : & Builder < ' _ > ) -> Self {
53
+ let config = & builder. config ;
54
+
52
55
let mut ra_project = RustAnalyzerProject {
53
56
crates : vec ! [ ] ,
54
57
sysroot : format ! ( "{}" , config. out. join( "host" ) . join( "stage0" ) . display( ) ) ,
@@ -86,11 +89,6 @@ impl RustAnalyzerProject {
86
89
krate. is_workspace_member = workspace_members. iter ( ) . any ( |p| p. name == target. name ) ;
87
90
krate. is_proc_macro = target. crate_types . contains ( & "proc-macro" . to_string ( ) ) ;
88
91
89
- // FIXME(before-merge): We need to figure out how to find proc-macro dylibs.
90
- // if krate.is_proc_macro {
91
- // krate.proc_macro_dylib_path =
92
- // }
93
-
94
92
krate. env . insert ( "RUSTC_BOOTSTRAP" . into ( ) , "1" . into ( ) ) ;
95
93
96
94
if target
@@ -109,14 +107,51 @@ impl RustAnalyzerProject {
109
107
110
108
// Find and fill dependencies of crates.
111
109
for package in packages {
112
- if package. dependencies . is_empty ( ) {
113
- continue ;
114
- }
110
+ if let Some ( index) =
111
+ ra_project. crates . iter ( ) . position ( |c| c. display_name == package. name )
112
+ {
113
+ assert ! (
114
+ !package. manifest_path. is_empty( ) ,
115
+ "manifest_path must be valid for proc-macro crates."
116
+ ) ;
117
+
118
+ let mut cargo = Command :: new ( & builder. initial_cargo ) ;
119
+ cargo
120
+ . env ( "RUSTC_BOOTSTRAP" , "1" )
121
+ . arg ( "build" )
122
+ . arg ( "--manifest-path" )
123
+ . arg ( package. manifest_path ) ;
124
+
125
+ if ra_project. crates [ index] . is_proc_macro {
126
+ // FIXME(before-merge): use `CARGO_TARGET_DIR` to place shared libraries in the build output directory.
127
+ let ok = stream_cargo ( builder, cargo. into ( ) , vec ! [ ] , & mut |msg| {
128
+ let filenames = match msg {
129
+ CargoMessage :: CompilerArtifact { filenames, .. } => filenames,
130
+ _ => return ,
131
+ } ;
132
+
133
+ for filename in filenames {
134
+ let snake_case_name = ra_project. crates [ index]
135
+ . display_name
136
+ . replace ( '-' , "_" )
137
+ . to_lowercase ( ) ;
138
+
139
+ if filename. ends_with ( ".so" )
140
+ && ( filename. contains ( & format ! (
141
+ "lib{}" ,
142
+ ra_project. crates[ index] . display_name
143
+ ) ) || filename. contains ( & format ! ( "lib{}" , snake_case_name) ) )
144
+ {
145
+ ra_project. crates [ index] . proc_macro_dylib_path =
146
+ Some ( filename. to_string ( ) ) ;
147
+ }
148
+ }
149
+ } ) ;
115
150
116
- for dependency in package . dependencies {
117
- if let Some ( index ) =
118
- ra_project . crates . iter ( ) . position ( |c| c . display_name == package . name )
119
- {
151
+ assert ! ( ok ) ;
152
+ }
153
+
154
+ for dependency in package . dependencies {
120
155
if let Some ( dependency_index) =
121
156
ra_project. crates . iter ( ) . position ( |c| c. display_name == dependency. name )
122
157
{
@@ -138,7 +173,6 @@ impl RustAnalyzerProject {
138
173
ra_project
139
174
}
140
175
141
- #[ allow( dead_code) ] // FIXME(before-merge): remove this
142
176
pub ( crate ) fn generate_file ( & self , path : & Path ) -> io:: Result < ( ) > {
143
177
if path. exists ( ) {
144
178
return Err ( io:: Error :: new (
0 commit comments