How To Generate Standalone Webassembly With Emscripten
The documentation offers two options: let optimizer strip unnecessary code and then replace the .js glue with your own, or use SIDE_MODULE flag. Both options result in a memory imp
Solution 1:
You can simply set the output option (-o
) to a filename with the .wasm
extension. Emscripten will then output only the wasm file.
So if you have the following test.c
file:
#include "emscripten.h"
EMSCRIPTEN_KEEPALIVE
int add(int a, int b) {
return a + b;
}
And you compile it with emscripten like this:
emcc -O3 test.c -o test.wasm
you will only get the file test.wasm
and no extra .js
file. Also if you disassemble test.wasm
using e.g. wasm2wat
you'll get this WebAssembly text:
(module
(type (;0;) (func))
(type (;1;) (func (param i32 i32) (result i32)))
(func (;0;) (type 0)
nop)
(func (;1;) (type 1) (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add)
(memory (;0;) 256 256)
(export "memory" (memory 0))
(export "add" (func 1))
(export "_start" (func 0))
(data (;0;) (i32.const 1536) "\a0\06P"))
as you can see it's just what you would expect from a minimum webassembly binary.
Post a Comment for "How To Generate Standalone Webassembly With Emscripten"