Skip to content

Add wasm_bindgen support #478

@mbalex99

Description

@mbalex99

Glad to see that rand is adding wasm support. However using wasm_bindgen to build towards nodejs we get a build artifact with an unknown require('env')

The make file to run the building is:

build-wasm-dev:
	cargo build --target wasm32-unknown-unknown; \
	mkdir -p dist; \
	wasm-bindgen target/wasm32-unknown-unknown/debug/ditto.wasm --out-dir ./dist --nodejs

And the created file looks like this:

let imports = {};
imports['./ditto'] = require('./ditto');
imports['env'] = require('env'); // HERE, what is this?

            const join = require('path').join;
            const bytes = require('fs').readFileSync(join(__dirname, 'ditto_bg.wasm'));
            const wasmModule = new WebAssembly.Module(bytes);
            const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
            module.exports = wasmInstance.exports;

Therefore running in node throws an unknown env module error.

This seems to only happen when my Cargo.toml includes:

rand = {version = "0.5.0", features = ['stdweb']}

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-new-extFunctionality: new, outside of RandP-postponeWaiting on something else

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions