Skip to content

Commit 437073d

Browse files
committed
Initial commit
0 parents  commit 437073d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1430
-0
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: build
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
name: build
14+
runs-on: ubuntu-24.04
15+
permissions:
16+
pages: write
17+
id-token: write
18+
steps:
19+
20+
- name: install-nix
21+
uses: DeterminateSystems/nix-installer-action@v17
22+
23+
- name: checkout
24+
uses: actions/checkout@v4
25+
26+
- name: build-lessons
27+
run: |
28+
nix develop -i -k HOME --command sh -c "wasm32-wasi-cabal update && exec ./build.sh"
29+
30+
- name: build-slides
31+
run: |
32+
nix shell nixpkgs#pandoc --command sh -c "cd slides && exec ./build.sh"
33+
34+
- name: upload-pages-artifact
35+
uses: actions/upload-pages-artifact@v3
36+
with:
37+
path: slides/dist
38+
retention-days: 90
39+
40+
- name: deploy-pages
41+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
dist-newstyle
3+
4+
*.br
5+
*.wasm

LICENSE

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

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Zurihac 2025 wasm track material
2+
3+
## Building the slides
4+
5+
The slides are available on [GitHub
6+
pages](https://haskell-wasm.github.io/zurihac-2025). To build from
7+
source, run `build.sh` in `slides`. The slides will be available in
8+
`dist/index.html`. Requires `pandoc`.
9+
10+
## Setting up development environment
11+
12+
This repo is a nix flake that provides a default dev shell with all
13+
relevant build tools. Run `nix develop` to enter the shell, and run
14+
`wasm32-wasi-cabal update` at least once in the shell before running
15+
other builds, since `wasm32-wasi-cabal` uses an isolated cabal store
16+
from the default native cabal store to avoid potential interference.
17+
18+
Non-nix users can follow instructions
19+
[here](https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta#getting-started-without-nix).
20+
21+
## Building each lesson
22+
23+
The wasm track is organized into five lessons. Each lesson's directory
24+
is a cabal project directory containing a `README.md` with short
25+
description, and a `build.sh` to build it. All build scripts are meant
26+
to be run in that lesson's subdirectory, different lessons don't share
27+
any code.
28+
29+
After building a lesson, run `python3 -m http.server -b localhost
30+
8000` in the lesson's subdirectory to serve a local HTTP server that
31+
loads `index.html`. All `index.html` is self-contained with all
32+
required CSS/JS code.
33+
34+
The repo root `build.sh` builds all lessons at once.
35+
36+
## License
37+
38+
Everything here is licensed under BSD-3.

build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
pushd lesson1
6+
./build.sh
7+
popd
8+
9+
pushd lesson2
10+
./build.sh
11+
popd
12+
13+
pushd lesson3
14+
./test.sh
15+
popd
16+
17+
pushd lesson4
18+
./build.sh
19+
popd
20+
21+
pushd lesson5
22+
./build.sh
23+
popd

flake.lock

Lines changed: 81 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
inputs.ghc-wasm-meta.url = "gitlab:haskell-wasm/ghc-wasm-meta?host=gitlab.haskell.org";
3+
4+
outputs =
5+
{ self
6+
, ghc-wasm-meta
7+
,
8+
}:
9+
ghc-wasm-meta.inputs.flake-utils.lib.eachSystem
10+
[
11+
"x86_64-linux"
12+
"aarch64-darwin"
13+
"aarch64-linux"
14+
]
15+
(
16+
system:
17+
let
18+
pkgs = import ghc-wasm-meta.inputs.nixpkgs { inherit system; };
19+
in
20+
{
21+
devShells.default = pkgs.mkShellNoCC {
22+
nativeBuildInputs = with pkgs; [
23+
brotli
24+
ghcid
25+
git
26+
python3
27+
wabt
28+
ghc-wasm-meta.outputs.packages."${system}".all_9_12
29+
];
30+
};
31+
}
32+
);
33+
}

lesson1/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# `lesson1`
2+
3+
In `lesson1`, we build our first wasm app:
4+
[`pointfree`](https://hackage.haskell.org/package/pointfree). It will
5+
be built as a self-contained `wasm32-wasi` module, which can be run by
6+
a non-web engine like [`wasmtime`](https://wasmtime.dev) or in the
7+
browser.
8+
9+
Topics covered:
10+
11+
- Using `wasm32-wasi-cabal` to build a wasm module
12+
- Running a self-contained wasm module
13+
- Disassembling a wasm module
14+
- Optimizing a wasm module
15+
16+
To build `pointfree`, run `build.sh` which is equivalent to:
17+
18+
```bash
19+
wasm32-wasi-cabal install --installdir=dist --install-method=copy --overwrite-policy=always pointfree-1.1.1.12
20+
```
21+
22+
To disassemble the wasm module to a readable text format:
23+
24+
```bash
25+
wasm-tools print dist/pointfree.wasm -o dist/pointfree.wat
26+
```
27+
28+
To run it with `wasmtime`:
29+
30+
```bash
31+
wasmtime run -- dist/pointfree.wasm "\(x, y) -> y x"
32+
```
33+
34+
Here's a stock `wasm-opt` command to optimize a wasm module. Add
35+
`--converge` to make it run multiple passes until the wasm module size
36+
no longer shrinks. Specify `BINARYEN_CORES=4` environment variable to
37+
restrict CPU cores.
38+
39+
```bash
40+
$ wasm-opt --low-memory-unused --strip-dwarf -O4 -Oz dist/pointfree.wasm -o dist/pointfree.wasm
41+
$ ls -Alh dist
42+
total 3.6M
43+
-rwxr-xr-x 1 terrorjack users 3.6M Jun 6 11:01 pointfree.wasm
44+
```
45+
46+
To estimate an optimized wasm module's network transmission size:
47+
48+
```bash
49+
$ brotli --best dist/pointfree.wasm
50+
51+
$ ls -Alh dist
52+
total 4.3M
53+
-rwxr-xr-x 1 terrorjack users 3.6M Jun 6 11:01 pointfree.wasm
54+
-rwxr-xr-x 1 terrorjack users 768K Jun 6 11:01 pointfree.wasm.br
55+
```
56+
57+
Comparison against native executable size:
58+
59+
```bash
60+
$ cabal install --installdir=. --install-method=copy --overwrite-policy=always pointfree-1.1.1.12 --allow-newer=all:base --enable-split-sections
61+
$ ls -Alh
62+
total 14M
63+
-rwxr-xr-x 1 runner docker 14M Jun 6 09:02 pointfree
64+
```

lesson1/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
wasm32-wasi-cabal install --installdir=dist --install-method=copy --overwrite-policy=always pointfree-1.1.1.12

lesson1/cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allow-newer: all:base

0 commit comments

Comments
 (0)