To use GHCJS with stack, place a GHCJS version in the
compiler field of
stack.yaml. After this, all stack commands should work with GHCJS! In particular:
stack setupwill install GHCJS from source and boot it, which takes a long time.
$(stack path --local-install-root)/bin/EXECUTABLE.jsexe/all.js(bash syntax, where
EXECUTABLEis the name of your executable).
You can also build existing stack projects which target GHC, and instead build
them with GHCJS. For example:
stack build --compiler ghcjs-0.2.0.9006020_ghc-7.10.3
Sidenote: If you receive a message like
The program 'ghcjs' version >=0.1 is
required but the version of .../ghcjs could not be determined., then you may
need to install a different version of
Recent versions of GHCJS, repacked for stack¶
These versions of GHCJS were created by Marcin Tolysz, and were particularly crafted to include package versions which match those expected by particular stackage snapshots.
ghcjs based on
ghc-7.10.3 one could try:
resolver: lts-6.25 compiler: ghcjs-0.2.0.9006025_ghc-7.10.3 compiler-check: match-exact setup-info: ghcjs: source: ghcjs-0.2.0.9006025_ghc-7.10.3: url: http://ghcjs.tolysz.org/lts-6.25-9006025.tar.gz sha1: 3c87228579b55c05e227a7876682c2a7d4c9c007
Or for the latest one based on
ghc-8.0.1 (with more features):
resolver: lts-7.8 compiler: ghcjs-0.2.1.9007008_ghc-8.0.1 compiler-check: match-exact setup-info: ghcjs: source: ghcjs-0.2.1.9007008_ghc-8.0.1: url: http://ghcjs.tolysz.org/ghc-8.0-2016-11-07-lts-7.8-9007008.tar.gz sha1: 190300a3725cde44b2a08be9ef829f2077bf8825
The later can be generated via: https://github.com/tolysz/prepare-ghcjs
the fromer is a bit more manual. Those bundles are only tested against the latest
In order to corrrectly boot and use ghcjs, one might need to install
hsc2hs with the normal ghc.
If you do not use the same resolver, say, an older LTS snapshot, you will get some warnings like this:
Ignoring that the GHCJS boot package "aeson" has a different version, 0.9.0.1, than the resolver's wanted version, 0.8.0.2 Ignoring that the GHCJS boot package "attoparsec" has a different version, 0.13.0.1, than the resolver's wanted version, 0.12.1.6 Ignoring that the GHCJS boot package "scientific" has a different version, 0.3.3.8, than the resolver's wanted version, 0.3.4.2 ...
These warnings can usually be safely ignored, but they do indicate a divergence between your snapshot's packages, and those that are being used to compile your project. You will normally get these warnings when using a GHCJS tarball that has not been packaged with a particular snapshot in mind.
GHCJS (old base)¶
If you want to build some older GHCJS packages, you may need to use the "old base" GHCJS. To do this, use the following compiler info:
compiler: ghcjs-0.1.0.20150924_ghc-7.10.2 compiler-check: match-exact
Custom installed GHCJS (development branch)¶
In order to use a GHCJS installed on your path, just add the following to your
ghcjs-0.1.0_ghc-7.10.2 if you are working with an older version)
Project with both client and server¶
For projects with both a server and client, the recommended project
organization is to put one or both of your
stack.yaml files in
sub-directories. This way, you can use the current working directory to
specify whether you're working on the client or server. This will also allow
more straightforward editor tooling, once projects like
haskell-ide-engine support GHCJS.
For example, here's what a script for building both client and server looks like:
You can also put both the yaml files in the same directory, and have e.g.
ghcjs-stack.yaml, but this won't work well with editor integrations.
Using stack without a snapshot¶
If you don't want to use a snapshot, instead place the ghcjs version in the
resolver field of your
stack.yaml. This is also necessary when using stack
Setting up GHCJS on Windows¶
stack setup command fails to successfully complete with message:
commitBuffer: invalid argument (invalid character), it means you have a locale problem.
This problem is not exclusive to GHCJS, and might happen also during other builds. A workaround is to set Language for non-Unicode programs to English (US).
For details see stack issue #1448.