• Stars
    star
    536
  • Rank 82,794 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Remove unused Rust dependencies with this one weird trick!

cargo-machete

Remove unused Rust dependencies with this one weird trick!

build status matrix chat supported rustc stable

Introduction

cargo-machete is a Cargo tool that detects unused dependencies in Rust projects, in a fast (yet imprecise) way.

See also the blog post for a detailed writeup.

Installation

Install cargo-machete with cargo:

cargo install cargo-machete

Usage

Run cargo-machete in a directory that contains one or more Rust projects (using Cargo for dependency management):

cd my-directory && cargo machete

# alternatively

cargo machete /absolute/path/to/my/directory

The return code gives an indication whether unused dependencies have been found:

  • 0 if machete found no unused dependencies,
  • 1 if it found at least one unused dependency,
  • 2 if there was an error during processing (in which case there's no indication whether any unused dependency was found or not).

This can be used in CI situations.

False positives

To ignore a certain set of dependencies in a crate, add package.metadata.cargo-machete to Cargo.toml, and specify an ignored array:

For example:

[dependencies]
prost = "0.10" # Used in code generated by build.rs output, which cargo-machete cannot check

[package.metadata.cargo-machete]
ignored = ["prost"]

If there are too many false positives, consider using the --with-metadata CLI flag, which will call cargo metadata --all-features to find final dependency names, more accurate dependencies per build type, etc. ⚠ This may modify the Cargo.lock files in your projects.

Cargo Machete Action

A github action for cargo machete.

Example usage

The step given by,

      - uses: bnjbvr/cargo-machete@v1

can be added to any workflow.

An example workflow is shown below:

name: Cargo Machete
on:
  pull_request: { branches: "*" }

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Machete
        uses: bnjbvr/cargo-machete@v1

Contributing

Contributor Covenant

We welcome community contributions to this project.

License

MIT license.

More Repositories

1

rouille

Rust programming, in French.
Rust
1,318
star
2

trinity

Matrix bots in Rust and WebAssembly
Rust
62
star
3

botzilla

Matrix bot tuned for Mozilla's needs
JavaScript
25
star
4

laverna-webclipper

WebExtension to easily import pages into your Laverna instance
JavaScript
13
star
5

diary

Diary is a Tent app that allows one to create essays, manage them (update and delete them).
CoffeeScript
12
star
6

Knights-Tour

A Prolog solution to the Knights Tour problem, as stated by Euler.
Prolog
7
star
7

random-cloud

python + mrjob + tornado + foundation == distributed random forests implementation for hadoop clusters
JavaScript
7
star
8

perf-wasm-calls

A micro-benchmark to test the performance of JavaScript to WebAssembly calls
JavaScript
6
star
9

file-per-thread-logger

Rust logging implementation that writes thread logs into separate files
Rust
5
star
10

meta-bot

an irc bot that quotes the twitter account @horsejs and does much more
JavaScript
5
star
11

texture-synthesis-wasm

Texture synthesis algorithm running in WebAssembly
JavaScript
4
star
12

mysteryshack-docker

Dockerfile for self-hosting your own mysteryhack (Rust remote-storage server).
Shell
3
star
13

lolcampz

Collection of scripts to easily set up your tent instance
Ruby
3
star
14

rustatouille

Rustatouille is a page status system!
Rust
3
star
15

gdrive-to-webdav

Moves files from Google Drive to Webdav servers (e.g. Nextcloud)
JavaScript
3
star
16

minstrel

A web proxy for Spotify and a Firefox OS app to play along with it.
JavaScript
3
star
17

udeps-false-negative

Demonstration of an issue with cargo-udeps
Rust
2
star
18

wwww

World Wide Web Workers
JavaScript
2
star
19

slides

All my slide decks
JavaScript
2
star
20

blog.benj.me

Sources of my blog https://blog.benj.me
CSS
2
star
21

baldrdashlift

cli tool to update Cranelift in Spidermonkey (Baldrdash)
Rust
2
star
22

mlocjs-2015

HTML
1
star
23

octotest

Small repo to test Octobors features
Rust
1
star
24

cranelift-compare-gencode

Just a dummy repository to compare code generated by Cranelift in the meta crate.
Rust
1
star
25

regalloc_benchmarks

Rust
1
star
26

nextcloud_analytics_rs

A tiny Rust wrapper for the Nextcloud Analytics API
Rust
1
star
27

leekspin

Reviving the leekspin.com website thanks to wasm
HTML
1
star
28

lox.rs

Rust
1
star
29

algorithms

Why would you keep for yourself the algorithms you're training for, when you can show their bugs to everybody?
C++
1
star
30

cozy-docker-dev

Docker Cozy development environment
JavaScript
1
star
31

.files

My dot files
Python
1
star
32

floats32-bench

Some benchmarks for Float32 optimizations in Firefox Nightly
JavaScript
1
star