-
Notifications
You must be signed in to change notification settings - Fork 432
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
Add wasm_bindgen support #478
Comments
Probably related to the |
The implementation lives here: https://github.com/rust-lang-nursery/rand/blob/0.5.0/src/rngs/os.rs#L696. |
I am unfortunately pretty new to rust (😞) and by my glance I am not sure where the |
Since Rand transitively depends on |
Ah I see maybe that's the cause of it. |
I have the same issue :( here's the full error (for google, and if someone knows more than us 😄 )
|
The Basically, the way the let value = 2;
js! {
console.log( "1 + 1 = ", @{value} );
} is effectively equivalent to this under the hood (I'm simplifying a little): extern "C" {
pub fn __js_1( a1: i32, code: *const u8 ) -> i32;
}
let value = 2;
__js_1( value, r#"console.log( "1 + 1 = ", $0 );"# ); Now what's supposed to happen here (and Since you're not using You could probably work around this issue (this is super hacky though) by creating a module called Ideally we'd come up with a cross-tool ABI of specifying JavaScript snippets (which both |
Thank you @koute, I had a hunch that the |
Thanks @koute for the good explanation! So what I think needs to happen here is we need to support @dhardy Do you think this is a nice 'help wanted' issue to advertise? (Changed the title from "rand with stdweb feature and with --nodejs in wasm_bindgen and wasm32-unknown-unknown target generates unknown 'env' module" to "Add wasm_bindgen support"). |
Yes, agreed @pitdicker. And thanks @koute for helping us out with ha good explanation of the issue. I don't know what the best solution for Rand is, but I guess we don't want |
Here's a quick & dirty fix for the Nevermind, I was wrong 😭 let imports = {};
imports['./wasm_pibench'] = require('./wasm_pibench');
imports['env'] = {__js_1: require('crypto') } // that's what stdweb/rand is trying to import on nodejs
const join = require('path').join;
const bytes = require('fs').readFileSync(join(__dirname, 'wasm_pibench_bg.wasm'));
const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
module.exports = wasmInstance.exports; |
@quininer continuing from our conversation on reddit https://www.reddit.com/r/rust/comments/8msrfp/help_add_wasmbindgen_support_to_rand/ (I like github a bit more).
But would it be possible to link to two custom javascript functions, like (and sorry, didn't recognise your name at first as the author of the |
@pitdicker It's possible, but I don't know if there's any elegant way to do that. |
I am not sure what would make it inelegant, that it needs a *.js file for support? |
|
Ah, it links, but users have to ship both the wasm and js file. No, not very friendly. Do you think you can come up with a solution (I again clearly know too little to be of much use), or should this wait a while to let |
I believe wasm-bindgen will eventually solve the problem. |
This commit adds support to implement the `rand` crate on the wasm32-unknown-unknown target with the `wasm-bindgen`-based runtime. This supports being run both in node.js as well as browsers by delegating appropriately. Closes rust-random#478
This commit adds support to implement the `rand` crate on the wasm32-unknown-unknown target with the `wasm-bindgen`-based runtime. This supports being run both in node.js as well as browsers by delegating appropriately. Closes rust-random#478
This commit adds support to implement the `rand` crate on the wasm32-unknown-unknown target with the `wasm-bindgen`-based runtime. This supports being run both in node.js as well as browsers by delegating appropriately. Closes rust-random#478
This commit adds support to implement the `rand` crate on the wasm32-unknown-unknown target with the `wasm-bindgen`-based runtime. This supports being run both in node.js as well as browsers by delegating appropriately. Closes rust-random#478
This commit adds support to implement the `rand` crate on the wasm32-unknown-unknown target with the `wasm-bindgen`-based runtime. This supports being run both in node.js as well as browsers by delegating appropriately. Closes rust-random#478
This commit adds support to implement the `rand` crate on the wasm32-unknown-unknown target with the `wasm-bindgen`-based runtime. This supports being run both in node.js as well as browsers by delegating appropriately. Closes rust-random#478
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:
And the created file looks like this:
Therefore running in node throws an unknown
env
module error.This seems to only happen when my Cargo.toml includes:
The text was updated successfully, but these errors were encountered: