Skip to content
kripken edited this page Nov 3, 2012 · 96 revisions

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

Using Emscripten, you can

  • Compile C and C++ code into JavaScript and run that on the web
  • Run code in languages like Python as well, by compiling CPython from C to JavaScript and interpreting code in that on the web

Demos

  • BananaBread - Port of Sauerbraten/Cube 2. Demo site here. additional levels added!
  • Graphviz - Graph visualization software (port is here) new!
  • Me & My Shadow - A 2D SDL platform/puzzle game (original here) optimized!
  • Heriswap - Port of a match-3 puzzle game.
  • Ceferino - Port of a 2D action game (also available here).
  • SuperTux WIP - Port of SuperTux. by forandom
  • JS-VBA-M - Port of VBA-M. by ILOVEPIE
  • Transport Tycoon Deluxe port of OpenTTD by caiiiycuk
  • PNG Crush - PNG optimizer in a web page
  • OpenGL ES 2.0 Gears - OpenGL ES 2.0 rendering compiled to WebGL.
  • XML schema validation - XML validation in pure JS using compiled libxml.
  • hpdf.js - Create PDF files in pure JS using compiled libharu. new!
  • Box2D/WebGL - The Box2D physics engine compiled to JavaScript with convenient automatically-generated bindings (through box2d.js)
  • SQLite - SQLite compiled to JavaScript with an easy-to-use API (through sql.js)
  • Bullet/WebGL - The Bullet physics engine compiled to JavaScript with convenient automatically-generated bindings (through ammo.js)
  • Text-to-Speech - eSpeak, a speech synthesizer, compiled to JavaScript.
  • Ray tracing - A simple C++ ray tracer, rendering to a canvas element
  • Python, Ruby, Lua - The popular dynamic languages Python, Ruby and Lua, compiled to JavaScript. Python even supports importing modules! [Note: Currently broken on nightly Firefox and Chrome due to sync XHR API changes)
  • Poppler - PDF rendering in JavaScript, using Poppler and FreeType. Warning: Very large (>12MB) download.
  • OpenJPEG - JPEG 2000 decoding in JavaScript, using OpenJPEG (see also j2k.js)
  • FreeType - TrueType font rendering in JavaScript, using FreeType
  • Lua - The Lua interpreter

Other Examples

  • zpipe - zlib compiled to JS
  • zee.js - Another port of zlib to JS (focused on compressing/decompressing of gzip files)
  • lzma.js - LZMA ported to JS
  • sql.js - SQLite ported to JS

Useful Things

Get in Touch

Bug Reports

You can file issues here on GitHub. If relevant, please supply the original source, the generated .ll, and the generated .js files (in a gist, pastebin, or any other method).

If you file an issue with what looks like a bug in the generated code - it behaves differently than it should - please describe how the results differ when that code is compiled and run as native code. Also, please mention exactly how you compiled the code to JavaScript, as changing options from their safe defaults (for example, CORRECT_SIGNS) can greatly affect the results.

Contributing

Anyone is welcome to join us in developing Emscripten. Feel free to contact us on IRC or on the mailing list (links above), or through issues here on GitHub.

Patches can be submitted either in issues (as a gist is probably most convenient), or as pull requests, either is fine. When submitting patches, please:

  • Add yourself to the AUTHORS file (if you aren't already there). By adding yourself, you agree to license your code under the project's open source licenses (MIT/LLVM).
  • You should run all the automatic tests and make sure they pass (python tests/runner.py). Patches that are simple enough (for example, just add library functions that were not used before) might not need this, but most will. Please mention in the pull request or issue which tests you ran.
  • If you did not run all the automatic tests, please make your pull request to incoming, not master. Code in incoming will have tests run on it, and will later merge to master when they all pass.
  • If you add any new functionality or fix an existing bug, add an automatic test to tests/runner.py.
  • Please do not include merge commits in pull requests; include only commits with the new relevant code.

Branches of interest

  • master - Always safe to pull from, the test suite always passes on it
  • incoming - Where new code lands before tests have been done
  • llvmsvn - Where work to support a new version of LLVM lands. Activity typically begins near the end of an LLVM 6-month dev cycle. When LLVM launches the new version, we merge this branch to master and incoming, at which point our support officially moves to that new LLVM version (we only support one at a time)

Thanks to juj we have test results for master and incoming on multiple platforms.

Clone this wiki locally