Emscripten

Emscripten: An LLVM-to-JavaScript Compiler

If you want to work with emcc, emconfigure and emmake as you are used to from Ubuntu and similar distributions,

Terminal window
nix-shell -p emscripten

A few things to note:

  • export EMCC_DEBUG=2 is nice for debugging
  • The build artifact cache in ~/.emscripten sometimes creates issues and needs to be removed from time to time

Examples

Let’s see two different examples from pkgs/top-level/emscripten-packages.nix:

  • pkgs.zlib.override
  • pkgs.buildEmscriptenPackage

A special requirement of the pkgs.buildEmscriptenPackage is the doCheck = true. This means each Emscripten package requires that a checkPhase is implemented.

  • Use export EMCC_DEBUG=2 from within a phase to get more detailed debug output what is going wrong.
  • The cache at ~/.emscripten requires to set HOME=$TMPDIR in individual phases. This makes compilation slower but also more deterministic.

Debugging

Use nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz and from there you can go through the individual steps. This makes it easy to build a good unit test or list the files of the project.

  1. nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz
  2. cd /tmp/
  3. unpackPhase
  4. cd libz-1.2.3
  5. configurePhase
  6. buildPhase
  7. … happy hacking…