koute / stdweb

A standard library for the client-side Web
Apache License 2.0
3.45k stars 177 forks source link

Not compiling with newest version of dependencies #427

Open bobbobbio opened 1 year ago

bobbobbio commented 1 year ago

After updating wasm-bindgen to 0.2.86 (I think) I get a compilation error when trying to compile with wasm This was with rustc 1.71.0-nightly (5ea3f0ae0 2023-05-23) but fails on stable also

error[E0433]: failed to resolve: unresolved import
  --> src/webcore/ffi/wasm_bindgen.rs:67:32
   |
67 |             alloc: &Closure< Fn( usize ) -> *mut u8 >,
   |                                ^ unresolved import

error[E0425]: cannot find function `wasm_bindgen_initialize` in this scope
  --> src/webcore/ffi/wasm_bindgen.rs:77:22
   |
77 |         let module = wasm_bindgen_initialize( memory, table, &alloc, &free );
   |                      ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
eduardvercaemer commented 1 year ago

For anyone trying to get around this you can try this in your Cargo.toml

wasm-bindgen = "=0.2.84"
rdbisme commented 1 year ago

Hello, downgrading wasm-bindgen is a no-go for me since I need to use the latest version of the Cloudflare workers rust runtime, and they pin to wasm-bindgen=0.2.86.

Is there another way of fixing this?

sdasda7777 commented 1 year ago

Jeez, I'm not pinned to a higher version, but why did I have to waste three hours debugging this?

Dampfwalze commented 9 months ago

The suggestion by @eduardvercaemer does fix the compile error, but pinning wasm-bindgen has other undesired impacts for me and really should not be the solution to the problem.

I think I found the issue! It is within these lines (Exactly where the error points to):

https://github.com/koute/stdweb/blob/9b418d98df6fafaa4d4b87b04c304d0220292055/src/webcore/ffi/wasm_bindgen.rs#L63-L70

I couldn't make sense of the error, but I looked at the docs of the Closure struct. Interestingly, in the examples, it is always used with the dyn keyword, which makes sense. The fix looks like this:

Closure<dyn Fn(...) -> ...>

On line 75 and 76 there is a warning: trait objects without an explicit 'dyn' are deprecated. I guess historically, rust implicitly added the dyn keyword, but at some point that feature got removed... Probably for the better. But since this package does not receive any updates (for 5 years, FIVE YEARS!!!), it is full of similar deprecation warnings that are never fixed. This is just the first instance where it broke. I am not sure why it works when pinning wasm_bindgen though.

This crate really needs a general overhaul to fix all the warnings! It has thousands of dependents, it is crucial that this crate does not brake! @koute

sigmasoldi3r commented 4 months ago

So the project is abandoned then? I was hoping to use it as a way of integrating 3rd party libraries with no Rust bindings (Like Chart.js).

Any suggestion for automatic binding generation for such libraries?

joe-p commented 2 days ago

Thank you @Dampfwalze for #429! Unfortunately this repo seems to be abandoned so this likely will never get merged.

For anyone that is encountering this issue you can patch the version of stdweb your dependencies are using by adding the following to your cargo.toml

[patch.crates-io]
stdweb = { git = "https://github.com/Dampfwalze/stdweb/", rev = "a0086b4bd9b3116edeb679fe0ca477d48e06bb32" }

The diff between this commit and the latest tagged release is minimal so I wouldn't anticipate anything breaking. If you do, however, encounter problems then you can cherry pick the commit in #429 and apply it to whatever version of stdweb is needed. The long term solution is to get crates to start using the patched version.