Skip to content

Programatic Patching #15564

Open
Open
@raphaelhetzel

Description

@raphaelhetzel

Problem

Hey,
in my project I am using cargo as a library to build customized binaries (user-generated packages) on a server that are then sent to worker nodes.
For this I need to patch a set of my own API/ABI crates to a local/pinned version.

This can be done using the [patch] section in cargo.toml. However, it would be beneficial to do that programatically. A cargo::core::Workspace allows to acquire a PackageRegistry, which allows applying patches. However, there is no method that allows passing that PackageRegistry back to the Workspaceor to pass it to cargo::ops::compile.

Is there something that makes this impossible?
If I create a PR, which of the options below would be the desired one?

Proposed Solution

I see a few options:

  1. A setter that allows setting a PackageRegistry for the Workspace. As the Workspace does not store a PackageRegistry, this might be a larger change.
  2. A setter for the workspace's root_patch. While this is also not stored but generated on the fly, I would assume one could add a setter and a hashmap that is merged in with the highest priority.
  3. Allow passing the PackageRegistry to cargo::ops::Compile, and pass that through to the resolver.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargo-apiArea: cargo-the-library API and internal code issuesA-patchArea: [patch] table overrideC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions