My Dark emscripten secrets

Joshua Koo, 23 feb 2015, talk.js

What is Emscripten?

Emscripten is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which can be generated from C/C++, using llvm-gcc (DragonEgg) or clang, or any other language that can be converted into LLVM - and compiles that into JavaScript, which can be run on the web (or anywhere else JavaScript can run).

Emscripten is an LLVM-based project that compiles C and C++ into highly-optimizable JavaScript in asm.js format. This lets you run C and C++ on the web at near-native speed, without plugins.

http://kripken.github.io/emscripten-site/

Why?

Some Inception

emcmake cmake .
emmake make
oh oh....

: (

make clean
git checkout
google errors
stackoverflow
(repeat)

....

I struggle with Emscripten

(OPEN) SECRET #1

  • these projects weren't trivial
  • maybe my Emscripten environment wasn't setup correctly
  • I wasn't familiar with C or C++ world
  • I wasn't familiar with the build systems

What went wrong?

study the requirements

Understand the source

Compile native

understand emscripten

Pick a simplier project

HLSL2GLSL

Dump the Build Systems

(pun intended)

emcc src/*.cpp -o hlslparser.js -s EXPORTED_FUNCTIONS="['_parseHLSL']" --bind -O3

GLSL Optimizer

Dump the Build Systems

Some other tips

1. Check for threads

2. Check File I/O

3. Consider bindings

What's Next?

conclusion

The C* & JS world are not that far apart

I think emscripten is kinda awesome

There are more things out there

have fun!

I'm Joshua Koo
I work for Zopim, a Zendesk company
and organize creative coding meetups

twitter: @blurspline
facebook: fb
github: zz85

Links!

My forks
https://github.com/zz85/hlslparser
https://github.com/zz85/glsl-optimizer


Documentation
https://github.com/kripken/emscripten/wiki
http://kripken.github.io/emscripten-site/

More Readings!

https://hacks.mozilla.org/2014/11/porting-to-emscripten/
http://mozakai.blogspot.sg/2013/11/c-to-javascript-emscripten-mandreel-and.html
http://ejohn.org/blog/asmjs-javascript-compile-target/
https://github.com/gsathya/SDL-emscripten/wiki/Building-with-CMake
http://mozakai.blogspot.sg/2012/03/howto-port-cc-library-to-javascript.html

http://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#c.em_str_callback_func
http://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html
http://kripken.github.io/emscripten-site/docs/api_reference/val.h.html

 

Made with Slides.com