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

Compile failure if the crate using the wasm_init! macro does not itself depend on wasm_bindgen. #1

Closed
kyren opened this issue Aug 27, 2023 · 2 comments · Fixed by #2

Comments

@kyren
Copy link
Contributor

kyren commented Aug 27, 2023

I don't know how to solve this, but the #[wasm_bindgen] proc macro does not appear to support renaming the wasm_bindgen crate to something else, and refers to the module path wasm_bindgen in the expanded output. This causes wasm_init! to not compile if the caller does not itself depend on wasm_bindgen.

I implemented a replacement for the inventory crate using ctor and wasm-init. Calling inventory::submit! without depending on wasm_bindgen produces get the following output:

error[E0433]: failed to resolve: use of undeclared crate or module `wasm_bindgen`
  --> src/core/src/scripting/globals.rs:39:1
   |
39 | / inventory::submit!(GlobalLib::new("serde global markers", |ctx| {
40 | |     scripting::serde::global_markers(ctx);
41 | |     Ok(())
42 | | }));
   | |___^ use of undeclared crate or module `wasm_bindgen`
   |
   = note: this error originates in the attribute macro `$crate::__macrodeps::wasm_bindgen` which comes from the expansion of the macro `inventory::submit` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `FUNCTION` in this scope
  --> src/core/src/scripting/globals.rs:39:1
   |
39 | / inventory::submit!(GlobalLib::new("serde global markers", |ctx| {
40 | |     scripting::serde::global_markers(ctx);
41 | |     Ok(())
42 | | }));
   | |___^ not found in this scope
   |
   = note: this error originates in the attribute macro `$crate::__macrodeps::wasm_bindgen` which comes from the expansion of the macro `inventory::submit` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0405]: cannot find trait `WasmDescribe` in this scope
  --> src/core/src/scripting/globals.rs:39:1
   |
39 | / inventory::submit!(GlobalLib::new("serde global markers", |ctx| {
40 | |     scripting::serde::global_markers(ctx);
41 | |     Ok(())
42 | | }));
   | |___^ not found in this scope
   |
   = note: this error originates in the attribute macro `$crate::__macrodeps::wasm_bindgen` which comes from the expansion of the macro `inventory::submit` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find function `inform` in this scope
  --> src/core/src/scripting/globals.rs:39:1
   |
39 | / inventory::submit!(GlobalLib::new("serde global markers", |ctx| {
40 | |     scripting::serde::global_markers(ctx);
41 | |     Ok(())
42 | | }));
   | |___^ not found in this scope
   |
   = note: this error originates in the attribute macro `$crate::__macrodeps::wasm_bindgen` which comes from the expansion of the macro `inventory::submit` (in Nightly builds, run with -Z macro-backtrace for more info)
@kyren
Copy link
Contributor Author

kyren commented Aug 28, 2023

I have a solution incoming...

kyren added a commit to kyren/wasm-init that referenced this issue Aug 28, 2023
…e same time.

Drops the `paste` crate and does not bother to use `#[wasm_bindgen]` to
generate the exported init function. Instead, exports a plain `extern
"C"` function and uses uses `#[export = name]` to set its name, as
`wasm-bindgen` would have done.

This is both simpler, and also does not require that the calling crate
have `wasm_bindgen` as a direct dependency, so it fixes returnString#1 at the same
time.
kyren added a commit to kyren/wasm-init that referenced this issue Aug 28, 2023
…e same time.

Drops the `paste` crate and does not bother to use `#[wasm_bindgen]` to
generate the exported init function. Instead, exports a plain `extern
"C"` function and uses uses `#[export = name]` to set its name, as
`wasm-bindgen` would have done.

This is both simpler, and also does not require that the calling crate
have `wasm_bindgen` as a direct dependency, so it fixes returnString#1 at the same
time.
kyren added a commit to kyren/wasm-init that referenced this issue Aug 28, 2023
…e same time.

Drops the `paste` crate and does not bother to use `#[wasm_bindgen]` to
generate the exported init function. Instead, exports a plain `extern
"C"` function and uses uses `#[export = name]` to set its name, as
`wasm-bindgen` would have done.

This is both simpler, and also does not require that the calling crate
have `wasm_bindgen` as a direct dependency, so it fixes returnString#1 at the same
time.
returnString pushed a commit that referenced this issue Aug 28, 2023
Drops the `paste` crate and does not bother to use `#[wasm_bindgen]` to
generate the exported init function. Instead, exports a plain `extern
"C"` function and uses uses `#[export = name]` to set its name, as
`wasm-bindgen` would have done.

This is both simpler, and also does not require that the calling crate
have `wasm_bindgen` as a direct dependency, so it fixes #1 at the same
time.
@returnString
Copy link
Owner

Fixed in 0.2.2

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

Successfully merging a pull request may close this issue.

2 participants