WASM hello world
This commit is contained in:
parent
38838c47b9
commit
77ee0c0abb
9 changed files with 121 additions and 46 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
dist-newstyle
|
dist-newstyle
|
||||||
.direnv
|
.direnv
|
||||||
*.cabal
|
*.cabal
|
||||||
|
cabal.project.local
|
||||||
|
|
|
||||||
6
Makefile
6
Makefile
|
|
@ -1,8 +1,10 @@
|
||||||
|
|
||||||
all: out/numbersquare.wasm out/ghc_wasm_jsffi.js
|
all: out/numbersquare.wasm out/ghc_wasm_jsffi.js
|
||||||
|
|
||||||
out/numbersquare.wasm: app/* src/* numbersquare.cabal
|
numbersquare.cabal: package.yaml
|
||||||
wasm32-wasi-cabal build
|
hpack
|
||||||
|
|
||||||
|
out/numbersquare.wasm: app/*.hs src/*.hs numbersquare.cabal
|
||||||
wasm32-wasi-cabal install --installdir=out --overwrite-policy=always
|
wasm32-wasi-cabal install --installdir=out --overwrite-policy=always
|
||||||
|
|
||||||
out/ghc_wasm_jsffi.js: out/numbersquare.wasm
|
out/ghc_wasm_jsffi.js: out/numbersquare.wasm
|
||||||
|
|
|
||||||
19
app/App.hs
Normal file
19
app/App.hs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
module App where
|
||||||
|
|
||||||
|
import Reflex
|
||||||
|
import Reflex.Dom.Core
|
||||||
|
|
||||||
|
import Language.Javascript.JSaddle
|
||||||
|
|
||||||
|
testWidget ::
|
||||||
|
( DomBuilder t m
|
||||||
|
, DomBuilderSpace m ~ GhcjsDomSpace
|
||||||
|
, MonadHold t m
|
||||||
|
, PostBuild t m
|
||||||
|
) =>
|
||||||
|
m ()
|
||||||
|
testWidget = elAttr "div" ("class" =: "content") do
|
||||||
|
text "hello, world!"
|
||||||
|
|
||||||
|
start :: JSM ()
|
||||||
|
start = mainWidget testWidget
|
||||||
10
app/Main.hs
10
app/Main.hs
|
|
@ -1,4 +1,12 @@
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
|
import App qualified
|
||||||
|
import Language.Javascript.JSaddle
|
||||||
|
import Language.Javascript.JSaddle.Wasm qualified as W
|
||||||
|
|
||||||
|
foreign export javascript "hs_start" main :: IO ()
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = putStrLn "hi"
|
main = W.run $ App.start
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
packages: ./numbersquare.cabal
|
packages: ./numbersquare.cabal
|
||||||
tests: True
|
tests: True
|
||||||
|
|
||||||
|
index-state: 2025-10-11T08:08:38Z
|
||||||
|
|
|
||||||
6
flake.lock
generated
6
flake.lock
generated
|
|
@ -73,11 +73,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1777268161,
|
"lastModified": 1777954456,
|
||||||
"narHash": "sha256-bxrdOn8SCOv8tN4JbTF/TXq7kjo9ag4M+C8yzzIRYbE=",
|
"narHash": "sha256-hGdgeU2Nk87RAuZyYjyDjFL6LK7dAZN5RE9+hrDTkDU=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "1c3fe55ad329cbcb28471bb30f05c9827f724c76",
|
"rev": "549bd84d6279f9852cae6225e372cc67fb91a4c1",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,12 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit ghc-wasm-meta;
|
|
||||||
devShells.x86_64-linux.default = pkgs.callPackage ./shell.nix {
|
devShells.x86_64-linux.default = pkgs.callPackage ./shell.nix {
|
||||||
wasm32-wasi-cabal = ghc-wasm-meta.packages.x86_64-linux.wasm32-wasi-cabal-9_14;
|
wasm32-wasi-cabal = ghc-wasm-meta.packages.x86_64-linux.wasm32-wasi-cabal-9_12;
|
||||||
wasm32-wasi-ghc = ghc-wasm-meta.packages.x86_64-linux.wasm32-wasi-ghc-9_14;
|
wasm32-wasi-ghc = ghc-wasm-meta.packages.x86_64-linux.wasm32-wasi-ghc-9_12;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
package.yaml
13
package.yaml
|
|
@ -6,10 +6,11 @@ description: "a game where you number square"
|
||||||
license: BSD3
|
license: BSD3
|
||||||
author: skulk
|
author: skulk
|
||||||
|
|
||||||
|
language: GHC2021
|
||||||
ghc-options: "-Wall"
|
ghc-options: "-Wall"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
- "base == 4.*"
|
- base
|
||||||
- random
|
- random
|
||||||
- array
|
- array
|
||||||
- text
|
- text
|
||||||
|
|
@ -30,6 +31,8 @@ default-extensions:
|
||||||
- OverloadedLabels
|
- OverloadedLabels
|
||||||
- NamedFieldPuns
|
- NamedFieldPuns
|
||||||
- TypeOperators
|
- TypeOperators
|
||||||
|
- BlockArguments
|
||||||
|
- OverloadedStrings
|
||||||
|
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
|
|
||||||
|
|
@ -41,6 +44,14 @@ executable:
|
||||||
source-dirs:
|
source-dirs:
|
||||||
- app
|
- app
|
||||||
main: Main.hs
|
main: Main.hs
|
||||||
|
dependencies:
|
||||||
|
- base
|
||||||
|
- reflex
|
||||||
|
- reflex-dom-core
|
||||||
|
- "ghcjs-dom == 0.9.*"
|
||||||
|
- jsaddle
|
||||||
|
- jsaddle-wasm
|
||||||
|
- ghc-experimental
|
||||||
when:
|
when:
|
||||||
- condition: arch(wasm32)
|
- condition: arch(wasm32)
|
||||||
ghc-options:
|
ghc-options:
|
||||||
|
|
|
||||||
37
shell.nix
37
shell.nix
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
callPackage,
|
||||||
haskellPackages,
|
haskellPackages,
|
||||||
haskell,
|
haskell,
|
||||||
zlib,
|
zlib,
|
||||||
|
|
@ -7,11 +8,29 @@
|
||||||
wasm32-wasi-ghc,
|
wasm32-wasi-ghc,
|
||||||
writeShellApplication,
|
writeShellApplication,
|
||||||
nodejs,
|
nodejs,
|
||||||
|
pkg-config,
|
||||||
python3,
|
python3,
|
||||||
|
fetchFromGitHub,
|
||||||
}:
|
}:
|
||||||
haskellPackages.developPackage {
|
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";
|
name = "numbersquare";
|
||||||
root = ./.;
|
root = ./.;
|
||||||
|
overrides = _: _: {
|
||||||
|
ghc-wasm-compat =
|
||||||
|
haskellPackages.callCabal2nix "ghc-wasm-compat" "${ghc-wasm-compat-src}/ghc-wasm-compat"
|
||||||
|
{ };
|
||||||
|
};
|
||||||
modifier =
|
modifier =
|
||||||
let
|
let
|
||||||
addBuildTools =
|
addBuildTools =
|
||||||
|
|
@ -22,6 +41,7 @@ haskellPackages.developPackage {
|
||||||
wasm32-wasi-cabal
|
wasm32-wasi-cabal
|
||||||
wasm32-wasi-ghc
|
wasm32-wasi-ghc
|
||||||
nodejs
|
nodejs
|
||||||
|
pkg-config
|
||||||
(writeShellApplication {
|
(writeShellApplication {
|
||||||
name = "dev-server";
|
name = "dev-server";
|
||||||
text = ''
|
text = ''
|
||||||
|
|
@ -32,6 +52,7 @@ haskellPackages.developPackage {
|
||||||
]
|
]
|
||||||
++ (with haskellPackages; [
|
++ (with haskellPackages; [
|
||||||
fourmolu
|
fourmolu
|
||||||
|
happy
|
||||||
haskell-language-server
|
haskell-language-server
|
||||||
cabal-install
|
cabal-install
|
||||||
hpack
|
hpack
|
||||||
|
|
@ -43,4 +64,16 @@ haskellPackages.developPackage {
|
||||||
addExtraLibraries = drv: haskell.lib.addExtraLibraries drv [ zlib ];
|
addExtraLibraries = drv: haskell.lib.addExtraLibraries drv [ zlib ];
|
||||||
in
|
in
|
||||||
drv: addExtraLibraries (addBuildTools drv);
|
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
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue