I’ve created this little nix shell to get the JS enabled GHC:
{
description = "A pristine single page web app example written in Haskell.";
inputs =
{
nixpkgs.url = "github:nixos/nixpkgs";
};
outputs = { self , nixpkgs }:
{
devShells.x86_64-linux.default = with import nixpkgs { system = "x86_64-linux"; }; with pkgs;
let
ghc = haskell.compiler.ghc9101;
ghc-js = haskell.compiler.ghc9101.override
{
stdenv = stdenv.override { targetPlatform = pkgsCross.ghcjs.stdenv.targetPlatform; };
};
in
mkShell
{
packages = [ ghc ghc-js cabal-install ghcid hello ];
shellHook = ''
alias ghcjs=javascript-unknown-ghcjs-ghc
export EMSCRIPTEN_CACHE=$HOME/.emscripten_cache
'';
};
};
}
I’ve made a very simple HelloJS.hs file to test things out:
module Main where
main :: IO ()
main = putStrLn "Hello, JavaScript!"
And have tried to compile it like so:
:> ghcjs HelloJS.hs
[1 of 2] Compiling Main ( HelloJS.hs, HelloJS.o )
[2 of 2] Linking HelloJS
This is successful, however I’m missing the all.js file from the HelloJS.jsexe directory. Here’s the ls:
:> ls -la HelloJS.jsexe/
total 5292
drwxr-xr-x 2 mastarija users 4096 Apr 2 09:12 .
drwxr-xr-x 7 mastarija users 4096 Apr 2 09:25 ..
-rw-r--r-- 1 mastarija users 227006 Apr 2 09:12 lib.js
-rw-r--r-- 1 mastarija users 21 Apr 2 09:12 out.frefs.js
-rw-r--r-- 1 mastarija users 0 Apr 2 09:12 out.frefs.json
-rw-r--r-- 1 mastarija users 4973375 Apr 2 09:12 out.js
-rw-r--r-- 1 mastarija users 22707 Apr 2 09:12 out.stats
-rw-r--r-- 1 mastarija users 174664 Apr 2 09:12 rts.js
From what I’ve read there should be the all.js file, and perhaps even some .html. I’m assuming I’d have to manually create some index.html file and include the rts.js, lib.js and out.js file and call the main function manually to get the output, but I was hoping for something I can quickly test by running e.g. node all.js like I’ve seen in some of the early tutorials.
Did something change in the meantime, is there a flag to enable the all.js generation or have I messed up something in my flake?