@@ -14,6 +14,8 @@ use cargo_metadata::{Metadata, Package};
14
14
15
15
const PREFIX : & str = "ra-ap" ;
16
16
17
+ const IN_TREE_FEATURE_NAMES : & [ & str ] = & [ "nightly" , "rustc" ] ;
18
+
17
19
fn main ( ) {
18
20
let do_publish = std:: env:: args ( ) . nth ( 1 ) . unwrap ( ) == "publish" ;
19
21
let token = std:: env:: args ( ) . nth ( 2 ) ;
@@ -32,37 +34,46 @@ fn main() {
32
34
RustcApCrate {
33
35
name: "rustc_abi" . to_owned( ) ,
34
36
dir: "compiler/rustc_abi" . to_owned( ) ,
35
- in_tree_feature_name: "nightly" . to_owned( ) ,
36
37
} ,
37
38
RustcApCrate {
38
39
name: "rustc_hashes" . to_owned( ) ,
39
40
dir: "compiler/rustc_hashes" . to_owned( ) ,
40
- in_tree_feature_name: "" . to_owned( ) ,
41
41
} ,
42
42
RustcApCrate {
43
43
name: "rustc_lexer" . to_owned( ) ,
44
44
dir: "compiler/rustc_lexer" . to_owned( ) ,
45
- in_tree_feature_name: "nightly" . to_owned( ) ,
46
45
} ,
47
46
RustcApCrate {
48
47
name: "rustc_parse_format" . to_owned( ) ,
49
48
dir: "compiler/rustc_parse_format" . to_owned( ) ,
50
- in_tree_feature_name: "nightly" . to_owned( ) ,
51
49
} ,
52
50
RustcApCrate {
53
51
name: "rustc_pattern_analysis" . to_owned( ) ,
54
52
dir: "compiler/rustc_pattern_analysis" . to_owned( ) ,
55
- in_tree_feature_name: "rustc" . to_owned( ) ,
56
53
} ,
57
54
RustcApCrate {
58
55
name: "rustc_index" . to_owned( ) ,
59
56
dir: "compiler/rustc_index" . to_owned( ) ,
60
- in_tree_feature_name: "nightly" . to_owned( ) ,
61
57
} ,
62
58
RustcApCrate {
63
59
name: "rustc_index_macros" . to_owned( ) ,
64
60
dir: "compiler/rustc_index_macros" . to_owned( ) ,
65
- in_tree_feature_name: "" . to_owned( ) ,
61
+ } ,
62
+ RustcApCrate {
63
+ name: "rustc_type_ir" . to_owned( ) ,
64
+ dir: "compiler/rustc_type_ir" . to_owned( ) ,
65
+ } ,
66
+ RustcApCrate {
67
+ name: "rustc_type_ir_macros" . to_owned( ) ,
68
+ dir: "compiler/rustc_type_ir_macros" . to_owned( ) ,
69
+ } ,
70
+ RustcApCrate {
71
+ name: "rustc_next_trait_solver" . to_owned( ) ,
72
+ dir: "compiler/rustc_next_trait_solver" . to_owned( ) ,
73
+ } ,
74
+ RustcApCrate {
75
+ name: "rustc_ast_id" . to_owned( ) ,
76
+ dir: "compiler/rustc_ast_id" . to_owned( ) ,
66
77
} ,
67
78
] ;
68
79
@@ -167,46 +178,43 @@ fn download_src(dst: &Path, commit: &str) {
167
178
}
168
179
169
180
fn get_rustc_packages ( target_crates : & [ RustcApCrate ] , dst : & Path ) -> Vec < RustcPackageInfo > {
170
- for RustcApCrate {
171
- name : _,
172
- dir,
173
- in_tree_feature_name,
174
- } in target_crates
175
- {
181
+ for RustcApCrate { name : _, dir } in target_crates {
176
182
let path = dst. join ( dir) . join ( "Cargo.toml" ) ;
177
183
let toml = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
178
184
let mut toml = toml. parse :: < toml_edit:: Document > ( ) . unwrap ( ) ;
179
185
180
186
// remove "lints.workspace = true" because we don't have a workspace
181
187
toml. remove ( "lints" ) ;
182
188
183
- ( || {
184
- let item = toml
185
- . get_mut ( "features" ) ?
186
- . as_table_like_mut ( ) ?
187
- . get_mut ( in_tree_feature_name) ?;
188
- let deps = item. as_array_mut ( ) ?;
189
- let mut res = vec ! [ ] ;
190
- for ele in deps. iter ( ) {
191
- if let Some ( s) = ele. as_str ( ) {
192
- if s. contains ( '/' ) {
193
- // this just toggles something, skip it
194
- continue ;
189
+ for in_tree_feature_name in IN_TREE_FEATURE_NAMES {
190
+ ( || {
191
+ let item = toml
192
+ . get_mut ( "features" ) ?
193
+ . as_table_like_mut ( ) ?
194
+ . get_mut ( in_tree_feature_name) ?;
195
+ let deps = item. as_array_mut ( ) ?;
196
+ let mut res = vec ! [ ] ;
197
+ for ele in deps. iter ( ) {
198
+ if let Some ( s) = ele. as_str ( ) {
199
+ if s. contains ( '/' ) {
200
+ // this just toggles something, skip it
201
+ continue ;
202
+ }
203
+ res. push ( s. strip_prefix ( "dep:" ) . unwrap_or ( s) . to_owned ( ) )
195
204
}
196
- res. push ( s. strip_prefix ( "dep:" ) . unwrap_or ( s) . to_owned ( ) )
197
205
}
198
- }
199
- deps . clear ( ) ;
200
- for dep in res {
201
- if let Some ( deps ) = toml
202
- . get_mut ( "dependencies" )
203
- . and_then ( |it| it . as_table_like_mut ( ) )
204
- {
205
- deps . remove ( & dep ) ;
206
+ deps . clear ( ) ;
207
+ for dep in res {
208
+ if let Some ( deps ) = toml
209
+ . get_mut ( "dependencies" )
210
+ . and_then ( |it| it . as_table_like_mut ( ) )
211
+ {
212
+ deps . remove ( & dep ) ;
213
+ }
206
214
}
207
- }
208
- Some ( ( ) )
209
- } ) ( ) ;
215
+ Some ( ( ) )
216
+ } ) ( ) ;
217
+ }
210
218
// remove all features mentioning the in tree feature
211
219
( || {
212
220
let features_to_kill = toml
@@ -215,8 +223,10 @@ fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPa
215
223
. iter ( )
216
224
. filter ( |( _, val) | {
217
225
val. as_array ( ) . map_or ( false , |a| {
218
- a. iter ( )
219
- . any ( |feat| feat. as_str ( ) == Some ( & in_tree_feature_name) )
226
+ a. iter ( ) . any ( |feat| {
227
+ feat. as_str ( )
228
+ . is_some_and ( |feat| IN_TREE_FEATURE_NAMES . contains ( & feat) )
229
+ } )
220
230
} )
221
231
} )
222
232
. map ( |( key, _) | key. to_owned ( ) )
@@ -230,21 +240,11 @@ fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPa
230
240
std:: fs:: write ( path, toml. to_string ( ) ) . unwrap ( ) ;
231
241
}
232
242
233
- let mut work = target_crates. to_vec ( ) ;
234
243
let mut packages = Vec :: new ( ) ;
235
-
236
- while let Some ( RustcApCrate {
237
- name,
238
- dir,
239
- in_tree_feature_name : _,
240
- } ) = work. pop ( )
241
- {
242
- if packages
244
+ for RustcApCrate { name, dir } in target_crates {
245
+ assert ! ( !packages
243
246
. iter( )
244
- . any ( |it : & RustcPackageInfo | it. package . name == name)
245
- {
246
- continue ;
247
- }
247
+ . any( |it: & RustcPackageInfo | it. package. name == * name) ) ;
248
248
let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
249
249
cmd. manifest_path ( dst. join ( dir) . join ( "Cargo.toml" ) ) ;
250
250
let metadata = cmd. exec ( ) . unwrap ( ) ;
@@ -255,16 +255,17 @@ fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPa
255
255
. find ( |p| p. name == * name)
256
256
. expect ( & format ! ( "failed to find {}" , & name) )
257
257
. clone ( ) ;
258
- for dep in rustc_package. dependencies . iter ( ) {
259
- if let Some ( path) = & dep. path {
260
- work. push ( RustcApCrate {
261
- name : dep. name . clone ( ) ,
262
- dir : path. to_string ( ) ,
263
- in_tree_feature_name : "" . to_owned ( ) ,
264
- } )
265
- }
266
- }
267
258
259
+ assert_eq ! (
260
+ & * rustc_package
261
+ . dependencies
262
+ . iter( )
263
+ . filter( |dep| target_crates. iter( ) . all( |it| it. name != dep. name) )
264
+ . map( |dep| dep. name. clone( ) )
265
+ . collect:: <Vec <_>>( ) ,
266
+ & [ ] ,
267
+ "Some dependencies are not specified for publishing"
268
+ ) ;
268
269
packages. push ( RustcPackageInfo {
269
270
package : rustc_package,
270
271
metadata,
@@ -332,7 +333,6 @@ fn crates_in_topological_order<'a>(pkgs: &[&'a Package]) -> Vec<&'a Package> {
332
333
struct RustcApCrate {
333
334
name : String ,
334
335
dir : String ,
335
- in_tree_feature_name : String ,
336
336
}
337
337
338
338
struct RustcPackageInfo {
0 commit comments