Search code examples
rustpatchrust-cargo

Is it possible to apply a patch to external code in Cargo.toml?


I read the Cargo manual about the patch option but it is still unclear to me.

Is it possible to instruct Cargo:

  1. Get the code from this repository.
  2. Apply this patch file (my_cool_change.patch) to that code.

Is making my own fork of the project the only way to do it?


Solution

  • It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it".

    The Cargo documentation is not lying to you: you will need to fork the project you wish to change, make the changes however you need, then replace the dependency with your forked version.