-
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
cargo add
refuses to add new non-vendored packages due to source replacement
#10729
Comments
It looks like this happens because a fuzzy search for a The simple solution would be to turn off fuzzy searching but I don't know if that is the correct course of action as it would stop |
Hmm, yeah that would at least get rid of the warning message, though you're right, that would cause other issues. Though even if that were changed, wouldn't that cause |
Yeah it would cause it to outright fail. I think throwing an error here is the best course of action as bypassing a source replace feels wrong as it wouldn't be vendored then. You would have to run I personally think throwing an error if their is a source replace may be the best course of action and then have a community subcommand to deal with vendor. This is just my opinion and one of the maintainers will probably have a better idea for the path forward. |
I'm a bit annoyed with the disparate implementations of fuzzy searching. Its difficult to provide a consistent user experience and is easy to make mistakes like this where you assume "its a registry, of course fuzzy searching is safe" when its easy to overlook the interaction with other features like source replacements. Fundamentally, I think that is what needs to be fixed though to fix that would probably require a major refactoring to keep the current, expected behavior working. This would also make solving #10680 less ambiguous As for vendoring in general, we had not yet fleshed out that use case (see #10472). Mind creating a separate issue for this? I had missed that when creating the initial batch of cargo-add issues. |
Sure! So just to make sure I'm on the same page, this issue should be related to the fuzzy searching, and a new issue should be made for the cargo-add-with-vendoring use case? Do you want me to rewrite this current issue, or keep it as-is? |
Yes, let's keep this issue about the fuzzy searching |
I'd propose we do the following
|
refactor(source): Open query API for adding more types of queries ### What does this PR try to resolve? This refactors the Source/Registry traits from accepting a `fuzzy: bool` to accepting an enum so we can add alternative query styles in the future, as discussed in the Cargo team meeting for fixing #10729 The expected fix for `cargo add` at this point would be - Add `QueryKind::Normalized` - Initially, we can make it like Exact for path sources and like Fuzzy for registry sources - Switch cargo-add to using that kind everywhere (both where `Exact` and `Fuzzy` are used) - A test to ensure this fixed it - Rename `Fuzzy` to `Alternatives` or something to clarify its actual intent ### How should we test and review this PR? The refactor is broken down into multiple commits, so ideally review a commit at a time to more easily see how it evolved. ### Additional information Future possibilities - Supporting normalized search on all sources - Doing version / source matching for normalized results (probably not needed for cargo-add but will make the API less surprising for future users)
#10883 was a refactor that laid the ground work for fixing this. Remaining steps:
|
I am presently running into this issue and I have no idea how to find my way out. |
claim first, question it later~ @rustbot claim |
fix(add): Improve error when adding registry packages while vendored ### **What does this PR try to resolve?** When a vendored directory is established, cargo add no longer adds new packages. Instead, it tries to translate a package name into a package that already exists in the vendored directory. [More details](#10729 (comment)) Since `@epage` has done most of the work, here I do the rest of the finishing work. Improves the error from #10729 ### **How should we test and review this PR?** The implementation procedure is as follows: #10729 (comment) Test steps: 1. Try to get an arbitrary crate and execute `cargo vendor` command. 2. Configure the vendor directory in .cargo/config.toml. 3. Add `alter-registry` to the config.toml file. ``` [registries] alter-registry= { index = "XXX" } ``` 4. run the same `cargo add` command. ``` cargo add another-crate --registry alter-registry ```
fix(add): Improve error when adding registry packages while vendored ### **What does this PR try to resolve?** When a vendored directory is established, cargo add no longer adds new packages. Instead, it tries to translate a package name into a package that already exists in the vendored directory. [More details](#10729 (comment)) Since `@epage` has done most of the work, here I do the rest of the finishing work. Improves the error from #10729 ### **How should we test and review this PR?** The implementation procedure is as follows: #10729 (comment) Test steps: 1. Try to get an arbitrary crate and execute `cargo vendor` command. 2. Configure the vendor directory in .cargo/config.toml. 3. Add `alter-registry` to the config.toml file. ``` [registries] alter-registry= { index = "XXX" } ``` 4. run the same `cargo add` command. ``` cargo add another-crate --registry alter-registry ```
I didn't quite follow. Does #13281 resolve this? |
Thanks for the reply. #10729 (comment) seems to scope this issue within fuzzy search. Close as resolved via #13281. |
Problem
When a vendored directory is established,
cargo add
no longer adds new packages. Instead, it tries to translate a package name into a package that already exists in the vendored directory.In this case, I've added
xml-rs
, then proceeded to vendor my dependencies. Now, no matter what I try tocargo add
, it always tries to addxml-rs
.I've even tried to run
cargo +beta add cbindgen --registry crates-io
, and it still gives me the same behaviour. The only way I can getcargo add
to work is to remove.cargo/config.toml
file and place it back afterwards.Steps
Commands to run:
Contents of
.cargo/config.toml
:Possible Solution(s)
I assume the reason for this is because what's added in
.cargo/config.toml
is source replacement, meaning any dependencies that try to accesscrates-io
will access the vendored directory instead. I think I understand whycargo add
does what it does here, however I feel it's fairly unintuitive combined with vendoring.I haven't figured out any way to work around this (at least, in a way that I can continue to use
cargo add
). I've tried to add to config.toml:(I've also tried git in place of https, and adding .git to the end of the URL)
and if I try to use
cargo add cbindgen --registry actual-crates
, I get:If I put the following into cargo.toml:
and run the same
cargo add
command, I get the same behaviour:For now, I can easily add my dependencies by modifying
Cargo.toml
myself, however thecargo add
command is very convenient, especially when introducing Rust to a team that's new to the language.Notes
While I am identifying this as a bug (or at least, a problem), I'm not sure what the best way is to fix it.
Making
cargo add
always grab from crates.io, despite a configured source replacement, feels like the wrong way to go about it because it has the potential to break other setups, especially ones that use mirrored (or alternative) registries.Perhaps a flag could be given to
cargo add
? Maybecargo add --no-source-replacement
or something less wordy?Alternatively, maybe there should be a new command
cargo vendor-add
that calls cargo-add code, but without the source replacement? Though that would likely have to be special-cased only to "directory" source-replacement, or you'd need to pass the vendor path as well, like you do withcargo vendor
.Version
The text was updated successfully, but these errors were encountered: