Skip to content

Instantly share code, notes, and snippets.

@madsmtm
Created October 15, 2025 05:10
Show Gist options
  • Select an option

  • Save madsmtm/2a81fc77f4d079882430a24c7126e069 to your computer and use it in GitHub Desktop.

Select an option

Save madsmtm/2a81fc77f4d079882430a24c7126e069 to your computer and use it in GitHub Desktop.
Find crates on crates.io that use `[target.<triple>.dependencies]` sections
#!/usr/bin/env cargo +nightly -Z script
---
[package]
edition = "2024"
[dependencies]
crates-index = { version = "3.11.0", features = [
"git-performance",
"parallel",
"git-https",
] }
crates_io_api = "0.12.0"
rayon = "1.11.0"
[profile.dev]
opt-level = 2
---
use crates_io_api::SyncClient;
use rayon::prelude::*;
use std::{
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
sync::Mutex,
};
fn main() {
let index = crates_index::GitIndex::new_cargo_default().unwrap();
println!("Done fetching git index");
let found = Mutex::new(BTreeSet::new());
index.crates_parallel().for_each(|crate_| {
let crate_ = crate_.unwrap();
let version = crate_
.highest_normal_version()
.unwrap_or(crate_.most_recent_version());
for dep in version.dependencies() {
if let Some(target_cfg) = dep.target() {
if !target_cfg.starts_with("cfg") {
found.lock().unwrap().insert(crate_.name().to_string());
}
}
}
});
let found = found.into_inner().unwrap();
println!("Done parsing crates");
println!("Found {} crates that use target dependencies", found.len());
let client = SyncClient::new(
"small-test-script ([email protected])",
std::time::Duration::from_secs(1),
)
.unwrap();
let mut ordered: Vec<(String, u64)> = found
.into_iter()
.map(|crate_name| {
let downloads = client.crate_downloads(&crate_name).unwrap();
let total = downloads
.version_downloads
.iter()
.map(|d| d.downloads)
.sum();
(crate_name, total)
})
.collect();
println!("Done looking up download stats");
println!();
ordered.sort_by(|(_, a), (_, b)| b.cmp(&a));
for (crate_name, total_downloads) in &ordered {
println!("{crate_name} does not use cfg dependency ({total_downloads} downloads)");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment