| Crates.io | cargo-fixup |
| lib.rs | cargo-fixup |
| version | 0.1.2 |
| created_at | 2025-05-22 09:49:48.403422+00 |
| updated_at | 2025-05-23 05:41:56.839441+00 |
| description | A Cargo helper that installs a rustc-wrapper to dynamically patch crate source code at build time — no need to modify Cargo.toml or maintain forks. |
| homepage | https://github.com/cecton/cargo-fixup |
| repository | https://github.com/cecton/cargo-fixup |
| max_upload_size | |
| id | 1684957 |
| size | 26,049 |
A lightweight Cargo plugin that lets you patch crates during build time
using a custom rustc-wrapper.
This tool is useful when you want to:
cargo-fixup installs a rustc-wrapper shell script into your project's
.cargo/ directory, and adds the following to .cargo/config.toml:
[build]
rustc-wrapper = "./.cargo/rustc-wrapper.sh"
At build time, this wrapper:
Intercepts the compilation of each dependency.
Checks if a patch exists under patches/<crate-name>/.
If it finds patch files, it:
target/patched-crates/<crate-name>/All patch logs are written to a file you specify during installation.
In each crate-specific patch directory (e.g. patches/clap-4.5.38/),
cargo-fixup processes every file as follows:
.patch, it is treated as a
unified diff patch and applied using the patch command.This design allows both static patches and dynamic patch logic per crate version, offering high flexibility.
cargo install cargo-fixup
cargo fixup /tmp/patch-log.txt
This writes the wrapper script and (overwrite) config.toml into your
current workspace's .cargo/ directory.
Note: cargo-fixup only sets up the patching mechanism — it does not need
to be installed for the patches to be applied during build.
By default, patching logs are discarded. If you want to capture logs (e.g. to
debug patch application issues), run cargo fixup /path/to/logfile to
configure where logs should be written during builds.
your-project/
├── patches/
│ └── clap-4.5.38/
│ └── clap-fix.patch
├── .cargo/
│ ├── config.toml
│ └── rustc-wrapper.sh
Note: The patch directory name must match the exact package name and
version, formatted as <name>-<version> (e.g. clap-4.5.38). This ensures
patches are applied only to the correct version of a crate.
clapLet's say you want to inject a constant into the clap crate. Create this
patch file at:
patches/clap-4.5.38/clap-fix.patch
diff '--color=auto' -Naur a/src/lib.rs b/src/lib.rs
--- a/src/lib.rs 2006-07-24 03:21:28.000000000 +0200
+++ b/src/lib.rs 2025-05-22 09:29:48.300874016 +0200
@@ -100,3 +100,5 @@
pub mod _features;
#[cfg(feature = "unstable-doc")]
pub mod _tutorial;
+
+pub const HELLO: &str = "Hello from clap!";
Then build your project as usual:
cargo build
If clap (4.5.38) is being compiled, your patch will be applied automatically.
cargo is building external dependencies.patches/<crate-name>-<version>/ directory are
applied.Cargo.toml or interfere with [patch] or
[replace].[patch]?Cargo’s [patch] feature requires maintaining a fork of the entire crate.
cargo-fixup is ideal for:
If you need native Windows support, consider rewriting the wrapper as a Rust binary.
To revert, delete:
.cargo/config.toml.cargo/rustc-wrapper.shpatches/MIT OR Apache-2.0
This project does not accept issues, pull requests, or other contributions. Forks are welcome — feel free to use, modify, and build on it as needed.
mettke/cargo-patch
Automates unpacking a crate into your workspace and adds a [patch] section
in Cargo.toml to override it.
Comparison: Uses Cargo's built-in [patch]; requires manual edits or
workspace management. No dynamic patching.
mokeyish/cargo-patch-crate
Generates and applies [patch] overrides using local crate copies based on
your config.
Comparison: Similar goals, but uses static patching via Cargo configuration instead of runtime patching.
cargo-fixup is unique in that it applies patches dynamically at build
time, using a rustc-wrapper. This avoids modifying Cargo.toml or
committing forked code, making it ideal for temporary or experimental changes.