https://github.com/mokeyish/cargo-patch-crate
Fix broken crates instantly 🏃🏽♀️💨
https://github.com/mokeyish/cargo-patch-crate
cargo-patch crate patch rust
Last synced: 8 months ago
JSON representation
Fix broken crates instantly 🏃🏽♀️💨
- Host: GitHub
- URL: https://github.com/mokeyish/cargo-patch-crate
- Owner: mokeyish
- License: mit
- Created: 2023-10-27T13:35:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-09T06:58:15.000Z (8 months ago)
- Last Synced: 2025-03-31T16:15:07.148Z (8 months ago)
- Topics: cargo-patch, crate, patch, rust
- Language: Rust
- Homepage:
- Size: 45.9 KB
- Stars: 28
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Patch-Crate
[](https://crates.io/crates/patch-crate)
patch-crate lets rust app developer instantly make and keep fixes to rust crate dependencies.
It's a vital band-aid for those of us living on the bleeding edge.
```sh
# fix a bug in one of your dependencies
vim target/patch/brokencrate
# run patch-crate to create a .patch file
cargo patch-crate some-crate
# commit the patch file to share the fix with your team
git add patches/some-crate+3.14.15.patch
git commit -m "fix broken_file.rs in some-crate"
```
Checkout our example at [here](https://github.com/mokeyish/cargo-patch-crate-example).
## Get started
1. Install command `patch-crate`
```sh
cargo install patch-crate
```
2. Add broken crate in your Cargo.toml
```toml
[package.metadata.patch]
crates = ["some-crate"]
[patch.crates-io]
some-crate = { path="./target/patch/some-crate-1.0.110" }
```
3. Download the crate's source code into `target/patch`
```sh
cargo patch-crate
```
4. Fix the broken code in `target/patch/some-crate` directly.
5. Create a crate-patch
```sh
cargo patch-crate some-crate
```
6. Commit the patch file to share the fix with your team
```sh
git add patches/some-crate+1.0.110.patch
git commit -m "fix broken-code in some-crate"
```
7. Instead of running cargo patch-crate its also possible to add a build.rs file like this:
```rust
fn main() {
println!("cargo:rerun-if-changed=Cargo.toml");
patch_crate::run().expect("Failed while patching");
}
```
To make it work, add the patch-crate library to the build-dependencies
```toml
patch-crate = "0.1"
```
## Command explanation
- `cargo patch-crate`
Apply patch files in `./patches` to `./target/patch/crate-xxx` if it not exist.
- `cargo patch-crate --force`
Clean up `./target/patch/` and apply patch files in `./patches` to `./target/patch/crate-xxx`.
- `crate patch-crate ...`
Create patch file of specific crate from `./target/patch/crate-xxx` and save to `./patches`
## Credits
- [itmettkeDE/cargo-patch](https://github.com/itmettkeDE/cargo-patch)
- [ds300/patch-package](https://github.com/ds300/patch-package)
## License
Licensed under either of
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license ([LICENSE-MIT](LICENSE-MIT) or )
at your option.