From a72ebbeafcfc0364407dc5a94151ebf10152408b Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 26 Sep 2024 10:24:37 +0200 Subject: [PATCH] Add a `cargo machete` CI step (#5171) `cargo machete` looks for unused dependencies --- .github/workflows/cargo_machete.yml | 12 ++++++++++++ Cargo.lock | 2 -- RELEASES.md | 1 - crates/egui-winit/Cargo.toml | 1 - crates/egui_demo_lib/Cargo.toml | 1 - examples/custom_style/Cargo.toml | 5 +++++ examples/hello_world_par/Cargo.toml | 4 ++++ examples/images/Cargo.toml | 4 ++++ tests/test_egui_extras_compilation/Cargo.toml | 2 ++ 9 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/cargo_machete.yml diff --git a/.github/workflows/cargo_machete.yml b/.github/workflows/cargo_machete.yml new file mode 100644 index 00000000000..dab6725553c --- /dev/null +++ b/.github/workflows/cargo_machete.yml @@ -0,0 +1,12 @@ +name: Cargo Machete + +on: [push, pull_request] + +jobs: + cargo-machete: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Machete + uses: bnjbvr/cargo-machete@main diff --git a/Cargo.lock b/Cargo.lock index 1a2423eaa8a..2c509d7462b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1261,7 +1261,6 @@ dependencies = [ "document-features", "egui", "log", - "nix", "puffin", "raw-window-handle 0.6.2", "serde", @@ -1306,7 +1305,6 @@ dependencies = [ "document-features", "egui", "egui_extras", - "log", "serde", "unicode_names2", ] diff --git a/RELEASES.md b/RELEASES.md index b825eef8df5..99aec8ef382 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -33,7 +33,6 @@ We don't update the MSRV in a patch release, unless we really, really need to. * [ ] `./scripts/docs.sh`: read and improve documentation of new stuff * [ ] `cargo update` * [ ] `cargo outdated` (or manually look for outdated crates in each `Cargo.toml`) -* [ ] `cargo machete` ## Release testing * [ ] `cargo r -p egui_demo_app` and click around for while diff --git a/crates/egui-winit/Cargo.toml b/crates/egui-winit/Cargo.toml index 4472c70f552..f8a11ec7a36 100644 --- a/crates/egui-winit/Cargo.toml +++ b/crates/egui-winit/Cargo.toml @@ -62,7 +62,6 @@ egui = { workspace = true, default-features = false, features = ["log"] } ahash.workspace = true log.workspace = true -nix = { version = "0.26.4", default-features = false, optional = true } raw-window-handle.workspace = true web-time.workspace = true winit = { workspace = true, default-features = false } diff --git a/crates/egui_demo_lib/Cargo.toml b/crates/egui_demo_lib/Cargo.toml index cc41e923abe..28b0592c228 100644 --- a/crates/egui_demo_lib/Cargo.toml +++ b/crates/egui_demo_lib/Cargo.toml @@ -45,7 +45,6 @@ syntect = ["egui_extras/syntect"] egui = { workspace = true, default-features = false, features = ["color-hex"] } egui_extras = { workspace = true, features = ["default"] } -log.workspace = true unicode_names2 = { version = "0.6.0", default-features = false } # this old version has fewer dependencies #! ### Optional dependencies diff --git a/examples/custom_style/Cargo.toml b/examples/custom_style/Cargo.toml index 23f8a4e93c8..c7ae125493a 100644 --- a/examples/custom_style/Cargo.toml +++ b/examples/custom_style/Cargo.toml @@ -9,6 +9,11 @@ publish = false [lints] workspace = true + +[package.metadata.cargo-machete] +ignored = ["image"] # We need the .png feature + + [dependencies] eframe = { workspace = true, features = [ "default", diff --git a/examples/hello_world_par/Cargo.toml b/examples/hello_world_par/Cargo.toml index a64e7c0e9b0..458847eba4f 100644 --- a/examples/hello_world_par/Cargo.toml +++ b/examples/hello_world_par/Cargo.toml @@ -11,6 +11,10 @@ publish = false workspace = true +[package.metadata.cargo-machete] +ignored = ["winit"] # Just enable some features of it; see below + + [dependencies] eframe = { workspace = true, default-features = false, features = [ # accesskit struggles with threading diff --git a/examples/images/Cargo.toml b/examples/images/Cargo.toml index 57d552e3be4..fd6ed440b39 100644 --- a/examples/images/Cargo.toml +++ b/examples/images/Cargo.toml @@ -11,6 +11,10 @@ publish = false workspace = true +[package.metadata.cargo-machete] +ignored = ["image"] # We only use the dependency to add more features to it + + [dependencies] eframe = { workspace = true, features = [ "default", diff --git a/tests/test_egui_extras_compilation/Cargo.toml b/tests/test_egui_extras_compilation/Cargo.toml index 167a8fa288c..aa1ea2c7ec9 100644 --- a/tests/test_egui_extras_compilation/Cargo.toml +++ b/tests/test_egui_extras_compilation/Cargo.toml @@ -9,6 +9,8 @@ publish = false [lints] workspace = true +[package.metadata.cargo-machete] +ignored = ["eframe", "egui_extras"] # We don't use them, just check that things compile [dependencies] eframe = { workspace = true, features = ["default", "persistence"] }