Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

cargo-equip

> 包管理
Open source

A Cargo subcommand to bundle your code into one `.rs` file for competitive programming

100 stars0 likes3 views
WebsiteGitHub

About

A Cargo subcommand to bundle your code into one `.rs` file for competitive programming

cargo-equip

日本語

A Cargo subcommand to bundle your code into one .rs file for competitive programming.

Recent updates

See CHANGELOG.md or Releases for recent updates.

Features

cargo-equip can

  • bundle multiple crates,
  • bundle only used crates,
  • exclude certain crates (--exclude-{atcoder, codingame}-crates),
  • expand procedural macros,
  • preserve scopes for #[macro_export]ed macros,
  • resolve #[cfg(..)],
  • remove comments and doc comments (--remove),
  • minify code (--minify),
  • and check the output.

Example

Sqrt Mod - Library-Cheker

toml
[package]
name = "library-checker"
version = "0.0.0"
edition = "2018"

[dependencies]
ac-library-rs-parted-modint = { git = "https://github.com/qryxip/ac-library-rs-parted" }
proconio = { version = "0.4.3", features = ["derive"] }
qryxip-competitive-tonelli-shanks = { git = "https://github.com/qryxip/competitive-programming-library" }
# ...
rust
use acl_modint::ModInt;
use proconio::{fastout, input};
use tonelli_shanks::ModIntBaseExt as _;

#[fastout]
fn main() {
    input! {
        yps: [(u32, u32)],
    }

    for (y, p) in yps {
        ModInt::set_modulus(p);
        if let Some(x) = ModInt::new(y).sqrt() {
            println!("{}", x);
        } else {
            println!("-1");
        }
    }
}

mod sub {
    // You can also `use` the crate in submodules.

    #[allow(unused_imports)]
    use proconio::input as _;
}

↓

bash
❯ cargo equip \
>       --remove docs `# Remove doc comments` \
>       --minify libs `# Minify each library` \
>       --bin sqrt_mod `# Specify the bin crate` | xsel -b

Submit Info #59239 - Library-Checker

Works With

  • fixedbitset 0.4.0
  • lazy_static 1.4.0
  • maplit 1.0.2
  • memoise 0.3.2
  • multimap 0.8.3
  • permutohedron 0.2.4
  • proconio 0.4.3
  • rustc-hash 1.1.0
  • smallvec 1.6.1
  • strsim 0.10.0
  • whiteread 0.5.0

Installation

Install a nightly toolchain and cargo-udeps first.

bash
❯ rustup update nightly
bash
❯ cargo install cargo-udeps

From Crates.io

bash
❯ cargo install cargo-equip

From master branch

bash
❯ cargo install cargo-equip --git https://github.com/qryxip/cargo-equip

GitHub Releases

Releases

Usage

Follow these constrants when you writing libraries to bundle.

  1. Set package.edition to "2018".

    "2015" is not supported.

  2. Do not use procedural macros in lib crates.

    You can pub use them, but cannot call.

  3. Use $crate instead of crate in macros.

    cargo-equip replaces $crate in macro_rules! with $crate::extern_crate_name_in_main_crate. crate identifiers in macro_rules! are not modified.

  4. Do not use absolute path as possible.

    cargo-equip replaces crate with crate::extern_crate_name_in_main_crate and pub(crate) with pub(in crate::extern_crate_name_in_main_crate).

    However I cannot ensure this works well. Use self:: and super:: instead of crate::.

    diff
    -use crate::foo::Foo;
    +use super::foo::Foo;
  5. If possible, do not use glob import.

    cargo-equip inserts glob imports as substitutes for extern prelude and #[macro_use].

  6. Split into small separate crates as possible.

    cargo-equip does not search "dependencies among items".

    On a website other except AtCoder, Split your library into small crates to fit in 64KiB.

    bash
    .
    ├── a
    │   ├── Cargo.toml
    │   └── src
    │       └── lib.rs
    ├── b
    │   ├── Cargo.toml
    │   └── src
    │       └── lib.rs
    ⋮

When you finish preparing your library crates, add them to [dependencies] of the bin/example. If you generate packages automatically with a tool, add them to its template.

If you want to use rust-lang-ja/ac-library-rs, use qryxip/ac-library-rs-parted instead.

…

The constraints for bins/examples are:

  1. If you use proc-macro crates, make sure the macro names unique.

    If you have trouble about procedural macro names, you can import them with #[macor_use].

  2. If possible, do not use glob import.

    cargo-equip also inserts glob imports as it does into libraries.

    rust
    pub use __cargo_equip::prelude::*;
    
    // ︙
    
    pub mod __cargo_equip {
        pub mod crates {
            // ︙
        }
        // ︙
    
        pub(crate) prelude {
            pub use crate::__cargo_equip::crates::*;
        }
    }
rust
use input::input;
use mic::answer;
use partition_point::RangeBoundsExt as _;

#[answer(join("\n"))]
fn main() -> _ {
    input! {
        a: [u64],
    }
    a.into_iter()
        .map(|a| (1u64..1_000_000_000).partition_point(|ans| ans.pow(2)  i64 {
    if n == 0 || n == 1 {
        return n;
    }
    fib(n - 1) + fib(n - 2)
}
  • proc-macro crates need to be compile with Rust 1.48.0+. If version of the active toolchain is less than 1.48.0, cargo-equip finds an alternative toolchain and uses it for compiling proc-macros.
  • procedural macros re-exported with pub use $name::*; are also able to be expanded.

Options

--remove ...

Removes

  • doc comments (//! .., /// .., /** .. */, #[doc = ".."]) with --remove docs.
  • comments (// .., /* .. */) with --remove comments.
rust
#[allow(dead_code)]
pub mod a {
    //! A.

    /// A.
    pub struct A; // aaaaa
}

↓

rust
#[allow(dead_code)]
pub mod a {
    pub struct A;
}

--minify

Minifies

  • each expaned library with --minify lib.
  • the whole code with --minify all.

Not that the minification function is incomplete. Unnecessary spaces may be inserted.

--no-resolve-cfgs

Do not resolve #[cfg(…)].

--no-rustfmt

Do not format the output.

--no-check

Do not check the output.

License

Dual-licensed under MIT or Apache-2.0.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustcargo-subcommandcompetitive-programming

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category包管理
PricingOpen source

> Related tools

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image