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

Import wasm_bindgen in macros #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coolreader18
Copy link

This would fix (or make unnecessary) brendanzab/gl-rs#528, which was an attempt to fix webgl_stdweb compiling under wasm-pack/wasm-bindgen. It was giving me these kind of errors:

❯ cargo c --target wasm32-unknown-unknown
    Checking webgl_stdweb v0.3.0 (/home/coolreader18/gl-rs/webgl_stdweb)
error[E0433]: failed to resolve: use of undeclared type or module `wasm_bindgen`
    --> /home/coolreader18/gl-rs/target/wasm32-unknown-unknown/debug/build/webgl_stdweb-fd022828f1f02c5e/out/bindings.rs:5789:9
     |
5789 | /         js!(
5790 | |             return true;
5791 | |         ).try_into().unwrap()
     | |_________^ use of undeclared type or module `wasm_bindgen`
     |
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `wasm_bindgen`
    --> /home/coolreader18/gl-rs/target/wasm32-unknown-unknown/debug/build/webgl_stdweb-fd022828f1f02c5e/out/bindings.rs:5769:24
     |
5769 | #[derive(Debug, Clone, ReferenceType)]
     |                        ^^^^^^^^^^^^^ use of undeclared type or module `wasm_bindgen`
     |
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type or module `wasm_bindgen`
    --> /home/coolreader18/gl-rs/target/wasm32-unknown-unknown/debug/build/webgl_stdweb-fd022828f1f02c5e/out/bindings.rs:5760:24
     |
5760 | #[derive(Debug, Clone, ReferenceType)]
     |                        ^^^^^^^^^^^^^ use of undeclared type or module `wasm_bindgen`
     |
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
... 1600 total errors 

I was able to patch it by just adding wasm-bindgen as a dep to webgl_stdweb, but I realized I was also able to fix it directly in stdweb by importing wasm_bindgen inside the js!()/derive(ReferenceType) macros. I think it was failing because wasm-bindgen's macros expect to be able to access wasm_bindgen, but because crates invoking the stdweb macros that invoke the wasm-bindgen macros don't necessarily have wasm_bindgen in scope, it might fail to compile.

@coolreader18
Copy link
Author

Oh... I guess this is related to/duplicate of #390

@coolreader18
Copy link
Author

@koute could you review this?

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 this pull request may close these issues.

1 participant