Skip to content
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

Program fails if the [patch.crates-io] section must be considered in order to successfully resolve dependencies #65

Open
NeuralModder opened this issue Jun 30, 2024 · 1 comment

Comments

@NeuralModder
Copy link

Consider the following Cargo.toml.

[package]
name = "test-patch"
version = "0.1.0"
edition = "2021"

[dependencies]
wgpu = "0.18"
egui_wgpu_backend = "0.28"

[patch.crates-io]
wgpu = { git = "https://github.com/Imberflur/wgpu.git", tag = "0.18-with-fixes-for-veloren-v1" }

cargo check works fine here. But running cargo patch gives us this error:

Error: failed to select a version for `web-sys`.
    ... required by package `wgpu v0.18.0`
    ... which satisfies dependency `wgpu = "^0.18"` of package `test-patch v0.1.0 (/home/youser/src/test-patch)`
versions that meet the requirements `^0.3.64` (locked to 0.3.69) are: 0.3.69

the package `wgpu` depends on `web-sys`, with features: `GpuComputePassTimestampWrite` but `web-sys` does not have these features.


failed to select a version for `web-sys` which could resolve this conflict

We also get this error if we remove the [patch.crates-io] section from the Cargo.toml. The patch applied to wgpu is critical in this case, in order for cargo to resolve dependencies, and in consequence, in order for it to do anything at all.
I see that in the resolve_ws function, on lines 171-180, you have:

        let resolve: Resolve = resolve_with_previous(
            &mut registry,
            ws,
            &CliFeatures::new_all(true),
            HasDevUnits::No,
            prev.as_ref(),
            None,
            &[],
            false,
        )?;

That last false is the problem. Of course, if you just change it to true, that'll make the program fail on every project where a given target/patch/{PACKAGE} directory pointed to in the [patch.crates-io] section doesn't exist. Which is the situation you're probably in if you've freshly cloned a repository, or you ran cargo clean in a repository, that uses this program.

A direct solution would be to change the false to true, but (somehow) filter [patch.*] entries with a path pointing to a directory in target/patch out of the workspace being passed into this function. That would work in this case, but not if the patch itself is needed to resolve dependencies correctly (like for example, using cargo patch to apply the patches that make the wgpu fork work to wgpu). The only way to make that work would be to simply not resolve dependencies and just go grab the dependency from Cargo.toml directly, in which case the only way to know for sure which package to pick from crates.io would be to require pinned exact versions (e.g. wgpu = "=0.18.0" instead of wgpu = "0.18"), since you don't know if some transitive dependency actually requires a patch version that's lower than the highest one available. This, of course, doesn't apply to git repositories, which you can just clone (and switch to the branch or tag or commit if specified).

@NeuralModder
Copy link
Author

A note: in this case, the egui_wgpu_backend's wgpu version is different than the specified wgpu version, so you wouldn't want to do this anyway, but the core problem still exists and happens in real-world situations. Good enough for a test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant