Skip to content

Add ability to dynamically patch a dependency #3830

@Luthaf

Description

@Luthaf

Say I have a (list of) patch I want to apply to one of the dependencies of my crate, but I can not have it merged upstream. It would be good if cargo could apply the patch at build time on this crate.

[dependencies.foobar]
version = "1.42"
patches = [
    "path/to/patch-1.patch",
    "path/to/patch-2/foobarize-a-bit-less.patch"
]

This feature would be useful in the following cases:

  • The maintainer of some crate is not responding but I need to ship my fix quickly;
  • I am working in a corporate environment, and I need to patch one of my dependencies, but I can not release this patch;
  • I want to tune some crate for my specific use case, but there is no way the crate maintainer can accept my patch, and I do not want to fork the crate just for this.

How this could work

The patch would only be accepted in the unified diff format, at a fixed directory level. At build time, cargo would unpack the crate sources, parse the diff and apply it to the source before proceeding with compilation.

Are there any drawback of doing this I did not though of?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions