diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c23bca8..c26f0a3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,12 +9,9 @@ on: workflow_dispatch: jobs: - build: - name: build + nix-build: + name: nix-build runs-on: ubuntu-latest - permissions: - pages: write - id-token: write steps: - name: checkout @@ -27,6 +24,69 @@ jobs: run: | nix develop --command bash -c "cd frontend && wasm32-wasi-cabal update && exec ./build.sh --debuginfo --low-memory-unused --converge --gufa --flatten --rereloop -Oz" + ghcup-build: + name: ghcup-build + runs-on: ubuntu-latest + steps: + + - name: checkout + uses: actions/checkout@v4 + + - name: ghc-wasm-meta + run: | + pushd "$(mktemp -d)" + curl -f -L --retry 5 https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1 + SKIP_GHC=1 ./setup.sh + ~/.ghc-wasm/add_to_github_path.sh + popd + + - name: wasm32-wasi-ghc + run: | + ghcup config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/develop/ghcup-cross-0.0.8.yaml + ghcup install ghc --set wasm32-wasi-9.10.0.20240412 -- $CONFIGURE_ARGS + + - name: install-sass + run: | + npm install -g sass + + - name: build-frontend + run: | + cd frontend + cabal \ + --with-compiler=wasm32-wasi-ghc \ + --with-hc-pkg=wasm32-wasi-ghc-pkg \ + --with-hsc2hs=wasm32-wasi-hsc2hs \ + update + ./build.sh --debuginfo --low-memory-unused --converge --gufa --flatten --rereloop -Oz + + non-nix-build: + name: non-nix-build + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + steps: + + - name: checkout + uses: actions/checkout@v4 + + - name: ghc-wasm-meta + run: | + pushd "$(mktemp -d)" + curl -f -L --retry 5 https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1 + ./setup.sh + ~/.ghc-wasm/add_to_github_path.sh + popd + + - name: install-sass + run: | + npm install -g sass + + - name: build-frontend + run: | + cd frontend + ./build.sh --debuginfo --low-memory-unused --converge --gufa --flatten --rereloop -Oz + - name: upload-pages-artifact uses: actions/upload-pages-artifact@v3 with: diff --git a/README.md b/README.md index e2efc66..2a2033c 100644 --- a/README.md +++ b/README.md @@ -19,27 +19,40 @@ under the hood. ## Building +### With nix + Within the `nix develop` shell: ```sh cd frontend -npm install wasm32-wasi-cabal update -./build.sh -Oz +./build.sh ``` -The artifacts will be available in `frontend/dist`. The arguments -passed to `build.sh` are redirected to `wasm-opt`, if omitted, a dev -build without `wasm-opt` will be performed. +If you pass additional arguments to `build.sh`, they will be +redirected to `wasm-opt`, otherwise a dev build without `wasm-opt` +will be performed. + +The artifacts will be available in `frontend/dist`. + +### Without nix + +You can set up the toolchain by either: -They can also be built without nix, as long as the following -dependencies are met: +- Using + [`ghc-wasm-meta`](https://gitlab.haskell.org/ghc/ghc-wasm-meta#getting-started-without-nix) + directly to set up ghc head or ghc 9.10 +- Using [`ghcup`](https://www.haskell.org/ghcup/guide/#cross-support) + to set up ghc 9.10 -- `wasm32-wasi-ghc`/`wasm32-wasi-cabal` (use `ghc-9.10` branch, JSFFI is not - present in `ghc-9.6`/`ghc-9.8`) -- `node` (at least `v21.2.0`) -- `npm` -- `sass` +Then: + +```sh +source ~/.ghc-wasm/env +npm install -g sass +cd frontend +./build.sh +``` ## Acknowledgements diff --git a/cabal.project b/cabal.project index 4f22bcf..f6b576c 100644 --- a/cabal.project +++ b/cabal.project @@ -1,6 +1,6 @@ packages: . hs2048 -index-state: 2024-04-15T08:03:57Z +index-state: 2024-04-20T23:09:54Z if arch(wasm32) -- https://github.com/haskellari/splitmix/pull/73 diff --git a/flake.lock b/flake.lock index 3a029f9..81f5ca1 100644 --- a/flake.lock +++ b/flake.lock @@ -25,11 +25,11 @@ }, "locked": { "host": "gitlab.haskell.org", - "lastModified": 1712545072, - "narHash": "sha256-vb/6GtGmp/7wM74vEi7z1VmD9Tb0NWqVMIETf2bDoX8=", + "lastModified": 1713652818, + "narHash": "sha256-xwrapP27yKJ1oy5ykPE3X+feF+MLGdSvPnjbdE1M00c=", "owner": "ghc", "repo": "ghc-wasm-meta", - "rev": "48ecacd922638487f65981c0018044b55dc7feb9", + "rev": "e1123a732a70938b817caa7470aa4124913937e1", "type": "gitlab" }, "original": { @@ -41,11 +41,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1712439257, - "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", + "lastModified": 1713537308, + "narHash": "sha256-XtTSSIB2DA6tOv+l0FhvfDMiyCmhoRbNB+0SeInZkbk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", + "rev": "5c24cf2f0a12ad855f444c30b2421d044120c66f", "type": "github" }, "original": { diff --git a/frontend/build.sh b/frontend/build.sh index d80cbc1..5bac142 100755 --- a/frontend/build.sh +++ b/frontend/build.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash + set -e +if [[ $PWD != */frontend ]]; then + echo "This script is meant to be run in the frontend directory" + exit 1 +fi + if [ $# -eq 0 ]; then echo "Building for dev" dev_mode=true @@ -13,7 +19,16 @@ rm -rf dist mkdir dist cp ./*.html dist/ -wasm32-wasi-cabal build ghc-wasm-miso-examples +if command -v wasm32-wasi-cabal &>/dev/null; then + wasm32-wasi-cabal build ghc-wasm-miso-examples +else + cabal \ + --with-compiler=wasm32-wasi-ghc \ + --with-hc-pkg=wasm32-wasi-ghc-pkg \ + --with-hsc2hs=wasm32-wasi-hsc2hs \ + build ghc-wasm-miso-examples +fi + hs_wasm_path=$(find .. -name "*.wasm") "$(wasm32-wasi-ghc --print-libdir)"/post-link.mjs \