Compile to WASM for use in Scala, without name mangling #8235
Unanswered
MatheusDS4
asked this question in
Q&A
Replies: 1 comment 4 replies
-
|
Do you mean you are trying to compile Binaryen itself into wasm? The best way might be to look at the existing code for that:
|
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I've tried asking the !@#!%#% AI on how to get a WASM from Binaryen source, but I wasted ~2 hours compiling the source and got an apparently mangled WASM (checked it with
wasm2cand verified the C header to check function names myself).What can I do better than the following?:
AI-based prompt answer
(Based on AI (ChatGPT).)
🧱 What binaryen_wasm Is
binaryen_wasmtarget is a build option that compiles the Binaryen C API to a WebAssembly module that exposes Binaryen’s APIs as exports. (GitHub)🛠️ Step-by-Step: Building
binaryen_wasmClone the Binaryen Repository
git clone https://github.com/WebAssembly/binaryen.git cd binaryen(This is the official main source for Binaryen.) (GitHub)
Install Emscripten
You’ll need Emscripten so
cmakeandemcccan target WebAssembly:emcmake,emcc, and related tools are in your PATH.Initialize Git submodules
Configure with CMake for WebAssembly
Use
emcmakeso Binaryen’s build system knows you want a WASM target:mkdir build-wasm cd build-wasm emcmake cmake .. -DBINARYEN_BUILD_BINARYEN_WASM=ON(This tells CMake to include
binaryen_wasmtarget in the build.)Build It
cmake --build .After building, you should have something like:
.wasmfile exporting the Binaryen C API.jsglue file (if configured) that instantiates itThe build output and naming can vary based on Emscripten settings.
📦 Using the Resulting WASM Module
📌 Option A — Use the Raw WASM Exports
If you want to use it without JS glue (just the raw WebAssembly exports):
Working with the raw C API usually means calling functions that take/return integer handles for internal Binaryen objects. You’ll need to refer to the Binaryen C API headers (e.g.,
binaryen-c.h) for function signatures.📘 Tips & Notes
binaryen-c.h). It defines functions for module creation, passes, validation, etc.The build exposes those same functions under WASM exports. (GitHub)
Beta Was this translation helpful? Give feedback.
All reactions