wasm-bindgen

Rollup: bundling/embedding wasm code from an external module

流过昼夜 提交于 2020-07-22 16:59:06
问题 Using rollup, I'm trying to bundle a typescript library that imports and calls an npm module that contains a wasm file. Only the resulting bundle contains no trace of the wasm file contents. How can I force it to bundle the webassembly too ? Here's the key files from what I've tried: // typescript/src/index.ts import * as libEd from "ed25519-raw"; export const seed_from_phrase = libEd.seed_from_phrase; export const gen_keypair = libEd.gen_keypair; My package.json is { "name": "ed25519",

Rollup: bundling/embedding wasm code from an external module

妖精的绣舞 提交于 2020-07-22 16:58:44
问题 Using rollup, I'm trying to bundle a typescript library that imports and calls an npm module that contains a wasm file. Only the resulting bundle contains no trace of the wasm file contents. How can I force it to bundle the webassembly too ? Here's the key files from what I've tried: // typescript/src/index.ts import * as libEd from "ed25519-raw"; export const seed_from_phrase = libEd.seed_from_phrase; export const gen_keypair = libEd.gen_keypair; My package.json is { "name": "ed25519",

Using rug in Rust with wasm-bindgen

偶尔善良 提交于 2020-07-10 07:44:43
问题 I'd like to use the rug crate with wasm-bindgen to allow me to use arbitrary-precision arithmetic in a web browser. Whenever I try to compile, though, it fails to build the library, saying something along the lines of unresolved imports libc::c_char , libc::c_int , libc::c_long . Is there a workaround for this? If Emscripten is involved that's fine, but I'd like to be able to mostly write Rust code. 回答1: rug depends on libc I found https://github.com/rust-lang/libc/issues/858#issuecomment

Rust wasm: How to access Webassembly.Memory of current instance (from Rust)?

五迷三道 提交于 2020-05-17 06:21:46
问题 Looking at the function signature of js_sys::Uint8Array::new_with_byte_offset_and_length pub fn new_with_byte_offset_and_length( buffer: &JsValue, byte_offset: u32, length: u32 ) -> Uint8Array It needs an argument buffer which refers to the current wasm instance's memory buffer. How do I access such an object from the Rust side ? (that gets compiled to wasm) 回答1: It needs an argument buffer which refers to the current wasm instance's memory buffer. First of all, it's worth noting that this is

Wasm-bindgen: access wasm instance's memory buffer (from JS)

≯℡__Kan透↙ 提交于 2020-04-16 06:07:20
问题 According to this github comment, I can re-create an Uint8ClampedArray or Uint8Array returned from Rust/wasm by accessing the memory of the wasm instance directly: const textureRaw = new Uint8ClampedArray(memory.buffer, texture.offset(), texture.size()); The thing is, the js files generated by wasm-bindgen already instantiate a wasm instance, and I'd want to access the memory of this particular instance but it doesn't seem to be exported: // XXXXX_bg.js const path = require('path').join(_

How do I apply a macro attribute to a function defined in a separate module?

半世苍凉 提交于 2019-12-31 05:09:13
问题 I'm interested in using wasm-bindgen via rust-webpack-template to compile Rust code to WebAssembly. However, I'd like to avoid directly wrapping my code with the #[wasm_bindgen] attribute macro directly so that I can separate out the function logic from the generated WebAssembly interface to better organize my project. Instead, I would prefer to have binding generation be in a separate file, for example: mod my_code; use my_code::my_function; #[wasm_bindgen] my_function; // I want to do

Rust WebAssembly Custom Elements Memory Deallocation Error

梦想的初衷 提交于 2019-12-13 15:08:06
问题 My first Rust-produced WASM is producing the following error, I have no idea how to go about it debugging. wasm-000650c2-23:340 Uncaught RuntimeError: memory access out of bounds at dlmalloc::dlmalloc::Dlmalloc::free::h36961b6fbcc40c05 (wasm-function[23]:670) at __rdl_dealloc (wasm-function[367]:8) at __rust_dealloc (wasm-function[360]:7) at alloc::alloc::dealloc::h90df92e1f727e726 (wasm-function[146]:100) at <alloc::alloc::Global as core::alloc::Alloc>::dealloc::h7f22ab187c7f5835 (wasm