-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow [patch]
(and [replace]
) sections in Cargo config.
#5539
Comments
Just to add, I'm aware of
|
Any progress in this issue? config path documentation are not clear. it would be great to support patch in the config |
There's a decent more discussion over in #7199. It sounds like Alex is primarily worried about including this feature since it would mean that To me, that argument seems a little weak, since users can already do the same thing by using source replacement with a local or directory registry. But that approach is fairly complex to get working compared to a simple Nested workspaces (#5042) might help alleviate this problem somewhat by constructing a temporary workspace around all the crates you want to build and specifying a @alexcrichton It would be nice to get some clarity on whether this feature might conceivably be supported given the closure of #7199, or whether it's dead-on-arrival (in which case I think this issue should be closed). |
Personally I don't think that "simply add
Resolving a dependency graph is intended to be a project-local decision, not a global system-configuration decision. That's sort of what Cargo has always trended towards. All that being said there may still be room for a |
I have two proposed paths forward for this, and would be curious to hear your takes. But first, let me talk quickly through the use-case I have in mind. I give a lot more detail in this i.r-l.o post, but basically I have an external build system that manages first-party dependencies. That build system has a lot of bells and whistles, and one of them is that it sort of has its own patching mechanism. Essentially, the build system has a way to shadow first-party dependencies with replacements. This feature is used for a number of things:
The net result of this is that the build system wants to inject dependency patches for certain packages. It could inject them directly into In my case, the need for
I'd be curious to hear your thoughts on these two approaches @alexcrichton. This is a pretty big pain point for me at the moment, and one I'd happily put some time into solving. |
Ah, and a third option inspired by UNIX configuration scripts:
|
Ok thanks for the info, that all definitely makes sense. This definitely strikes a chord with me in the "build system integration" category of Cargo, which is always something that Cargo has basically languished at. Along these lines though at an abstract level this is a problem we've solved many times before in Cargo. A recent example is profile configuration which historically was only located in My worries above where mainly about how a features like this could be misused. In my opinion this stance towards new features has hampered Cargo historically to the point that no progress is made out of the fear that something could be misused. Basically I know I don't always personally strike the right balance between adding things which can be misused and also designing things which are impossible or hard to misuse. That's all basically a way of saying that given your problem statement I really think the best solution is In thinking about this one thing I'm reminded of is the historical So basically I think that a feature like this is a balance between the motivation and the downsides. The motivation depends on who wants it and who's willing to implement/design/advocate for it. The downsides are dependent on the same design and ability to mitigate where possible (or acknowledging that the benefit outweighs the downside if mitigation only goes but so far). Along the path of discussing possible mitigations for the downsides I mentioned above, could you describe a bit how things are set up for you? Many build system integration scenarios, for example, are large monorepos where first-party dependencies have one and will always only have one singular version to choose from. In these cases Is a situation like this applicable to you? Or are your first-party dependencies, for example, coming from an internal registry where there's multiple versions and Cargo's actually doing version resolution between them? |
Thank you for the context, that helps me understand where you're coming from a lot better. I agree this is ultimately a matter of balancing concerns, and think you're right that I think I've documented how things work for me in a couple of places, but it's scattered so let me try to bring it all together here. There are two designs at play — one that is currently in use, and one that is the "next generation" design I'm going for. Current design: The build system generates a local registry ( Lots of internal packages are already built using this pattern, so it's not feasible to change its design overnight, such as telling everyone to now use path dependencies. And even if I could, the paths are generated by the build system, and so we'd need something like named path bases to really make it work. If, on the other hand, the build system could inject a Future design: Going forward, what I want to move to is a single "normal" registry (an http registry if possible) that serves both crates.io crates and internal crates. First-party packages can then be published to said registry, and thus become available to There is another class of dependencies in this design, which is if A depends on B and B is not published to the internal registry. There are a couple of reasons why this might be the case that we don't need to get into. If that's the case, A would list B directly in its dependency closure in the main build system, and it would take care of fetching A locally before trying to build B. The question then of course is how A lists its dependency on B in (*) A question arises here about lockfiles. Say my lockfile for A is generated with a Separately, I wonder if there might be room for a compromise where |
Hm ok thanks for explaining things! I was hoping I'd be struck by some sort of inspiration that would lend itself to a solution to your issues while also not being a fully-generalized Perhaps the next steps here are to implement this in Cargo? I don't think it would be too too large of an implementation. We'd want to gate it to nightly for now, of course, but that should hopefully at least let you explore internally whether it would work for your intended use case?
This sort of depends I think. I'm not entirely sure what you're thinking about how the lockfile is shared, but in general Cargo doesn't complain about an "invalid" lock file unless you pass something like |
Yeah, I've also been going over this many times over, and I keep coming back to either needing to patch in
I'll give that a stab then! I'm imagining that I'll be modifying the part of the code that reads out the We don't currently use nightly internally, but that's a "me problem" not a cargo problem :) Landing it under a nightly-only flag for now seems like the only responsible way to go about it.
Okay, yeah, I think that should be good enough. Thanks!
What do you think of this idea @alexcrichton? It'd limit the blast radius of this kind of config patching to be project-local, and is unlikely to have quite the same chance of hard-to-debug problems as the recursive-search approach. |
I think so yeah, although I probably wouldn't try to agument the
I probably wouldn't bother with extra restrictions for now. I think it makes more sense to implement something easy-ish and flexible in nightly. This is something we'd want to revisit before stabilization. |
I submitted a preliminary nightly-only implementation in #9204. |
Support [patch] in .cargo/config files This patch adds support for `[patch]` sections in `.cargo/config.toml` files. Patches from config files defer to `[patch]` in `Cargo.toml` if both provide a patch for the same crate. The current implementation merge config patches into the workspace manifest patches. It's unclear if that's the right long-term plan, or whether these patches should be stored separately (though likely still in the manifest). Regardless, they _should_ likely continue to be parsed when the manifest is parsed so that errors and such occur in the same place regardless of where a patch is specified. Fixes #5539.
Scenario:
git stash
ing[patch]
sections in the scatteredCargo.toml
files (you are bound to commit them accidentally at some point).Wouldn't it be super useful if we could put
[patch]
(and maybe[replace]
too) sections into our~/.cargo/config
? I'd certainly use that.Thanks
The text was updated successfully, but these errors were encountered: