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

rust wasm-pack compatibility #269

Closed
benmkw opened this issue Mar 17, 2020 · 3 comments
Closed

rust wasm-pack compatibility #269

benmkw opened this issue Mar 17, 2020 · 3 comments

Comments

@benmkw
Copy link

benmkw commented Mar 17, 2020

  • Rollup Plugin Name: wasm
  • Rollup Plugin Version: ^3.0.0
  • Rollup Version: ^1.20.0
  • Operating System (or Browser): Version 1.4.96 Chromium: 80.0.3987.132 (Official Build) (64-bit)
  • Node Version: v13.11.0

How Do We Reproduce?

Expected Behavior

bundling wasm created using wasmpack https://rustwasm.github.io/wasm-pack/book/

Note:
I used the rollup config from the default svelte template as a starting point, this issue might also be an issue with svelte instead of rollup.

Actual Behavior

may be nearly working but some steps remain where I want to try to help figure out what they are

I created a repository with a minimal example where I tried to provide as much information as possible such that you don't necessarily need to install rust tooling in order to investigate the bug https://github.com/benmkw/svelte_rust_test . I can provide further information if needed.

short overview of the issue is the following:

rust_wasm.js:9 Uncaught TypeError: undefined is not a function
    at add (rust_wasm.js:9)
    at Object.create [as c] (App.svelte:8)
    at init (index.mjs:1410)
    at new App (App.svelte:3)
    at main.js:3
    at main.js:8
add @ rust_wasm.js:9
create @ App.svelte:8
init @ index.mjs:1410
App @ App.svelte:3
(anonymous) @ main.js:3
(anonymous) @ main.js:8

because in in bundle.js:

    function add(a, b) {
        var ret = undefined(a, b);
        return ret;
    }

rollup seems to optimize the call away

function rust_wasm_bg(imports){return _loadWasmModule(0, 'AGFzbQEAAAABBwFgAn9/AX8DAgEABQMBABEHEAIGbWVtb3J5AgADYWRkAAAKDQELACAAIAFqQf8BcQsLUgEAQaSIwAALSQEAAAAAAAAAAQAAAAIAAAADAAAABAAAAAUAAAAAAAAAAQAAAAIAAAADAAAABAAAAAYAAAAEAAAABAAAAAcAAAAIAAAACQAAAAoAgwEJcHJvZHVjZXJzAghsYW5ndWFnZQEEUnVzdAAMcHJvY2Vzc2VkLWJ5AwVydXN0YyUxLjQzLjAtbmlnaHRseSAoNTY0NzU4YzRjIDIwMjAtMDMtMDgpBndhbHJ1cwYwLjE0LjAMd2FzbS1iaW5kZ2VuEjAuMi41OSAoZGI4ZDNlNDQxKQ==', imports)}

var wasm = /*#__PURE__*/Object.freeze({
        __proto__: null,
        'default': rust_wasm_bg
    });

As far as I can see the wasm module gets embedded into the js file but _loadWasmModule is never actually called, so this might actually be very close to being in a working state.

@benmkw
Copy link
Author

benmkw commented Mar 26, 2020

I removed svelte from the equation thus the bundle.js is now really small.
The missing piece seems to be support for import await foo from bar.
Unfortunately I have not yet figured out if import await is a thing thats standardized/ likely be supported by rollup thus not sure how to go from here.

As can be seen in https://github.com/webpack/webpack/tree/master/examples/wasm-simple this would make it possible to call functions from a wasm module without worrying about async things (added to webpack here webpack/webpack#6615 (comment)).

@benmkw
Copy link
Author

benmkw commented Mar 26, 2020

as mentioned in rustwasm/wasm-pack#699 (comment) fixed by other wasm rollup plugin which is specifically designed for rust interop https://github.com/wasm-tool/rollup-plugin-rust

@benmkw benmkw closed this as completed Mar 26, 2020
@shellscape
Copy link
Collaborator

Thanks. I've added that plugin to our awesome list: rollup/awesome@d5826ee

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

No branches or pull requests

2 participants