Skip to content

Commit 414c256

Browse files
committed
Add readme
1 parent 49aabb5 commit 414c256

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

Readme.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[![build](https://github.com/pointfree-wasm/pointfree-wasm.github.io/actions/workflows/ci.yml/badge.svg)](https://github.com/pointfree-wasm/pointfree-wasm.github.io/actions/workflows/ci.yml)
2+
3+
# Synopsis
4+
5+
This is a pretty simple Haskell application that runs entirely in the browser thanks to Web Assembly.
6+
7+
The idea was to try out how WASM Haskell backend would handle a package with non-trivial functionality but complicated user interface. The (pointfree package)[https://hackage.haskell.org/package/pointfree] was great fit since it does interesting transformation while its interface is just a string from a user for input and a list of strings for output.
8+
9+
Apart from working pointfree converter in a browser this project might be interesting as a working example on how to use Haskell WASM backend to make other browser applications.
10+
11+
# Building and running locally
12+
13+
These steps are made for Linux/MacOS but should work on Windows as well potentially with some tweaking.
14+
15+
If in doubt you can check how this project’s CI is set up and copy steps from there: https://github.com/pointfree-wasm/pointfree-wasm.github.io/blob/master/.github/workflows/ci.yml. The advantage of CI is that it’s a working version.
16+
17+
## Step 0 - get ordinary Haskell development up and running
18+
19+
Install `ghc` and `cabal`. A good way to do so is via (`ghcup`)[https://www.haskell.org/ghcup/].
20+
21+
## Step 1 - obtaining GHC WASM backend
22+
23+
Please refer to https://gitlab.haskell.org/ghc/ghc-wasm-meta for detailed instructions.
24+
25+
For example, if you use `nix` package manager then use following flake-based command:
26+
27+
```
28+
$ nix shell https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz
29+
```
30+
31+
## Step 2 - ensure `happy` executable is in your PATH
32+
33+
Optionally do `cabal update`, then execute `cabal install happy` with regular ghc.
34+
35+
If you haven’t done so, add cabal’s installation directory to PATH:
36+
37+
```
38+
$ export PATH="$HOME/.cabal/bin:$PATH"
39+
```
40+
41+
Check with `happy --version` that executable is available in the PATH environment variable:
42+
43+
```
44+
$ happy --version
45+
Happy Version 1.20.1.1 Copyright (c) 1993-1996 Andy Gill, Simon Marlow (c) 1997-2005 Simon Marlow
46+
47+
Happy is a Yacc for Haskell, and comes with ABSOLUTELY NO WARRANTY.
48+
This program is free software; you can redistribute it and/or modify
49+
it under the terms given in the file 'LICENSE' distributed with
50+
the Happy sources.
51+
```
52+
53+
NB this step is needed because `haskell-src-exts` depends on the `happy` build tool but `haskell-src-exts` wasn’t updated to let `cabal` quietly provide `happy` during build so `happy` executable has to be on the PATH for the time being.
54+
55+
## Step 3 - build WASM file and other dependencies
56+
57+
After `wasm32-wasi-cabal build all` the resulting `.wasm` file will be at path returned by `wasm32-wasi-cabal list-bin pointfree-wasm:exe:pointfree-wasm`. Link it to the directory where `index.html` is located, i.e. the project’s root.
58+
59+
```
60+
$ ln -s $(wasm32-wasi-cabal list-bin pointfree-wasm:exe:pointfree-wasm) .
61+
```
62+
63+
Then generate `pointfree-wasm.js`:
64+
65+
```
66+
$ $(wasm32-wasi-ghc --print-libdir)/post-link.mjs -i $(wasm32-wasi-cabal list-bin pointfree-wasm:exe:pointfree-wasm) -o pointfree-wasm.js
67+
```
68+
69+
## Step 4 - run web server in project’s root
70+
71+
Any web server would do, good starting point is `python3 -m http.server` if Python is installed.
72+
73+
Now you can open the address the web server is running on in the browser and it should work.

0 commit comments

Comments
 (0)