Cargo 不使用 web-sys 依赖项的 nokhwa bc 构建 winit

问题描述 投票:0回答:1

我有一个基于 winit crate 的 Rust 项目,我也想向其中添加 nokhwa crate,但现在由于一些奇怪的依赖错误,cargo 甚至无法编译它:

error: failed to select a version for `web-sys`.
    ... required by package `wgpu v0.11.0`
    ... which satisfies dependency `wgpu = "^0.11"` of package `nokhwa v0.9.4`
    ... which satisfies dependency `nokhwa = "^0.9.4"` of package `winit_wgpu_test v0.1.0 (C:\schabby\Rust\winit_wgpu_test)`
versions that meet the requirements `^0.3.53` are: 0.3.67, 0.3.66, 0.3.65, 0.3.64, 0.3.63, 0.3.62, 0.3.61, 0.3.60, 0.3.59, 0.3.58, 0.3.57, 0.3.56, 0.3.55, 0.3.54, 0.3.53

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


all possible versions conflict with previously selected packages.

  previously selected package `web-sys v0.3.64`
    ... which satisfies dependency `web-sys = "^0.3.53"` of package `wgpu v0.11.0`
    ... which satisfies dependency `wgpu = "^0.11"` of package `nokhwa v0.9.4`
    ... which satisfies dependency `nokhwa = "^0.9.4"` of package `winit_wgpu_test v0.1.0 (C:\schabby\Rust\winit_wgpu_test)`

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

这是我的货物.toml:

[dependencies]
env_logger = "0.10.0"
pollster = "0.3.0"
winit = { version = "0.29.10", features = ["rwh_05"]}

[dependencies.nokhwa]
version = "0.9.4"
features = ["input-msmf", "output-wgpu"]

注意: 是的,使用最新版本的 nokhwa 这不是问题,但我必须使用 nokhwa 0.9.4,因为在较新的版本中,“output-wgpu”功能已损坏,而我需要它。

我的理解是,在 web-sys 中,“GpuBufferUsage”功能被重命名为“gpu_buffer_usage”(我从这里发现:https://www.reddit.com/r/rust/comments/xcsls9/comment/ io8pmam/

此外,在 web-sys 源代码的相关部分 - https://rustwasm.github.io/wasm-bindgen/api/src/web_sys/features/gen_gpu_buffer_usage.rs.html - 我看到这个:

#[cfg(web_sys_unstable_apis)]
    #[doc = "The `GPUBufferUsage.MAP_READ` const."]
    #[doc = ""]
    #[doc = "*This API requires the following crate features to be activated: `gpu_buffer_usage`*"]
    #[doc = ""]
    #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
    #[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]

因此,我尝试在启用

--cfg=web_sys_unstable_apis
的情况下构建我的项目,但无济于事。 我通过设置全局环境变量(重新启动计算机)和在 PowerShell(我在 Windows 11 上)中进行了尝试,如下所示:

$env:CARGO_ENCODED_RUSTFLAGS="--cfg=web_sys_unstable_apis"; cargo build

甚至在我的cargo.toml中:

[build]
CARGO_ENCODED_RUSTFLAGS = "--cfg=web_sys_unstable_api"

甚至简单地使用 RUSTFLAGS 而不是 CARGO_ENCODED_RUSTFLAGS,但一切都是一样的。

知道如何解决这个问题吗?

rust rust-cargo web-sys winit
1个回答
0
投票

在这种特定情况下,您只需选择:

  1. 针对 wgpu
    v0.11 分支
    制作 PR,并更改重命名的功能(要求您将
    web-sys
    箱更新到较新的版本)。这还需要发布到
    crates.io
    ,这就是为什么您可能需要使用 本地补丁版本或您自己的存储库中的版本(例如 winit v0.11 的分支)。
  2. 使用
    winit
    版本
    0.28.x
    ,因为这样
    web-sys
    v0.3.53
    (确实具有
    GpuBufferUsage
    功能;等等)仍然可以与
    winit
    一起使用。
© www.soinside.com 2019 - 2024. All rights reserved.