New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[experiment] patch
with patch files
#13779
base: master
Are you sure you want to change the base?
Conversation
b8bb3e5
to
74c61c6
Compare
/// A file indicates that if present, the patched source is ready to use. | ||
const READY_LOCK: &str = ".cargo-ok"; | ||
|
||
/// `PatchedSource` is a source that, when fetching, it patches a paticular |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this doc comment for some design decisions.
b77a914
to
2b15782
Compare
@weihanglo how would you like this reviewer? As this is unstable and we previously agreed to the idea of experiments, in theory the bar is fairly low. I will admit some hesitance on this experiment. In adding a new source kind, I'm assuming this can be a bit invasive (to be fair, I've not yet looked at the code). I'm also a bit surprised at the design direction described in the PR description. So how much design discussion should we work out vs get in, try it out, and then iterate on alternative design ideas as we see needed? |
a46ced8
to
ef73e26
Compare
@epage, This is not intended to merge as-is. It's more like a proof of concept that this approach does works but with a not okay user experience. About reviewing the pull request, I would recommend starting from tests to get an idea of how it looks like. I would suggest not getting into details until we feel better with the UI. We could probably open a Zulip topic on t-cargo for design discussions. |
☔ The latest upstream changes (presumably #13778) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #13783) made this pull request unmergeable. Please resolve the merge conflicts. |
Having look this over it seems pretty reasonable. If you would prefer to experiment with a "resolution loop" I'd be happy to compare cost-benefits, but I suspect this is simpler.
I don't understand why the equals requirement is needed. Say the patch was for I'm not remembering the API at the moment, it may be that we need to return them all up front instead of "as they turn out to be needed"? If that's the problem, we could think about making a lazier API. (PubGrub would be happy with the lazy API, I'm not sure how much churn would be involved in moving the current resolver.)
I don't think I follow, what ends up stuck in time?
This seems to be an important point. Especially as it's across "different versions" with the current |
Oh, I should capture some office hour thoughts In my mind, no matter the type of In my mind, I see this PR introducing two things:
I think we should decouple these conversations so we can make sure we are getting the right semantics for each or, at minimum, defer non- A thought of mine that didn't come up during office hours is me worrying that pluggable patch tools might be generalizing too much. I'd want to see a better explanation of why that extra complexity is needed and what the alternatives are. |
Regular patches can also affect resolution. It is |
Reply to #13779 (comment):
We could have lazy mechanism, but I would like to avoid patching “during resolution” at this moment. Patching before or after resolution is less complicated I believe.
The exact requirement issue. Reply to #13779 (comment):
Actually this PR intentionally touches nothing in The one major thing to explore is the semantic of the new patched source kind when being in Just talked to Jacob earlier. There are at least three timing for patching:
(By registering |
☔ The latest upstream changes (presumably #13813) made this pull request unmergeable. Please resolve the merge conflicts. |
Since `[patch]` section exists also in config, so have it inboth cargo-features and -Z flag.
`SourceKind::Patched` represents a source patched by local patch files.
One thing left out here is a consistent/stable hash for patches, The are absolute local paths that might introduces unnecessary changes in lockfile. To mitigate this, patches under the current workspace root will be relative.
What does this PR try to resolve?
An unstable
-Zpatch-files
flag is added to support patching your dependencies with patch files, with the patchtool you configure in[patchtool]
config table.This is one experiment based on rust-lang/rfcs#3177 that the team maybe be interested in.
See also #4648.
How should we test and review this PR?
Apparently commit by commit. You could start from test to understand the current user experience of it.
Some design decisions in this implementation:
This is currently done by requiring an exact version requirement
=
,so Cargo knows what to download.
we could patch whatever we want including dependencies and
package.version
.Summary
registered toPacakgeRegistry
is the source after patching.{ patches = [<path>] }
field is only available for dependencies under[patch]
table,and only allows patching registry dependencies for now.
PatchedSource
that fetches and applies patches to the original source code duringblock_until_ready
.patched+
, which compose the SourceId to patched.[patchtool]
table in Config to control.I imagine it would be something like git
mergetool
for registering tools,though at this moment it only accepts one via
path
.$CARGO_HOME/patched-src/<hash-of-original-source>/<pkg>-<version>/<cksum-of-patches>
.Patched source rebuilds whenever content of patch files or the underlying source change.
You can find some more documentation under
src/cargo/sources/patched.rs
.Additional information
I don't think patching before dependency resolution is ergonomic.
Your patched source code would be stuck in time and you need to eagerly update and rebuild them.
Some patches may be safely applied across major versions.
However with the current design you need to specify the same patch twice.
We may like to revisit patching during the resolution,
and reconsider the work of re-resolving dependencies.
That is a more user-friendly way for patching with patch files.