Skip to content

Add WebAssembly example embedded in web page #599

Description

@agentydragon

I'd like to compile Rust into WebAssembly, roll it up into a single WebAssembly (and/or JS file) and run it in a web browser. I've been having some trouble getting it to run.

(rust_wasm_bindgen generates JS / WASM with imports from other modules.)

I'm trying to use rollup_bundle from rules_nodejs, with @rollup/plugin-wasm, and am getting this error message:

bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen.js → bazel-out/k8-fastbuild/bin/wasm/bundle...
(!) Missing exports
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.js
memory is not exported by bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.wasm
 9: let cachegetUint8Memory0 = null;
10: function getUint8Memory0() {
11:     if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
                                                                                  ^
12:         cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
13:     }
bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.js
memory is not exported by bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.wasm
10: function getUint8Memory0() {
11:     if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
12:         cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
                                                       ^
13:     }
14:     return cachegetUint8Memory0;
bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.js
memory is not exported by bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.wasm
10: function getUint8Memory0() {
11:     if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
12:         cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
                                                       ^
13:     }
14:     return cachegetUint8Memory0;
bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen.js
__wbindgen_start is not exported by bazel-out/k8-fastbuild/bin/wasm/main_wasm_bindgen_bg.wasm
1: import * as wasm from "./main_wasm_bindgen_bg.wasm";
2: export * from "./main_wasm_bindgen_bg.js";
3: wasm.__wbindgen_start();
        ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions