WASM hello world

This commit is contained in:
Sidharth Kulkarni 2026-05-10 09:24:48 -07:00
parent 38838c47b9
commit 77ee0c0abb
Signed by: skulk
SSH key fingerprint: SHA256:Jby+S9d1WmwqnXIrngHgccYNHz+cYquxN1zm3ym3Kbg
9 changed files with 121 additions and 46 deletions

103
shell.nix
View file

@ -1,4 +1,5 @@
{
callPackage,
haskellPackages,
haskell,
zlib,
@ -7,40 +8,72 @@
wasm32-wasi-ghc,
writeShellApplication,
nodejs,
pkg-config,
python3,
fetchFromGitHub,
}:
haskellPackages.developPackage {
name = "numbersquare";
root = ./.;
modifier =
let
addBuildTools =
drv:
haskell.lib.addBuildTools drv (
[
watchexec
wasm32-wasi-cabal
wasm32-wasi-ghc
nodejs
(writeShellApplication {
name = "dev-server";
text = ''
python -m http.server -d ./out
'';
runtimeInputs = [ python3 ];
})
]
++ (with haskellPackages; [
fourmolu
haskell-language-server
cabal-install
hpack
ghcid
cabal-fmt
hoogle
])
);
addExtraLibraries = drv: haskell.lib.addExtraLibraries drv [ zlib ];
in
drv: addExtraLibraries (addBuildTools drv);
}
let
# TODO: this information is duplicated at the bottom. need to fix that.
ghc-wasm-compat-rev = "ef21ada9436046c7b118314d0c73752253ec58e1";
ghc-wasm-compat-src = fetchFromGitHub {
owner = "konn";
repo = "ghc-wasm-earthly";
rev = ghc-wasm-compat-rev;
hash = "sha256-oUf7HFLNxBZ/roFRe5q7Sz0D0ZRygu8prxEYoYuhSU8=";
};
in
let
shell = haskellPackages.developPackage {
name = "numbersquare";
root = ./.;
overrides = _: _: {
ghc-wasm-compat =
haskellPackages.callCabal2nix "ghc-wasm-compat" "${ghc-wasm-compat-src}/ghc-wasm-compat"
{ };
};
modifier =
let
addBuildTools =
drv:
haskell.lib.addBuildTools drv (
[
watchexec
wasm32-wasi-cabal
wasm32-wasi-ghc
nodejs
pkg-config
(writeShellApplication {
name = "dev-server";
text = ''
python -m http.server -d ./out
'';
runtimeInputs = [ python3 ];
})
]
++ (with haskellPackages; [
fourmolu
happy
haskell-language-server
cabal-install
hpack
ghcid
cabal-fmt
hoogle
])
);
addExtraLibraries = drv: haskell.lib.addExtraLibraries drv [ zlib ];
in
drv: addExtraLibraries (addBuildTools drv);
};
in
shell.overrideAttrs (old: {
shellHook = (old.shellHook or "") + ''
cat > cabal.project.local <<EOF
source-repository-package
type: git
location: https://github.com/konn/ghc-wasm-earthly
tag: ${ghc-wasm-compat-rev}
subdir: ghc-wasm-compat
EOF
'';
})