Skip to content

JS: support linking with C sources

Sylvain Henry requested to merge hsyl20/ghc:hsyl20/js-c-sources into master

Support compiling and linking C sources into JavaScript with Emscripten.

Note that we don't automatically generate wrappers. It means that linked C code isn't automatically called into. Wrappers need to provided as jsbits.

The new //#OPTIONS:EMCC=... pragma can be used to pass flags to the emcc linker. This is particularly useful to indicate which C functions to keep alive (-sEXPORTED_FUNCTIONS=...). An alternative is to use -optl.


  • fix issue with -SEXPORTED_... emcc flags not being cumulative
  • add flag -fjs-c-link=auto,disabled,enabled to support the current behavior even in the presence of C files (disabled) or to force the emcc linking (enabled)
  • add support for incremental linking of C files for Template Haskell using dlopen (in a future MR)
  • ensure that your commits are either individually buildable or squashed
  • ensure that your commit messages describe what they do (referring to tickets using #NNNN syntax when appropriate)
  • have added source comments describing your change. For larger changes you likely should add a [Note][notes] and cross-reference it from the relevant places.
  • add a [testcase to the testsuite][adding test].
  • updates the users guide if applicable
  • mentions new features in the release notes for the next release
Edited by Sylvain Henry

Merge request reports