Creates graphs of crates from cargo_metadata metadata

Creates graphs of crates from

📦 krates

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

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

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

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.

Issues

Collection of the latest Issues

Jake-Shadle

Jake-Shadle

enhancement
0

There are multiple reasons for why any particular crate won't end up in the final graph, but the filter callback only says that a crate was filtered, not why, so in complicated scenarios it can be difficult to figure that out, we should add a reason for why every crate was filtered so additional context is available to the user.

Another option, may be to add an optional logging feature that logs out debug info at each decision point, but I'd rather avoid that.

Versions

Find the latest versions by id

0.10.1 - Feb 16, 2022

Fixed

  • PR#38 fixed #37 by properly adding multiple features if specified.

0.10.0 - Feb 04, 2022

Changed

  • PR#36 updated cfg-expr and fixed up crates.io metadata.

0.9.0 - Feb 04, 2022

Fixed

  • PR#35 changed Krates::search_matches to get rid of unnecessary lifetime coupling.

Changed

  • PR#35 updated cfg-expr to 0.9.

0.8.1 - Feb 04, 2022

Added

0.8.0 - Feb 04, 2022

Changed

  • PR#32 replaced the use of difference with similar. Thanks @j-k!
  • PR#33 updated semver, cargo_metadata, petgraph, and cfg-expr to their latest versions.

0.7.0 - Feb 04, 2022

Changed

  • Updated cargo_metadata to 0.13.0, which uses camino for path information, so it is reexported and used for Krates::lock_path

0.6.0 - Feb 04, 2022

Changed

  • Updated cfg-expr to 0.7.0, which brings targets as of 1.50.0

0.5.0 - Feb 04, 2022

Added

  • Added impl PartialEq<cargo_metadata::DependencyKind> for DepKind

Changed

  • Updated semver, cargo_metadata, and `cfg-expr.

0.4.2 - Feb 04, 2022

Fixed

  • PR#19 Fixed an issue where git sources could differ in package id representation between the actual source, and the id used to specify it as a dependency from another package.

0.4.1 - Feb 04, 2022

Fixed

  • Fix to version 0.11.1 of cargo_metadata.

0.4.0 - Feb 04, 2022

Fixed

  • Align semver version with the same one used by cargo_metadata, again.

0.3.1 - Feb 04, 2022

Fixed

  • Align semver version with the same one used by cargo_metadata

0.3.0 - Feb 04, 2022

Changed

  • Updated cfg-expr to 0.4.0, and added the targets feature, will enable the targets feature in cfg-expr, allowing the use of matching cfg expressions against target_lexicon::Triple instead of only built-in targets/names.

0.2.0 - Feb 04, 2022

Changed

  • Updated cfg-expr to 0.2.0, so only 1.41.0 built-in targets are fully supported

0.1.1 - Feb 04, 2022

Added

  • Added PkgSpec, an implementation of cargo's package id specifications
  • Added Builder::workspace, which allows the equivalent of cargo <cmd> --workspace when building the graph
  • Added Builder::exclude, which allows the equivalent of cargo <cmd> --exclude when building the graph

0.1.0 - Feb 04, 2022

Added

  • Initial implementation

Information - Updated Jun 07, 2022

Stars: 20
Forks: 6
Issues: 1

Now available on stable Rust at crates

0 and above use stable Rust

Now available on stable Rust at crates

RustSec Crates 🦀🛡️📦

The RustSec Advisory Database is a repository of security advisories filed

RustSec Crates 🦀🛡️📦

cargo-cov: Source coverage for Rust

cargo-cov is a cargo subcommand which performs source coverage collection and reporting for Rust crates

cargo-cov: Source coverage for Rust

Interledger implementation in Rust :money_with_wings:

All crates require Rust 2018 edition and are tested on the following channels:

Interledger implementation in Rust :money_with_wings:

cargo-raze: Bazel BUILD generation for Rust Crates

An experimental support Cargo plugin for distilling a workspace-level

cargo-raze: Bazel BUILD generation for Rust Crates

Rust bindings for plthook

This crates provides Rust bindings for the API documentation and the description in the

Rust bindings for plthook

This repository holds a Rust port of Google's Tink cryptography library

This repository holds a Rust port of Google's RustCrypto crates – this repo focuses on making

This repository holds a Rust port of Google's Tink cryptography library

rust crates for parsing stuff

Tokenizers for math expressions, splitting text, lexing lisp-like stuff, etc

rust crates for parsing stuff

rust-semverver is a tool to check semver-compliance in Rust library crates

the tool has been developed as a student project during the Google Summer of Code 2017

rust-semverver is a tool to check semver-compliance in Rust library crates

Rust crates for working with healthchecks

io pinging and management APIs

Rust crates for working with healthchecks

Panamax is a tool to mirror the Rust and crates

io repositories, for offline usage of rustup and cargo

Panamax is a tool to mirror the Rust and crates
Facebook Instagram Twitter GitHub Dribbble
Privacy