WebAssembly support for Haxe ?

2,159 views
Skip to first unread message

MJ

unread,
Mar 17, 2017, 6:59:31 AM3/17/17
to Haxe
Hi,
 I wonder,  as Firefox 52 and Chrome 57 already support webassembly , is anyone try to compilie  haxe to wasm  ( Haxe->Cpp->WebAssembly )  ?  Is there any tutorial, how to use wasm with haxe together ? 
  This demo http://webassembly.org/demo/ , using Unity, show great performance on my PC.

Cambiata

unread,
Mar 17, 2017, 7:46:56 AM3/17/17
to Haxe
Well, let's hope that this tweet from Nicolas gives the direction:


michael solomon

unread,
Mar 17, 2017, 9:41:31 AM3/17/17
to Haxe
I think haxe must implement a good solution and make great efforts to compile into fast, good wasm.
I think that will be a migration from js to wasm as was with flash to js. Haxe must shine in this important junction!

Robert Konrad

unread,
Mar 17, 2017, 11:29:30 AM3/17/17
to Haxe
Compiling to wasm is very much the same as compiling to C++ (wasm is primarily designed as a C/C++ target) and Haxe generated C++ runs slower than Haxe generated JS in a lot of situations (for example because JS garbage collectors are very fast). Current wasm doesn't make a lot of sense for Haxe IMHO.

Dan Korostelev

unread,
Mar 17, 2017, 11:36:44 AM3/17/17
to Haxe
It will make sense when they have a GC though, right?

пятница, 17 марта 2017 г., 18:29:30 UTC+3 пользователь Robert Konrad написал:

michael solomon

unread,
Mar 17, 2017, 12:42:09 PM3/17/17
to Haxe
Technically you are absolutely right, but I'm looking from the business view... And for me it looks like must have target because it's gonna be the next web standart, so haxe wasm would be 2 time slower till the GC will be adde so what? Meanwhile you are loosing "clients" (programmers) for other solutions

JLM

unread,
Mar 17, 2017, 1:25:19 PM3/17/17
to Haxe
Can hxcpp already compile emscripten via the Binaryen tools, they use AST transforms to map to the stack used by Webassembly so perhaps HashLink could be mapped similar?  I guess cppia in webassembly might open some interesting possiblities, but I guess till someone smart looks into it we can't really be sure how fast or slow Haxe will be able to do some webassembly? But realistically it will be awhile before we can use this and webgl2 on anything comercial anyway, not much use if it only runs in latest browser.

Robert Konrad

unread,
Mar 17, 2017, 7:22:02 PM3/17/17
to Haxe
If you don't mind it being slower, I would guess what JLM suggests works right now (never tried though because I consider it useless).
@Dan: Probably.

michael solomon

unread,
Mar 17, 2017, 8:23:00 PM3/17/17
to Haxe
I think you two missing my point.. there should be at least a super simple tool todo it.

JeriX

unread,
Mar 18, 2017, 3:10:38 PM3/18/17
to Haxe
I think I got your point and I agree with you. Haxe need at least one way to compile to wasm, and it may be slow at first, but there has to be the way to do it, some simple steps to follow and check it works

Russ

unread,
Jun 13, 2017, 3:30:57 PM6/13/17
to Haxe
Here's a simple haxe 'Hello World' using wasm and the latest haxe+hxcpp.

First, visit http://webassembly.org/getting-started/developers-guide/ and follow the instructions there to setup Emscripten.  Ensure the setup is working by doing the "Compile and run a simple program" step.

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:
haxe build.hxml

And finally, run in the browser:
emrun out/Main.html

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.



Reply all
Reply to author
Forward
0 new messages