Here's a simple haxe 'Hello World' using wasm and the latest haxe+hxcpp.
Then, add these two files to a project folder somewhere:
build.hxml:
# Windows maybe needs this define
-D EMSCRIPTEN_SDK
# If you want the .html file showing how to embed the wasm
-D HXCPP_LINK_EMSCRIPTEN_EXT=.html
# Tell hxcpp to use emscripten-toolchain.xml
-D emscripten
-cpp out
-main Main
Main.hx:
@:buildXml("
<linker id='exe' exe='emcc'>
<flag value='-s' />
<flag value='WASM=1' />
</linker>
")
class Main {
static function main() {
trace('Hello Web Assembly');
}
}
Next, setup Emscripten environment vars in your shell:
source /path/to/emsdk_env.sh
Then compile:
And finally, run in the browser:
Or run in Node JS 8:
cd out
/path/to/nodejs8/node Main.js
Also check out the emscripten-toolchain.xml file in hxcpp for more Emscripten specific defines.