A powerful Rust code bundler that combines multiple source files into a single, optimized file for competitive programming and code distribution.
π Documentation | π Getting Started | π‘ Examples | π€ Contributing
With cargo :
cargo install cg-bundler
cg-bundler > output.rs
Without cargo :
curl -L https://github.com/MathieuSoysal/cg-bundler/releases/latest/download/cg-bundler-linux-amd64 -o cg-bundler
bash cg-bundler > output.rs
- π Fast bundling - Efficiently combines Rust projects into single files
- π Smart module expansion - Automatically resolves and inlines module dependencies
- π§Ή Code optimization - Removes tests, documentation, and unused code
- ποΈ Configurable transformation - Customize what gets included/excluded
- π¦ Cargo integration - Works seamlessly with standard Cargo projects
- π§ CLI & Library - Use as command-line tool or integrate into your workflow
- β‘ Minification - Optional code minification for size optimization
- π‘οΈ Error handling - Comprehensive error reporting with context
- π Watch mode - NEW Automatic rebuilding on file changes for live development
cargo install cg-bundler
git clone https://github.com/MathieuSoysal/cg-bundler.git
cd cg-bundler
cargo install --path .
# Bundle current directory
cg-bundler
# Bundle specific project
cg-bundler /path/to/rust/project
# Output to file
cg-bundler -o bundled.rs
# Minify output
cg-bundler --minify -o compressed.rs
# Keep documentation and tests
cg-bundler --keep-docs --keep-tests
# NEW: Watch mode for live development
cg-bundler --watch -o output.rs
# Watch with verbose output and fast response
cg-bundler --watch -o output.rs --verbose --debounce 200
- Rust 1.75.0 or later
- Cargo (comes with Rust)
- Compatible with all Rust editions (2015, 2018, 2021)
Option | Short | Description |
---|---|---|
--output |
-o |
Output file path (stdout if not specified) |
--keep-tests |
Keep test code in the bundled output | |
--keep-docs |
Keep documentation comments | |
--no-expand-modules |
Disable module expansion | |
--pretty |
Pretty print the output (format with rustfmt) | |
--minify |
-m |
Minify the output to a single line |
--m2 |
Aggressive minify with whitespace replacements | |
--verbose |
-v |
Verbose output |
--validate |
Validate project can be bundled without errors | |
--info |
Show project structure information | |
--watch |
-w |
NEW Watch for file changes and rebuild automatically |
--src-dir |
Source directory to watch (default: src) | |
--debounce |
Debounce delay in milliseconds (default: 500) | |
--help |
-h |
Print help information |
--version |
-V |
Print version information |
my_project/
βββ Cargo.toml
βββ src/
β βββ main.rs
β βββ lib.rs # Optional
β βββ utils.rs
β βββ game/
β β βββ mod.rs
β β βββ engine.rs
β βββ ai/
β βββ mod.rs
β βββ strategy.rs
// src/main.rs
use my_project::game::GameEngine;
use my_project::ai::Strategy;
fn main() {
let engine = GameEngine::new();
let strategy = Strategy::default();
engine.run_with_strategy(strategy);
}
// src/game/mod.rs
pub mod engine;
pub use engine::GameEngine;
// All modules expanded and combined
pub mod game {
pub struct GameEngine { /* ... */ }
impl GameEngine {
pub fn new() -> Self { /* ... */ }
pub fn run_with_strategy(&self, strategy: Strategy) { /* ... */ }
}
}
pub mod ai {
pub struct Strategy { /* ... */ }
impl Default for Strategy { /* ... */ }
}
use game::GameEngine;
use ai::Strategy;
fn main() {
let engine = GameEngine::new();
let strategy = Strategy::default();
engine.run_with_strategy(strategy);
}
We welcome contributions! Here's how to get started:
# Clone the repository
git clone https://github.com/MathieuSoysal/cg-bundler.git
cd cg-bundler
# Install dependencies and build
cargo build
# Run tests
cargo test
# Check formatting and linting
cargo fmt --check
cargo clippy -- -D warnings
Found a bug? Have a feature request? Please create an issue with:
- Clear description of the problem/feature
- Steps to reproduce (for bugs)
- Expected vs actual behavior
- Your environment (OS, Rust version, etc.)
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 CG Bundler Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Made with β€οΈ by the Rust community
β Star us on GitHub | π Report Bug | π‘ Request Feature