Skip to content

Commit ad86050

Browse files
Initial working setup of GHC with WASM backend
* Compile .cabal executable to .wasm * Optimize of .wasm for publication * Publish with Github Action
0 parents  commit ad86050

14 files changed

Lines changed: 461 additions & 0 deletions

File tree

.github/workflows/webpage.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build and Deploy to Github Page
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Install Nix
22+
uses: DeterminateSystems/nix-installer-action@v12
23+
24+
- name: Configure Nix Cache (optional)
25+
uses: DeterminateSystems/magic-nix-cache-action@v6
26+
27+
- name: Enter devShell and build
28+
run: |
29+
nix develop --command bash -c "
30+
echo 'Entered Nix devShell'
31+
wasm32-wasi-cabal update
32+
./build.sh && ./package.sh
33+
"
34+
35+
- name: Upload artifact
36+
uses: actions/upload-pages-artifact@v3
37+
with:
38+
path: www
39+
40+
deploy:
41+
needs: build
42+
runs-on: ubuntu-latest
43+
environment:
44+
name: github-pages
45+
url: ${{ steps.deployment.outputs.page_url }}
46+
steps:
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
dist
2+
dist-*
3+
cabal-dev
4+
*.o
5+
*.hi
6+
*.hie
7+
*.chi
8+
*.chs.h
9+
*.dyn_o
10+
*.dyn_hi
11+
.hpc
12+
.hsenv
13+
.cabal-sandbox/
14+
cabal.sandbox.config
15+
*.prof
16+
*.aux
17+
*.hp
18+
*.eventlog
19+
.stack-work/
20+
cabal.project.local
21+
cabal.project.local~
22+
.HTF/
23+
.ghc.environment.*

LICENSE

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Copyright the disco project and contributors
2+
SPDX-License-Identifier: BSD-3-Clause
3+
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above
13+
copyright notice, this list of conditions and the following
14+
disclaimer in the documentation and/or other materials provided
15+
with the distribution.
16+
17+
* Neither the name of Disco team nor the names of other
18+
contributors may be used to endorse or promote products derived
19+
from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Disco-live
2+
3+
This is the source code for a web UI where you can run programs written in [disco][].
4+
5+
[disco]: https://github.com/disco-lang/disco
6+
7+
# Building
8+
9+
Building
10+
11+
```
12+
nix develop
13+
./build.sh
14+
```
15+
16+
Running
17+
18+
```
19+
cd www
20+
python -m http.server
21+
```
22+
23+
Then, navigate to <http://localhost:8000/disco-live.html>.

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
wasm32-wasi-cabal build disco-live
5+
wasm32-wasi-cabal list-bin exe:disco-live
6+
EXE_WASM="$(wasm32-wasi-cabal list-bin exe:disco-live)"
7+
cp -f "$EXE_WASM" "www/disco-live.wasm"
8+
9+
"$(wasm32-wasi-ghc --print-libdir)"/post-link.mjs \
10+
--input "$EXE_WASM" --output "www/ghc_wasm_jsffi.js"

cabal.project

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages: .
2+
3+
allow-newer:
4+
disco:base

disco-live.cabal

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
cabal-version: 3.0
2+
name: disco-live
3+
4+
-- Package Versioning Policy: https://pvp.haskell.org
5+
-- PVP summary: +-+------- breaking API changes
6+
-- | | +----- non-breaking API additions
7+
-- | | | +--- code changes with no API change
8+
version: 0.1.0.0
9+
synopsis: Disco Web UI
10+
11+
category: Language
12+
license: BSD-3-Clause
13+
license-file: LICENSE
14+
author: Disco team, Heinrich Apfelmus
15+
maintainer: byorgey@gmail.com
16+
copyright: Disco team 2025-2026 (see LICENSE)
17+
extra-doc-files:
18+
README.md
19+
20+
source-repository head
21+
type: git
22+
location: https://github.com/disco-lang/disco.git
23+
24+
tested-with: GHC ==9.12.2
25+
26+
executable disco-live
27+
-- Compiler options that are necessary for the WASM backend.
28+
ghc-options:
29+
-no-hs-main
30+
-optl-mexec-model=reactor
31+
"-optl-Wl,--export=setup"
32+
33+
default-language: Haskell2010
34+
hs-source-dirs: src
35+
main-is: Main.hs
36+
37+
build-depends:
38+
, ghc-experimental ^>=0.1 || (>=9.1000 && <9.1300)
39+
, base >=4.8 && <4.22
40+
-- , disco >=0.2 && <0.3
41+
, text >=2.0.2 && <2.2
42+
43+
other-modules:
44+
Eval

flake.lock

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
description = "GHC WASM backend";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
ghc-wasm.url = "gitlab:haskell-wasm/ghc-wasm-meta?host=gitlab.haskell.org";
8+
};
9+
10+
outputs = { self, nixpkgs, flake-utils, ghc-wasm }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let
13+
pkgs = import nixpkgs { inherit system; };
14+
in
15+
{
16+
devShells.default = pkgs.mkShell {
17+
packages = [
18+
ghc-wasm.packages.${system}.all_9_12
19+
];
20+
21+
shellHook = ''
22+
echo "Development shell with GHC WASM backend"
23+
'';
24+
};
25+
}
26+
);
27+
}

package.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Minimize and package the final .wasm build.
4+
set -e
5+
WDIR="$(mktemp -d)"
6+
trap 'rm -rf -- "$WDIR"' EXIT
7+
8+
EXE_WASM="www/disco-live.wasm"
9+
10+
wizer \
11+
--allow-wasi --wasm-bulk-memory true --init-func _initialize \
12+
"$EXE_WASM" -o "$WDIR/exe-init.wasm"
13+
EXE_WASM_FINAL="$WDIR/exe-opt.wasm"
14+
wasm-opt "$WDIR/exe-init.wasm" -o "$EXE_WASM_FINAL" -Oz
15+
wasm-tools strip "$EXE_WASM_FINAL" -o "$EXE_WASM_FINAL"
16+
17+
cp -f "$EXE_WASM_FINAL" www/disco-live.wasm

0 commit comments

Comments
 (0)