Skip to content

Rust compiled to Wasm with wasm-pack, and recompiled with cargo and wasm-bindgen-cli to add DWARF debugging info.

Notifications You must be signed in to change notification settings

anfibiacreativa/wasmio-binarytranslate-rust

Repository files navigation

This is a Rust version of the binary translator I built with JavaScript and Javy.

Pre-requisites

Usage

See a video of the debugging: https://youtu.be/lytt2Od7jt0

Fork the repo, and build the translator library, running

wasm-pack build --target web

You can now start the vite server with

npm run dev

At which point, you can use the translator to translate any string you enter in the input box.

Debugging

From VS Code

Docs: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_debugging-webassembly

Rust Wasm module with DWARF information

Important

Rust emits DWARF debug information. However, wasm-pack does not yet retain it during the build. So, instead of running wasm-pack build, users of the common wasm-bindgen/wasm-pack libraries should build manually build using the following commands:

cargo install wasm-bindgen-cli

once to install the necessary command-line tool.

cargo build --target wasm32-unknown-unknown 

to build your library. And

wasm-bindgen --keep-debug --out-dir pkg ./target/wasm32-unknown-unknown/debug/<library-name>.wasm <extra-arguments> 

to generate the WebAssembly bindings, replacing with the name from your Cargo.toml and configuring as necessary. In our case, we run:

wasm-bindgen --keep-debug --out-dir pkg ./target/wasm32-unknown-unknown/debug/rust_binary_translate.wasm

with the default --target, which in this case is bundler. Once it's run, update the contents of the file ./pkg/rust_binary_translate.js

to

import * as wasm from "./rust_binary_translate_bg.wasm";
import { __wbg_set_wasm } from "./rust_binary_translate_bg.js";
__wbg_set_wasm(wasm);
// had to refactor the export statement to get the import to work
export * as pkg from "./rust_binary_translate_bg.js";

If it generates a package.json, also make sure to set

"type": "module"

About

Rust compiled to Wasm with wasm-pack, and recompiled with cargo and wasm-bindgen-cli to add DWARF debugging info.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published