#patch-file #patch #cargo #dependencies #patchfile

bin+lib patch-crate

patch-crate lets rust 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.

11 releases

0.1.11 Dec 17, 2024
0.1.10 Jul 27, 2024
0.1.9 Dec 16, 2023
0.1.6 Nov 6, 2023
0.1.5 Oct 27, 2023

#910 in Command line utilities

Download history 192/week @ 2024-09-25 279/week @ 2024-10-02 353/week @ 2024-10-09 246/week @ 2024-10-16 309/week @ 2024-10-23 254/week @ 2024-10-30 245/week @ 2024-11-06 296/week @ 2024-11-13 286/week @ 2024-11-20 412/week @ 2024-11-27 699/week @ 2024-12-04 877/week @ 2024-12-11 717/week @ 2024-12-18 433/week @ 2024-12-25 687/week @ 2025-01-01 614/week @ 2025-01-08

2,790 downloads per month

MIT license

27KB
307 lines

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.

# 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.

Get started

  1. Install command patch-crate

    cargo install patch-crate
    
  2. Add broken crate in your Cargo.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

    cargo patch-crate
    
  4. Fix the broken code in target/patch/some-crate directly.

  5. Create a crate-patch

    cargo patch-crate some-crate
    
  6. Commit the patch file to share the fix with your team

    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:

    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

    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 <crate name1> <crate name2> ...

    Create patch file of specific crate from ./target/patch/crate-xxx and save to ./patches

Credits

License

Licensed under either of

at your option.

Dependencies

~89MB
~1.5M SLoC