GithubHelp home page GithubHelp logo

pombredanne / krates Goto Github PK

View Code? Open in Web Editor NEW

This project forked from embarkstudios/krates

0.0 1.0 0.0 172 KB

๐Ÿ“ฆ Creates graphs of crates from cargo metadata ๐Ÿฆ€

License: Apache License 2.0

Rust 99.06% Shell 0.94%

krates's Introduction

๐Ÿ“ฆ krates

Embark Embark Crates.io Docs dependency status Rust Version 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.