Getting errors in `wgpu` crate when used as a dependency of `wonnx`

When I try and build my project, I get these errors in the wgpu crate, which is a dependency of the wonnx crate that I am using.

❯ $env:RUSTFLAGS="--cfg=web_sys_unstable_apis"; wasm-pack build --target bundler
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
[ME]: Truncated output for stackoverflow                                                                                                                                                                                                        
   Compiling wgpu v0.16.3                                                                                                                                                                                                          
error[E0061]: this function takes 1 argument but 2 arguments were supplied                                                                                                                                                         
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:1523:13
     |
1523 |             web_sys::GpuVertexState::new(desc.vertex.entry_point, &module.0);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -------------------------
     |                                          |
     |                                          unexpected argument of type `&str`
     |                                          help: remove the extra argument
     |
note: associated function defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuVertexState.rs:27:12
     |
27   |     pub fn new(module: &GpuShaderModule) -> Self {
     |            ^^^

error[E0061]: this function takes 2 arguments but 3 arguments were supplied                                                                                                                                                        
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:1598:17
     |
1598 |                 web_sys::GpuFragmentState::new(frag.entry_point, &module.0, &targets);
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----------------             -------- unexpected argument of type `&Array`
     |                                                |
     |                                                expected `&GpuShaderModule`, found `&str`
     |
     = note: expected reference `&GpuShaderModule`
                found reference `&str`
note: associated function defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuFragmentState.rs:27:12
     |
27   |     pub fn new(module: &GpuShaderModule, targets: &::wasm_bindgen::JsValue) -> Self {
     |            ^^^
help: remove the extra argument
     |
1598 -                 web_sys::GpuFragmentState::new(frag.entry_point, &module.0, &targets);
1598 +                 web_sys::GpuFragmentState::new(/* &GpuShaderModule */, &module.0);
     |

error[E0061]: this function takes 1 argument but 2 arguments were supplied
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:1623:13
     |
1623 |             web_sys::GpuProgrammableStage::new(desc.entry_point, &shader_module.0);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------------------
     |                                                |
     |                                                unexpected argument of type `&str`
     |                                                help: remove the extra argument
     |
note: associated function defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuProgrammableStage.rs:27:12
     |
27   |     pub fn new(module: &GpuShaderModule) -> Self {
     |            ^^^

error[E0599]: no method named `write_timestamp` found for struct `GpuCommandEncoder` in the current scope                                                                                                                          
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2304:14
     |
2302 | /         encoder_data
2303 | |             .0
2304 | |             .write_timestamp(&query_set_data.0, query_index);
     | |             -^^^^^^^^^^^^^^^ method not found in `GpuCommandEncoder`
     | |_____________|
     | 

error[E0308]: mismatched types                                                                                                                                                                                                     
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2556:17
     |
2554 |             .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length(
     |              --------------------------------------------------------------------- arguments to this method are incorrect
2555 |                 index,
2556 |                 &bind_group_data.0,
     |                 ^^^^^^^^^^^^^^^^^^ expected `Option<&GpuBindGroup>`, found `&GpuBindGroup`
     |
     = note:   expected enum `Option<&GpuBindGroup>`
             found reference `&GpuBindGroup`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuComputePassEncoder.rs:201:12
     |
201  |     pub fn set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2556 |                 Some(&bind_group_data.0),
     |                 +++++                  +

error[E0308]: mismatched types
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2681:17
     |
2679 |             .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length(
     |              --------------------------------------------------------------------- arguments to this method are incorrect
2680 |                 index,
2681 |                 &bind_group_data.0,
     |                 ^^^^^^^^^^^^^^^^^^ expected `Option<&GpuBindGroup>`, found `&GpuBindGroup`
     |
     = note:   expected enum `Option<&GpuBindGroup>`
             found reference `&GpuBindGroup`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuRenderBundleEncoder.rs:131:12
     |
131  |     pub fn set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2681 |                 Some(&bind_group_data.0),
     |                 +++++                  +

error[E0308]: mismatched types
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2731:21
     |
2729 |                 encoder_data.0.set_vertex_buffer_with_f64_and_f64(
     |                                ---------------------------------- arguments to this method are incorrect
2730 |                     slot,
2731 |                     &buffer_data.0,
     |                     ^^^^^^^^^^^^^^ expected `Option<&GpuBuffer>`, found `&GpuBuffer`
     |
     = note:   expected enum `Option<&GpuBuffer>`
             found reference `&GpuBuffer`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuRenderBundleEncoder.rs:617:12
     |
617  |     pub fn set_vertex_buffer_with_f64_and_f64(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2731 |                     Some(&buffer_data.0),
     |                     +++++              +

error[E0308]: mismatched types
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2739:55
     |
2739 |                     .set_vertex_buffer_with_f64(slot, &buffer_data.0, offset as f64);
     |                      --------------------------       ^^^^^^^^^^^^^^ expected `Option<&GpuBuffer>`, found `&GpuBuffer`
     |                      |
     |                      arguments to this method are incorrect
     |
     = note:   expected enum `Option<&GpuBuffer>`
             found reference `&GpuBuffer`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuRenderBundleEncoder.rs:546:12
     |
546  |     pub fn set_vertex_buffer_with_f64(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2739 |                     .set_vertex_buffer_with_f64(slot, Some(&buffer_data.0), offset as f64);
     |                                                       +++++              +

error[E0308]: mismatched types
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2896:17
     |
2894 |             .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length(
     |              --------------------------------------------------------------------- arguments to this method are incorrect
2895 |                 index,
2896 |                 &bind_group_data.0,
     |                 ^^^^^^^^^^^^^^^^^^ expected `Option<&GpuBindGroup>`, found `&GpuBindGroup`
     |
     = note:   expected enum `Option<&GpuBindGroup>`
             found reference `&GpuBindGroup`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuRenderPassEncoder.rs:218:12
     |
218  |     pub fn set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2896 |                 Some(&bind_group_data.0),
     |                 +++++                  +

error[E0308]: mismatched types
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2946:21
     |
2944 |                 pass_data.0.set_vertex_buffer_with_f64_and_f64(
     |                             ---------------------------------- arguments to this method are incorrect
2945 |                     slot,
2946 |                     &buffer_data.0,
     |                     ^^^^^^^^^^^^^^ expected `Option<&GpuBuffer>`, found `&GpuBuffer`
     |
     = note:   expected enum `Option<&GpuBuffer>`
             found reference `&GpuBuffer`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuRenderPassEncoder.rs:704:12
     |
704  |     pub fn set_vertex_buffer_with_f64_and_f64(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2946 |                     Some(&buffer_data.0),
     |                     +++++              +

error[E0308]: mismatched types
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fwgpu-0.16.3srcbackendweb.rs:2954:55
     |
2954 |                     .set_vertex_buffer_with_f64(slot, &buffer_data.0, offset as f64);
     |                      --------------------------       ^^^^^^^^^^^^^^ expected `Option<&GpuBuffer>`, found `&GpuBuffer`
     |                      |
     |                      arguments to this method are incorrect
     |
     = note:   expected enum `Option<&GpuBuffer>`
             found reference `&GpuBuffer`
note: method defined here
    --> C:Usersjacob.cargoregistrysrcindex.crates.io-6f17d22bba15001fweb-sys-0.3.69srcfeaturesgen_GpuRenderPassEncoder.rs:633:12
     |
633  |     pub fn set_vertex_buffer_with_f64(
     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: try wrapping the expression in `Some`
     |
2954 |                     .set_vertex_buffer_with_f64(slot, Some(&buffer_data.0), offset as f64);
     |                                                       +++++              +

   Compiling num v0.4.3                                                                                                                                                                                                            
Some errors have detailed explanations: E0061, E0308, E0599.                                                                                                                                                                       
For more information about an error, try `rustc --explain E0061`.
   Compiling futures v0.3.30
error: could not compile `wgpu` (lib) due to 11 previous errors                                                                                                                                                                    
warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed                                                                                                                                                                                  
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
[package]
name = "wonnx-repro"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
wasm-bindgen = "0.2.92"
web-sys = { version = "0.3.69" }
wonnx = "0.5.1"

lib.rs can be empty.

Please see the complete repro repo at jacobhq/wonnx-repro

Output of cargo tree in this gist due to stackoverflow length limits.

I tried:

  • Updating my crates with cargo update
  • Adding crate wgpu (0.20.1 as a direct dependency in cargo.toml
  • Asking various LLMs (ChatGPT, Claude, Gemini etc.), who were unhelpful
  • Searching through GitHub issues in webonnx/wonnx, finding nothing

If this is a known issue, and I’m being dumb, please point it out in the comments. If you’ve never heard of it before, please also comment, and I’ll end up opening a GitHub issue (maybe a better place to start I know).

Thank you!

0

You are specifying web_sys_unstable_apis, which is, by definition, unstable. That is, changes can occur in the APIs across minor versions.

This is what happened here. wonnx relies on an old, and unmaintained, version of wgpu (0.16). That versions relies on some old version of web-sys (0.3.61). web-sys has gained new minor versions since, and minor versions promise to keep the API the same, but excluding unstable APIs. Cargo used the newer web-sys versions (because they are SemVer-compatible), which broke wgpu.

The real fault here is probably of wgpu, since when relying on unstable APIs, you should generally specify a precise version requirement (=version) exactly to avoid situations like that. But I can understand people are hesitant to use precise requirements, since they can break in various ways.

The fault is also partially of wonnx, by not updating to the newer wgpu version. This is something you can open an issue about, but I don’t know how much work it will be to update to the current wgpu version, since it is SemVer-incompatible.

Other than waiting for wonnx to upgrade their wgpu, the easiest fix is to pin web-sys version’s yourself. That means patching wgpu. Instead of cloning wgpu, an easier way will be to copy it from your registry cache, normally located in <home>/.cargo/registry/src/index.crates.io-<some_hash>. Find the wgpu-0.16.3 directory there (it will be there if you already tried to build your project, if not you can specify it as a dependency some temporary project and cargo fetch), copy it, change Cargo.toml in the lines:

[target."cfg(target_arch = "wasm32")".dependencies.web-sys]
features = [...]
version = "0.3.61"

...

[target."cfg(target_arch = "wasm32")".dev-dependencies.web-sys]
features = [...]
version = "0.3.61"

To:

[target."cfg(target_arch = "wasm32")".dependencies.web-sys]
features = [...]
version = "=0.3.61"

...

[target."cfg(target_arch = "wasm32")".dev-dependencies.web-sys]
features = [...]
version = "=0.3.61"

Then in your project’s Cargo.toml, include this:

[patch.crates-io]
wgpu = { path = "../path/to/your/wgpu/clone" }

You also need to update your web-sys version to =0.3.61.

And that’s it!

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật