Monday, December 5, 2011

Emscripten in node.js and on the web

Until now, to use Emscripten to compile LLVM to JavaScript you had to install a JavaScript engine shell (like SpiderMonkey's or V8's), both to run Emscripten itself and to run the generated code. This meant you had to get the latest source code of one of those shells and build it, which isn't hard but isn't super convenient either. So over the weekend I landed support for running Emscripten itself in node.js and in web browsers, as well as support for running the generated code in node.js (it always ran in browsers).

What this means is that if you have node.js, Python and Clang, you have everything you need to use Emscripten. For more, see the updated Getting Started page. (Regarding running Emscripten itself in a web browser, see src/compiler.html. This isn't really intended as a serious way to use it, but there are some interesting use cases for it, or will be.)

It is still strongly recommended to install the JavaScript engine shells themselves, though. One reason is the trunk engine shells are the very latest code, so to see the maximum speed code can run you should use them. Also, some tests require the SpiderMonkey shell because the others do not yet fully support the latest typed arrays spec. But, if you already have node.js installed anyhow, it is now easier to use Emscripten because you can just use that.


  1. hi,

    speak.js is an amazing performance test for JavaScript engines, Wow!
    I started to play around a litte bit, adding support for/compatibility for Webkit/Safari (test for Float32Array only - Float64Array is not used by this script - and renamed method "print") and external voice modules (so there's no need to recompile the core to add a language).

    Since there's now need for public methods, the API is a slightly more complex. (loadVoice(), isVoiceLoaded, setDefaultVoice(), speak())
    Therefor I renamed the script to differentiate it from the original.

    Maybe some of this could find its way into the main project ...


  2. masswerk, that's great!

    I would love to work with you and include your additions in the main project. Can we do that on github using normal pull requests etc.?

  3. Hi,

    updated the code a little bit, now all binary files are loaded as modules base64encoded (safes some bandwidth).
    Im not sure, if this is the same project or a fork, since the external API has changed (from a single call to an object with public methods).
    You decide!
    For the time being please download the zip-file from the URL given in the last comment, do a diff, and pick what you like ...
    As your build script inludes the binary files, I think it would be best, if you would modify the repository first, before I would join commits and everything is out of sync ...

    Maybe I'll find some time to work through the generated code in order to make the file smaller. (I think it would be possible to bring the core down to 500k in pure JS, which would be totally feasable regarding bandwidths , when transmitted gzipped.)
    Would be great to have an all purpose text-to-speach JS library!


  4. I am fine with changing the API. Whatever is useful :)

    Can we do this on github though? I might easily miss comments on the blog here, and it is much easier on github to merge stuff, view diffs, etc...

    - azakai