-
Notifications
You must be signed in to change notification settings - Fork 25
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
[FR] Making bundler mode working #7
Comments
You do not need to use Also, your import is incorrect, you are supposed to import the import init from "./path/to/Cargo.toml"; You should never import any of the files inside of the |
My application runs in Nodejs. The web mode does not work in Node. The bundler or nodejs work. For example, |
Ah, yes, that's a good point. I should change it so that when the |
#6 is necessary for that so we know which target the user wants. I am working on fixing the imports. After that, we can fully support the bundler mode. |
@aminya As for Node support, that is unrelated to In the meantime, you can use |
Unfortunately Rollup doesn't allow for checking @xtuc Can I get commit writes again, so I can push the changes? |
Could you put some lights on the reasons and disclose them, so we can fix them? We can contribute to wasm-pack for fixing that. I am interested to fix this issue once for Rollup. In a simple example, wasm-pack generates the following code in bundler mode. This is just a simple JavaScript wrapper for importing the exports of the wasm file. So Rollup should find a way to instantiate wasm and load the code. import * as wasm from './index_bg.wasm';
/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
export function add(a, b) {
var ret = wasm.add(a, b);
return ret >>> 0;
}
let cachegetFloat64Memory0 = null;
function getFloat64Memory0() {
if (cachegetFloat64Memory0 === null || cachegetFloat64Memory0.buffer !== wasm.memory.buffer) {
cachegetFloat64Memory0 = new Float64Array(wasm.memory.buffer);
}
return cachegetFloat64Memory0;
}
let WASM_VECTOR_LEN = 0;
function passArrayF64ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 8);
getFloat64Memory0().set(arg, ptr / 8);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
/**
* @param {Float64Array} arr
* @returns {number}
*/
export function sum(arr) {
var ptr0 = passArrayF64ToWasm0(arr, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.sum(ptr0, len0);
return ret;
} cc: @xtuc |
@xtuc Thanks! @aminya I just published version 1.0.4 which adds in a The reason why import * as wasm from './index_bg.wasm'; The ability to import On the other hand, Using However, That's why I said that it's pointless to support a The same goes for |
Thanks for reporting the issue with Node, since it has been fixed, I'm going to close this. |
This is an issue in Rollup. Once this is solved we will get back to this. |
I added the bundler option in #6. To make
budnler
mode work, I had to also use"@rollup/plugin-wasm"
. However, I get an error using the two examples for importing Cargo.toml.The text was updated successfully, but these errors were encountered: