Skip to content

Commit f6f7b1f

Browse files
committed
Publish type-ir and next-trait-solver
1 parent d11cb68 commit f6f7b1f

File tree

1 file changed

+62
-62
lines changed

1 file changed

+62
-62
lines changed

src/main.rs

+62-62
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use cargo_metadata::{Metadata, Package};
1414

1515
const PREFIX: &str = "ra-ap";
1616

17+
const IN_TREE_FEATURE_NAMES: &[&str] = &["nightly", "rustc"];
18+
1719
fn main() {
1820
let do_publish = std::env::args().nth(1).unwrap() == "publish";
1921
let token = std::env::args().nth(2);
@@ -32,37 +34,46 @@ fn main() {
3234
RustcApCrate {
3335
name: "rustc_abi".to_owned(),
3436
dir: "compiler/rustc_abi".to_owned(),
35-
in_tree_feature_name: "nightly".to_owned(),
3637
},
3738
RustcApCrate {
3839
name: "rustc_hashes".to_owned(),
3940
dir: "compiler/rustc_hashes".to_owned(),
40-
in_tree_feature_name: "".to_owned(),
4141
},
4242
RustcApCrate {
4343
name: "rustc_lexer".to_owned(),
4444
dir: "compiler/rustc_lexer".to_owned(),
45-
in_tree_feature_name: "nightly".to_owned(),
4645
},
4746
RustcApCrate {
4847
name: "rustc_parse_format".to_owned(),
4948
dir: "compiler/rustc_parse_format".to_owned(),
50-
in_tree_feature_name: "nightly".to_owned(),
5149
},
5250
RustcApCrate {
5351
name: "rustc_pattern_analysis".to_owned(),
5452
dir: "compiler/rustc_pattern_analysis".to_owned(),
55-
in_tree_feature_name: "rustc".to_owned(),
5653
},
5754
RustcApCrate {
5855
name: "rustc_index".to_owned(),
5956
dir: "compiler/rustc_index".to_owned(),
60-
in_tree_feature_name: "nightly".to_owned(),
6157
},
6258
RustcApCrate {
6359
name: "rustc_index_macros".to_owned(),
6460
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(),
6677
},
6778
];
6879

@@ -167,46 +178,43 @@ fn download_src(dst: &Path, commit: &str) {
167178
}
168179

169180
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 {
176182
let path = dst.join(dir).join("Cargo.toml");
177183
let toml = std::fs::read_to_string(&path).unwrap();
178184
let mut toml = toml.parse::<toml_edit::Document>().unwrap();
179185

180186
// remove "lints.workspace = true" because we don't have a workspace
181187
toml.remove("lints");
182188

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())
195204
}
196-
res.push(s.strip_prefix("dep:").unwrap_or(s).to_owned())
197205
}
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+
}
206214
}
207-
}
208-
Some(())
209-
})();
215+
Some(())
216+
})();
217+
}
210218
// remove all features mentioning the in tree feature
211219
(|| {
212220
let features_to_kill = toml
@@ -215,8 +223,10 @@ fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPa
215223
.iter()
216224
.filter(|(_, val)| {
217225
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+
})
220230
})
221231
})
222232
.map(|(key, _)| key.to_owned())
@@ -230,21 +240,11 @@ fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPa
230240
std::fs::write(path, toml.to_string()).unwrap();
231241
}
232242

233-
let mut work = target_crates.to_vec();
234243
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
243246
.iter()
244-
.any(|it: &RustcPackageInfo| it.package.name == name)
245-
{
246-
continue;
247-
}
247+
.any(|it: &RustcPackageInfo| it.package.name == *name));
248248
let mut cmd = cargo_metadata::MetadataCommand::new();
249249
cmd.manifest_path(dst.join(dir).join("Cargo.toml"));
250250
let metadata = cmd.exec().unwrap();
@@ -255,16 +255,17 @@ fn get_rustc_packages(target_crates: &[RustcApCrate], dst: &Path) -> Vec<RustcPa
255255
.find(|p| p.name == *name)
256256
.expect(&format!("failed to find {}", &name))
257257
.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-
}
267258

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+
);
268269
packages.push(RustcPackageInfo {
269270
package: rustc_package,
270271
metadata,
@@ -332,7 +333,6 @@ fn crates_in_topological_order<'a>(pkgs: &[&'a Package]) -> Vec<&'a Package> {
332333
struct RustcApCrate {
333334
name: String,
334335
dir: String,
335-
in_tree_feature_name: String,
336336
}
337337

338338
struct RustcPackageInfo {

0 commit comments

Comments
 (0)