39 releases

0.16.10 Apr 12, 2024
0.16.7 Mar 20, 2024
0.15.1 Sep 3, 2023
0.14.0 Jul 25, 2023
0.2.0 Feb 5, 2020

#12 in Visualization

Download history 9366/week @ 2024-01-03 9987/week @ 2024-01-10 13544/week @ 2024-01-17 13145/week @ 2024-01-24 10937/week @ 2024-01-31 10056/week @ 2024-02-07 9598/week @ 2024-02-14 10962/week @ 2024-02-21 11625/week @ 2024-02-28 11176/week @ 2024-03-06 10050/week @ 2024-03-13 16034/week @ 2024-03-20 10863/week @ 2024-03-27 13190/week @ 2024-04-03 15641/week @ 2024-04-10 12455/week @ 2024-04-17

54,780 downloads per month
Used in 19 crates (6 directly)

MIT/Apache

120KB
2K SLoC

📦 krates

Embark Embark Crates.io Docs dependency status Build Status

Creates graphs of crates from cargo_metadata metadata.

Usage

use krates::{Builder, Cmd, Krates, cm, petgraph};
fn main() -> Result<(), krates::Error> {
    let mut cmd = Cmd::new();
    cmd.manifest_path("path/to/a/Cargo.toml");
    // Enable all features, works for either an entire workspace or a single crate
    cmd.all_features();

    let mut builder = Builder::new();
    // Let's filter out any crates that aren't used by x86_64 windows
    builder.include_targets(std::iter::once(("x86_64-pc-windows-msvc", vec![])));

    let krates: Krates = builder.build(cmd, |pkg: cm::Package| {
        println!("Crate {} was filtered out", pkg.id);
    })?;

    // Print a dot graph of the entire crate graph
    println!("{:?}", petgraph::dot::Dot::new(krates.graph()));

    Ok(())
}

krates can also be used if you use cargo as a dependency. It doesn't depend on cargo itself since cargo moves quickly and we don't want to artificially limit which versions you use, but, at least with the current stable cargo crate, the following code works well.

fn get_metadata(
    no_default_features: bool,
    all_features: bool,
    features: Vec<String>,
    manifest_path: PathBuf,
) -> Result<krates::cm::Metadata, anyhow::Error> {
    let config = cargo::util::Config::default()?;
    let ws = cargo::core::Workspace::new(&manifest_path, &config)?;
    let options = cargo::ops::OutputMetadataOptions {
        features,
        no_default_features,
        all_features,
        no_deps: false,
        version: 1,
        filter_platforms: vec![],
    };

    let md = cargo::ops::output_metadata(&ws, &options)?;
    let md_value = serde_json::to_value(md)?;

    Ok(serde_json::from_value(md_value)?)
}

Contributing

Contributor Covenant

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.5–3.5MB
~73K SLoC