From a125792f6fc1d7b013d7d2bec3a8fa00029a5003 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Fri, 6 Jun 2025 00:42:04 +0800 Subject: [PATCH 01/18] Add all deps for building on wasm32 --- .gitmodules | 16 ++++++++++++++++ BUILDING_WASM.md | 27 +++++++++++++++++++++++++++ agda-language-server.cabal | 20 ++++++++++---------- app/Main.hs | 2 +- cabal.project | 8 ++++++++ src/Options.hs | 2 +- wasm-submodules/agda | 1 + wasm-submodules/foundation | 1 + wasm-submodules/lsp | 1 + wasm-submodules/network | 1 + wasm-submodules/network-simple-0.4.2 | 1 + 11 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 100644 BUILDING_WASM.md create mode 100644 cabal.project create mode 160000 wasm-submodules/agda create mode 160000 wasm-submodules/foundation create mode 160000 wasm-submodules/lsp create mode 160000 wasm-submodules/network create mode 160000 wasm-submodules/network-simple-0.4.2 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c80f1dd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,16 @@ +[submodule "wasm-submodules/agda"] + path = wasm-submodules/agda + url = git@github.com:agda-web/agda.git +[submodule "wasm-submodules/foundation"] + path = wasm-submodules/foundation + url = git@github.com:haskell-wasm/foundation.git +[submodule "wasm-submodules/network"] + path = wasm-submodules/network + url = https://github.com/haskell-wasm/network +[submodule "wasm-submodules/network-simple-0.4.2"] + path = wasm-submodules/network-simple-0.4.2 + url = https://github.com/k0001/network-simple +[submodule "wasm-submodules/lsp"] + path = wasm-submodules/lsp + url = git@github.com:agda-web/lsp.git + diff --git a/BUILDING_WASM.md b/BUILDING_WASM.md new file mode 100644 index 0000000..084d287 --- /dev/null +++ b/BUILDING_WASM.md @@ -0,0 +1,27 @@ +# How to build on WASM + +1. Setup a working ghc (tested with v9.10) with WASM backend and wasm32-wasi-cabal. +2. `cd` into `wasm-submodules/network` and run `autoreconf -i`. +3. In the project root, run `wasm32-wasi-cabal build`. + +The process might output the following: + +``` +[442 of 452] Compiling Language.LSP.Protocol.Message.Types ( src/Language/LSP/Protocol/Message/Types.hs, /home/qbane/agda-project/haskell-lsp-wasm/dist-newstyle/build/wasm32-wasi/ghc-9.10.1.20250207/lsp-types-2.3.0.1/build/Language/LSP/Protocol/Message/Types.o, /home/qbane/agda-project/haskell-lsp-wasm/dist-newstyle/build/wasm32-wasi/ghc-9.10.1.20250207/lsp-types-2.3.0.1/build/Language/LSP/Protocol/Message/Types.dyn_o ) + +wasm://wasm/001e3c92:1 + + +RuntimeError: table index is out of bounds + at wasm://wasm/001e3c92:wasm-function[586]:0x45e40 + at wasm://wasm/001e3c92:wasm-function[365]:0x286e1 + at wasm://wasm/001e3c92:wasm-function[595]:0x46135 + at process.processImmediate (node:internal/timers:491:21) + +Node.js v22.14.0 +``` + +At this moment, you should terminate the process and run it again. +If this does *not* occur to you or you can fix it, please let me know. + +If everything works properly, it should build a `als.wasm`. diff --git a/agda-language-server.cabal b/agda-language-server.cabal index d970f61..818d5f2 100644 --- a/agda-language-server.cabal +++ b/agda-language-server.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: agda-language-server -version: 0.2.7.0.1.4 +version: 0.2.7.0.1.5 synopsis: An implementation of language server protocal (LSP) for Agda 2. description: Please see the README on GitHub at category: Development @@ -43,7 +43,7 @@ flag Agda-2-6-4-3 flag Agda-2-7-0-1 description: Embed Agda-2.7.0.1 manual: True - default: False + default: True library exposed-modules: @@ -94,13 +94,13 @@ library , lsp-types >=2 , mtl , network - , network-simple + , network-simple == 0.4.2 , prettyprinter , process , stm , strict , text - , text-icu + -- , text-icu default-language: Haskell2010 if flag(Agda-2-6-3) build-depends: @@ -123,7 +123,7 @@ executable als OverloadedStrings PatternSynonyms TypeOperators - ghc-options: -Wincomplete-patterns -Wunused-do-bind -Wunused-foralls -Wwarnings-deprecations -Wwrong-do-bind -Wmissing-fields -Wmissing-methods -Wmissing-pattern-synonym-signatures -Wmissing-signatures -threaded -rtsopts -with-rtsopts=-N -Werror=incomplete-patterns -fno-warn-orphans + ghc-options: -Wincomplete-patterns -Wunused-do-bind -Wunused-foralls -Wwarnings-deprecations -Wwrong-do-bind -Wmissing-fields -Wmissing-methods -Wmissing-pattern-synonym-signatures -Wmissing-signatures -rtsopts -Werror=incomplete-patterns -fno-warn-orphans build-depends: Agda , aeson @@ -137,13 +137,13 @@ executable als , lsp-types >=2 , mtl , network - , network-simple + , network-simple == 0.4.2 , prettyprinter , process , stm , strict , text - , text-icu + -- , text-icu default-language: Haskell2010 if flag(Agda-2-6-3) build-depends: @@ -195,7 +195,7 @@ test-suite als-test OverloadedStrings PatternSynonyms TypeOperators - ghc-options: -Wincomplete-patterns -Wunused-do-bind -Wunused-foralls -Wwarnings-deprecations -Wwrong-do-bind -Wmissing-fields -Wmissing-methods -Wmissing-pattern-synonym-signatures -Wmissing-signatures -threaded -rtsopts -with-rtsopts=-N -Werror=incomplete-patterns -fno-warn-orphans + ghc-options: -Wincomplete-patterns -Wunused-do-bind -Wunused-foralls -Wwarnings-deprecations -Wwrong-do-bind -Wmissing-fields -Wmissing-methods -Wmissing-pattern-synonym-signatures -Wmissing-signatures -rtsopts -Werror=incomplete-patterns -fno-warn-orphans build-depends: Agda , aeson @@ -209,7 +209,7 @@ test-suite als-test , lsp-types >=2 , mtl , network - , network-simple + , network-simple == 0.4.2 , prettyprinter , process , stm @@ -219,7 +219,7 @@ test-suite als-test , tasty-hunit , tasty-quickcheck , text - , text-icu + -- , text-icu default-language: Haskell2010 if flag(Agda-2-6-3) build-depends: diff --git a/app/Main.hs b/app/Main.hs index ba3291d..dd22719 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -38,4 +38,4 @@ main = do else do _ <- run options -- _ <- run - return () \ No newline at end of file + return () diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..78a8cd0 --- /dev/null +++ b/cabal.project @@ -0,0 +1,8 @@ +packages: + . + wasm-submodules/agda + wasm-submodules/foundation/basement + wasm-submodules/network + wasm-submodules/network-simple-0.4.2 + wasm-submodules/lsp/lsp-types + diff --git a/src/Options.hs b/src/Options.hs index b0b700e..8e26f09 100644 --- a/src/Options.hs +++ b/src/Options.hs @@ -72,7 +72,7 @@ options = ] versionNumber :: Int -versionNumber = 5 +versionNumber = 5999 versionString :: String versionString = diff --git a/wasm-submodules/agda b/wasm-submodules/agda new file mode 160000 index 0000000..3e4973b --- /dev/null +++ b/wasm-submodules/agda @@ -0,0 +1 @@ +Subproject commit 3e4973bd3ae732c0e70692491fd9e98c6edcd7f9 diff --git a/wasm-submodules/foundation b/wasm-submodules/foundation new file mode 160000 index 0000000..8e6dd48 --- /dev/null +++ b/wasm-submodules/foundation @@ -0,0 +1 @@ +Subproject commit 8e6dd48527fb429c1922083a5030ef88e3d58dd3 diff --git a/wasm-submodules/lsp b/wasm-submodules/lsp new file mode 160000 index 0000000..9baf76e --- /dev/null +++ b/wasm-submodules/lsp @@ -0,0 +1 @@ +Subproject commit 9baf76e6d9965a3b6e8b3ecfcdf33c62b5628fd8 diff --git a/wasm-submodules/network b/wasm-submodules/network new file mode 160000 index 0000000..1dc8708 --- /dev/null +++ b/wasm-submodules/network @@ -0,0 +1 @@ +Subproject commit 1dc870889eee4ac733335ced4e274b4dfe8ed369 diff --git a/wasm-submodules/network-simple-0.4.2 b/wasm-submodules/network-simple-0.4.2 new file mode 160000 index 0000000..2c3ab6e --- /dev/null +++ b/wasm-submodules/network-simple-0.4.2 @@ -0,0 +1 @@ +Subproject commit 2c3ab6e7aa2a86be692c55bf6081161d83d50c34 From 4eb616d30890b74caeddf67b4b84276f7795e3a8 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 12 Jun 2025 10:52:48 +0800 Subject: [PATCH 02/18] Add workflow to compile wasm --- .github/workflows/wasm.yaml | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/wasm.yaml diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml new file mode 100644 index 0000000..96e9fe6 --- /dev/null +++ b/.github/workflows/wasm.yaml @@ -0,0 +1,84 @@ +name: Compile WASM + +on: [push, pull_request, workflow_dispatch] + +env: + GHC_WASM_META_FLAVOUR: '9.10' + GHC_WASM_META_COMMIT_HASH: fe5573f28327d12a1c47ec61d6bbe0cc9d7983dd + +jobs: + build: + name: Build + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + with: + path: als + submodules: recursive + + - name: Try to restore cached .ghc-wasm + id: ghc-wasm-cache-restore + uses: actions/cache/restore@v4 + with: + path: ~/.ghc-wasm + key: ${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-r0-ghc-wasm + + - name: Clone and setup ghc-wasm-meta + id: ghc-wasm-setup + if: steps.ghc-wasm-cache-restore.outputs.cache-hit != 'true' + run: | + mkdir ghc-wasm-meta + cd ghc-wasm-meta + git config --global init.defaultBranch dontcare + git config --global advice.detachedHead false + git init + git remote add origin https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta.git + git fetch origin ${{ env.GHC_WASM_META_COMMIT_HASH }} --depth=1 + git checkout FETCH_HEAD + FLAVOUR=${{ env.GHC_WASM_META_FLAVOUR }} ./setup.sh + + - name: Delete cabal's store + if: steps.ghc-wasm-setup.outcome == 'success' + run: | + mv ~/.ghc-wasm/.cabal/config /tmp/cabal-config + rm -rf ~/.ghc-wasm/.cabal + mkdir ~/.ghc-wasm/.cabal + mv /tmp/cabal-config ~/.ghc-wasm/.cabal/config + + - name: Cache ghc-wasm-meta + if: steps.ghc-wasm-setup.outcome == 'success' + uses: actions/cache/save@v4 + with: + path: ~/.ghc-wasm + key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} + + - name: Add ghc-wasm-meta to PATH + run: ~/.ghc-wasm/add_to_github_path.sh + + # setup script also updates package store near the end + - name: Update wasm32 cabal + if: steps.ghc-wasm-setup.outcome == 'success' || steps.ghc-wasm-setup.outcome == 'skipped' + run: wasm32-wasi-cabal update + + - name: Build als + run: | + ~/.ghc-wasm/cabal/bin/cabal update + ~/.ghc-wasm/cabal/bin/cabal install alex-3.5.0.0 happy-1.20.1.1 + mkdir ~/out + cd als/wasm-submodules/network + autoreconf -i + cd ../.. + echo "---------------- First build attmept (should timeout) ----------------" + timeout 30m wasm32-wasi-cabal build || true + echo "---------------- Second build attempt (should succeed) ----------------" + wasm32-wasi-cabal build + echo "---------------- DONE ----------------" + cp $(wasm32-wasi-cabal list-bin als) ~/out + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: als + path: ~/out + include-hidden-files: true From 1ed418696d21b4f0ce9b1bb43ac79ea7f48d056a Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 12 Jun 2025 11:39:35 +0800 Subject: [PATCH 03/18] Bump Agda revision --- wasm-submodules/agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-submodules/agda b/wasm-submodules/agda index 3e4973b..87cac9c 160000 --- a/wasm-submodules/agda +++ b/wasm-submodules/agda @@ -1 +1 @@ -Subproject commit 3e4973bd3ae732c0e70692491fd9e98c6edcd7f9 +Subproject commit 87cac9ce17932321dc1a0fdaed83436de22fa0aa From 2f54d51040651bb74d61fb02d37d18f3aeb42e2b Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 26 Jun 2025 04:03:20 +0800 Subject: [PATCH 04/18] Build lsp-types first --- .github/workflows/wasm.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 96e9fe6..6c7b631 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -4,7 +4,7 @@ on: [push, pull_request, workflow_dispatch] env: GHC_WASM_META_FLAVOUR: '9.10' - GHC_WASM_META_COMMIT_HASH: fe5573f28327d12a1c47ec61d6bbe0cc9d7983dd + GHC_WASM_META_COMMIT_HASH: '913a51e58b330f00e3b0ad5b89184cad328ea109' jobs: build: @@ -69,9 +69,11 @@ jobs: cd als/wasm-submodules/network autoreconf -i cd ../.. - echo "---------------- First build attmept (should timeout) ----------------" - timeout 30m wasm32-wasi-cabal build || true - echo "---------------- Second build attempt (should succeed) ----------------" + echo "---------------- lsp-types First build attmept (should timeout) ----------------" + timeout 10m wasm32-wasi-cabal build lib:lsp-types || true + echo "---------------- lsp-types Second build attempt (should succeed) ----------------" + wasm32-wasi-cabal build lib:lsp-types + echo "---------------- Build everything else ----------------" wasm32-wasi-cabal build echo "---------------- DONE ----------------" cp $(wasm32-wasi-cabal list-bin als) ~/out From db2955f9dd2b27085be80c7f1cf28b3532326478 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Fri, 27 Jun 2025 01:50:16 +0800 Subject: [PATCH 05/18] Split the build task & Cache cabal store --- .github/workflows/wasm.yaml | 51 ++++++++++++++++++++----------------- BUILDING_WASM.md | 4 +-- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 6c7b631..3e0b3ab 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -38,21 +38,6 @@ jobs: git checkout FETCH_HEAD FLAVOUR=${{ env.GHC_WASM_META_FLAVOUR }} ./setup.sh - - name: Delete cabal's store - if: steps.ghc-wasm-setup.outcome == 'success' - run: | - mv ~/.ghc-wasm/.cabal/config /tmp/cabal-config - rm -rf ~/.ghc-wasm/.cabal - mkdir ~/.ghc-wasm/.cabal - mv /tmp/cabal-config ~/.ghc-wasm/.cabal/config - - - name: Cache ghc-wasm-meta - if: steps.ghc-wasm-setup.outcome == 'success' - uses: actions/cache/save@v4 - with: - path: ~/.ghc-wasm - key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} - - name: Add ghc-wasm-meta to PATH run: ~/.ghc-wasm/add_to_github_path.sh @@ -61,23 +46,43 @@ jobs: if: steps.ghc-wasm-setup.outcome == 'success' || steps.ghc-wasm-setup.outcome == 'skipped' run: wasm32-wasi-cabal update - - name: Build als + - name: Install native utilities run: | + echo ">>> Update cabal" ~/.ghc-wasm/cabal/bin/cabal update + echo ">>> Install alex and happy" ~/.ghc-wasm/cabal/bin/cabal install alex-3.5.0.0 happy-1.20.1.1 - mkdir ~/out + + - name: 'Build dep: lsp-types' + uses: nick-fields/retry@v3 + with: + timeout_minutes: 10 + max_attempts: 2 + command: wasm32-wasi-cabal build lib:lsp-types + + - name: 'Build dep: agda' + run: wasm32-wasi-cabal build lib:agda + + - name: Build every dependency else + run: | cd als/wasm-submodules/network autoreconf -i cd ../.. - echo "---------------- lsp-types First build attmept (should timeout) ----------------" - timeout 10m wasm32-wasi-cabal build lib:lsp-types || true - echo "---------------- lsp-types Second build attempt (should succeed) ----------------" - wasm32-wasi-cabal build lib:lsp-types - echo "---------------- Build everything else ----------------" + wasm32-wasi-cabal build --dependencies-only + + - name: Build als + run: | + mkdir ~/out wasm32-wasi-cabal build - echo "---------------- DONE ----------------" cp $(wasm32-wasi-cabal list-bin als) ~/out + - name: Cache ghc-wasm-meta + uses: actions/cache/save@v4 + if: always() + with: + path: ~/.ghc-wasm + key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} + - name: Upload artifact uses: actions/upload-artifact@v4 with: diff --git a/BUILDING_WASM.md b/BUILDING_WASM.md index 084d287..6b76b2b 100644 --- a/BUILDING_WASM.md +++ b/BUILDING_WASM.md @@ -1,4 +1,4 @@ -# How to build on WASM +# How to build for WASM 1. Setup a working ghc (tested with v9.10) with WASM backend and wasm32-wasi-cabal. 2. `cd` into `wasm-submodules/network` and run `autoreconf -i`. @@ -22,6 +22,6 @@ Node.js v22.14.0 ``` At this moment, you should terminate the process and run it again. -If this does *not* occur to you or you can fix it, please let me know. +This is a known issue ([ghc#26106](https://gitlab.haskell.org/ghc/ghc/-/issues/26106)). If this does *not* occur to you or you can fix it, please report to that issue. If everything works properly, it should build a `als.wasm`. From e8f01d33275cea1672581a45e2667c75122feaf4 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Fri, 27 Jun 2025 01:57:47 +0800 Subject: [PATCH 06/18] Fix working dir --- .github/workflows/wasm.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 3e0b3ab..e739b6b 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -58,19 +58,22 @@ jobs: with: timeout_minutes: 10 max_attempts: 2 - command: wasm32-wasi-cabal build lib:lsp-types + command: cd als && wasm32-wasi-cabal build lib:lsp-types - name: 'Build dep: agda' + working-directory: './als' run: wasm32-wasi-cabal build lib:agda - name: Build every dependency else + working-directory: './als' run: | - cd als/wasm-submodules/network + cd wasm-submodules/network autoreconf -i cd ../.. wasm32-wasi-cabal build --dependencies-only - name: Build als + working-directory: './als' run: | mkdir ~/out wasm32-wasi-cabal build From a0be5ecfc2014f9adde280978c8354767e7f7360 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Fri, 27 Jun 2025 02:42:04 +0800 Subject: [PATCH 07/18] Respecify cache name using hashFiles --- .github/workflows/wasm.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index e739b6b..ca61f7b 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -22,11 +22,13 @@ jobs: uses: actions/cache/restore@v4 with: path: ~/.ghc-wasm - key: ${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-r0-ghc-wasm + key: "ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-${{ hashFiles('.ghc-wasm/**') }}" + restore-keys: | + 'ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-' - name: Clone and setup ghc-wasm-meta id: ghc-wasm-setup - if: steps.ghc-wasm-cache-restore.outputs.cache-hit != 'true' + if: steps.ghc-wasm-cache-restore.outputs.cache-matched-key == '' run: | mkdir ghc-wasm-meta cd ghc-wasm-meta @@ -79,6 +81,9 @@ jobs: wasm32-wasi-cabal build cp $(wasm32-wasi-cabal list-bin als) ~/out + - name: Clean up cabal logs + run: rm -rf ~/.ghc-wasm/.cabal/logs + - name: Cache ghc-wasm-meta uses: actions/cache/save@v4 if: always() From b98a610e3b23285300f6786c1f4cd243ef0a693e Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Fri, 27 Jun 2025 03:49:56 +0800 Subject: [PATCH 08/18] Try again --- .github/workflows/wasm.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index ca61f7b..c249cb1 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -22,7 +22,7 @@ jobs: uses: actions/cache/restore@v4 with: path: ~/.ghc-wasm - key: "ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-${{ hashFiles('.ghc-wasm/**') }}" + key: 'ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}' restore-keys: | 'ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-' @@ -89,7 +89,7 @@ jobs: if: always() with: path: ~/.ghc-wasm - key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} + key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }}-${{ hashFiles('.ghc-wasm/**') }} - name: Upload artifact uses: actions/upload-artifact@v4 From 2fa0589a6b11b097dd660db48a6617fe8b5967de Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 28 Jun 2025 15:02:43 +0800 Subject: [PATCH 09/18] Also cache dist-newstyle --- .github/workflows/wasm.yaml | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index c249cb1..60508f6 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -17,14 +17,26 @@ jobs: path: als submodules: recursive + - name: Compute cache key + run: echo "CI_CACHE_KEY=${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}" >> "$GITHUB_ENV" + - name: Try to restore cached .ghc-wasm id: ghc-wasm-cache-restore uses: actions/cache/restore@v4 with: - path: ~/.ghc-wasm - key: 'ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}' + path: | + ~/.cabal + ~/.ghc-wasm + key: ghc-wasm-${{ env.CI_CACHE_KEY }} + + - name: Try to restore cached dist-newstyle + id: dist-newstyle-cache-restore + uses: actions/cache/restore@v4 + with: + path: dist-newstyle + key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('dist-newstyle/**') }} restore-keys: | - 'ghc-wasm-${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-' + dist-newstyle-${{ env.CI_CACHE_KEY }}- - name: Clone and setup ghc-wasm-meta id: ghc-wasm-setup @@ -57,15 +69,24 @@ jobs: - name: 'Build dep: lsp-types' uses: nick-fields/retry@v3 + id: build-dep-lsp-types with: timeout_minutes: 10 max_attempts: 2 command: cd als && wasm32-wasi-cabal build lib:lsp-types - name: 'Build dep: agda' + id: build-dep-agda working-directory: './als' run: wasm32-wasi-cabal build lib:agda + - name: Cache dist-newstyle + uses: actions/cache/save@v4 + if: steps.build-dep-lsp-types.outcome == 'success' && steps.build-dep-agda.outcome == 'success' + with: + path: dist-newstyle + key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('dist-newstyle/**') }} + - name: Build every dependency else working-directory: './als' run: | @@ -82,14 +103,16 @@ jobs: cp $(wasm32-wasi-cabal list-bin als) ~/out - name: Clean up cabal logs - run: rm -rf ~/.ghc-wasm/.cabal/logs + run: rm -rf ~/.cabal/logs ~/.ghc-wasm/.cabal/logs - name: Cache ghc-wasm-meta uses: actions/cache/save@v4 if: always() with: - path: ~/.ghc-wasm - key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }}-${{ hashFiles('.ghc-wasm/**') }} + path: + ~/.cabal + ~/.ghc-wasm + key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} - name: Upload artifact uses: actions/upload-artifact@v4 From 371d804a5b839996003515a75eb2f2d17a138350 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 28 Jun 2025 23:45:32 +0800 Subject: [PATCH 10/18] Fix typos --- .github/workflows/wasm.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 60508f6..7149f06 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -33,8 +33,8 @@ jobs: id: dist-newstyle-cache-restore uses: actions/cache/restore@v4 with: - path: dist-newstyle - key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('dist-newstyle/**') }} + path: als/dist-newstyle + key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('als/dist-newstyle/**') }} restore-keys: | dist-newstyle-${{ env.CI_CACHE_KEY }}- @@ -84,8 +84,8 @@ jobs: uses: actions/cache/save@v4 if: steps.build-dep-lsp-types.outcome == 'success' && steps.build-dep-agda.outcome == 'success' with: - path: dist-newstyle - key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('dist-newstyle/**') }} + path: als/dist-newstyle + key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('als/dist-newstyle/**') }} - name: Build every dependency else working-directory: './als' @@ -109,7 +109,7 @@ jobs: uses: actions/cache/save@v4 if: always() with: - path: + path: | ~/.cabal ~/.ghc-wasm key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} From eb58eb8aff0decdc81f902160676c778d49b407c Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 28 Jun 2025 23:52:59 +0800 Subject: [PATCH 11/18] Cache native cabal from ~/.config --- .github/workflows/wasm.yaml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 7149f06..31fa180 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -24,11 +24,16 @@ jobs: id: ghc-wasm-cache-restore uses: actions/cache/restore@v4 with: - path: | - ~/.cabal - ~/.ghc-wasm + path: ~/.ghc-wasm key: ghc-wasm-${{ env.CI_CACHE_KEY }} + - name: Try to restore cached native cabal + id: native-cabal-cache-restore + uses: actions/cache/restore@v4 + with: + path: ~/.config/cabal + key: native-cabal-${{ env.CI_CACHE_KEY }} + - name: Try to restore cached dist-newstyle id: dist-newstyle-cache-restore uses: actions/cache/restore@v4 @@ -103,15 +108,20 @@ jobs: cp $(wasm32-wasi-cabal list-bin als) ~/out - name: Clean up cabal logs - run: rm -rf ~/.cabal/logs ~/.ghc-wasm/.cabal/logs + run: rm -rf ~/.config/cabal/logs ~/.ghc-wasm/.cabal/logs + + - name: Cache native cabal + uses: actions/cache/save@v4 + if: always() + with: + path: ~/.config/cabal + key: ${{ steps.native-cabal-cache-restore.outputs.cache-primary-key }} - name: Cache ghc-wasm-meta uses: actions/cache/save@v4 if: always() with: - path: | - ~/.cabal - ~/.ghc-wasm + path: ~/.ghc-wasm key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} - name: Upload artifact From 0ccdb815a4303f76f4ba3a4300b54054d06a3b53 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 29 Jun 2025 00:22:23 +0800 Subject: [PATCH 12/18] Use the XDG-adhering path to cache native cabal store --- .github/workflows/wasm.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 31fa180..667be77 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -31,7 +31,9 @@ jobs: id: native-cabal-cache-restore uses: actions/cache/restore@v4 with: - path: ~/.config/cabal + path: | + ~/.config/cabal + ~/.cache/cabal key: native-cabal-${{ env.CI_CACHE_KEY }} - name: Try to restore cached dist-newstyle @@ -107,14 +109,16 @@ jobs: wasm32-wasi-cabal build cp $(wasm32-wasi-cabal list-bin als) ~/out - - name: Clean up cabal logs - run: rm -rf ~/.config/cabal/logs ~/.ghc-wasm/.cabal/logs + - name: Clean up native/wasm cabal logs + run: rm -rf ~/.cache/cabal/logs ~/.ghc-wasm/.cabal/logs - name: Cache native cabal uses: actions/cache/save@v4 if: always() with: - path: ~/.config/cabal + path: | + ~/.config/cabal + ~/.cache/cabal key: ${{ steps.native-cabal-cache-restore.outputs.cache-primary-key }} - name: Cache ghc-wasm-meta From b426b80c16568dd75b7b4c88ecf52aa3373e9172 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 14 Jul 2025 22:50:06 +0800 Subject: [PATCH 13/18] Clean up cabal file and package.yaml --- .github/workflows/wasm.yaml | 2 +- agda-language-server.cabal | 5 +---- package.yaml | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 667be77..775a598 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -106,7 +106,7 @@ jobs: working-directory: './als' run: | mkdir ~/out - wasm32-wasi-cabal build + wasm32-wasi-cabal build --flag=Agda-2-7-0-1 cp $(wasm32-wasi-cabal list-bin als) ~/out - name: Clean up native/wasm cabal logs diff --git a/agda-language-server.cabal b/agda-language-server.cabal index 818d5f2..56bd58f 100644 --- a/agda-language-server.cabal +++ b/agda-language-server.cabal @@ -43,7 +43,7 @@ flag Agda-2-6-4-3 flag Agda-2-7-0-1 description: Embed Agda-2.7.0.1 manual: True - default: True + default: False library exposed-modules: @@ -100,7 +100,6 @@ library , stm , strict , text - -- , text-icu default-language: Haskell2010 if flag(Agda-2-6-3) build-depends: @@ -143,7 +142,6 @@ executable als , stm , strict , text - -- , text-icu default-language: Haskell2010 if flag(Agda-2-6-3) build-depends: @@ -219,7 +217,6 @@ test-suite als-test , tasty-hunit , tasty-quickcheck , text - -- , text-icu default-language: Haskell2010 if flag(Agda-2-6-3) build-depends: diff --git a/package.yaml b/package.yaml index 5bc37cc..63e85e4 100644 --- a/package.yaml +++ b/package.yaml @@ -68,7 +68,6 @@ dependencies: - strict - stm - text - - text-icu - process - prettyprinter From 6db17dc540ac05aa038059230fe4de2dc398d3d4 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 14 Jul 2025 22:55:00 +0800 Subject: [PATCH 14/18] Bump the revision of ghc-wasm-meta used in CI --- .github/workflows/wasm.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 775a598..bb61a28 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -4,7 +4,7 @@ on: [push, pull_request, workflow_dispatch] env: GHC_WASM_META_FLAVOUR: '9.10' - GHC_WASM_META_COMMIT_HASH: '913a51e58b330f00e3b0ad5b89184cad328ea109' + GHC_WASM_META_COMMIT_HASH: '7927129e42bcd6a54b9e06e26455803fa4878261' jobs: build: From d792f1a00f5bad0243855f697c60d8cd3934d92b Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 14 Jul 2025 23:08:06 +0800 Subject: [PATCH 15/18] Make configure a separate step in CI --- .github/workflows/wasm.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index bb61a28..cf079f6 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -74,6 +74,10 @@ jobs: echo ">>> Install alex and happy" ~/.ghc-wasm/cabal/bin/cabal install alex-3.5.0.0 happy-1.20.1.1 + - name: Run cabal configure + working-directory: './als' + run: wasm32-wasi-cabal configure --flag=Agda-2-7-0-1 + - name: 'Build dep: lsp-types' uses: nick-fields/retry@v3 id: build-dep-lsp-types @@ -106,7 +110,7 @@ jobs: working-directory: './als' run: | mkdir ~/out - wasm32-wasi-cabal build --flag=Agda-2-7-0-1 + wasm32-wasi-cabal build cp $(wasm32-wasi-cabal list-bin als) ~/out - name: Clean up native/wasm cabal logs From b1fce53a53be7aaf1a024c806903b30aa81d9754 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 14 Jul 2025 23:21:42 +0800 Subject: [PATCH 16/18] Only cache ghc-wasm-meta when its setup succeeds --- .github/workflows/wasm.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index cf079f6..125eee2 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -118,7 +118,7 @@ jobs: - name: Cache native cabal uses: actions/cache/save@v4 - if: always() + if: steps.ghc-wasm-setup.outcome == 'success' with: path: | ~/.config/cabal @@ -127,7 +127,7 @@ jobs: - name: Cache ghc-wasm-meta uses: actions/cache/save@v4 - if: always() + if: steps.ghc-wasm-setup.outcome == 'success' with: path: ~/.ghc-wasm key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }} From 8cc3d415c1761deb2624333a091b34f8c7c838a4 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 19 Jul 2025 02:31:10 +0800 Subject: [PATCH 17/18] Use a different version string for the WebAssembly build and unclobber the version number --- src/Options.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Options.hs b/src/Options.hs index 8e26f09..e77a432 100644 --- a/src/Options.hs +++ b/src/Options.hs @@ -72,11 +72,13 @@ options = ] versionNumber :: Int -versionNumber = 5999 +versionNumber = 5 versionString :: String versionString = -#if MIN_VERSION_Agda(2,7,0) +#ifdef wasm32_HOST_ARCH + "Agda v2.7.0.1 Language Server (WebAssembly build) v" <> show versionNumber +#elif MIN_VERSION_Agda(2,7,0) "Agda v2.7.0.1 Language Server v" <> show versionNumber #elif MIN_VERSION_Agda(2,6,4) "Agda v2.6.4.3 Language Server v" <> show versionNumber From cec3d3d03ee02a73349b32a818d8b78ff0d6b2c8 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Wed, 23 Jul 2025 02:59:05 +0800 Subject: [PATCH 18/18] Add wasm32-specific patch to warn on runtimes without non-blocking stdin support --- agda-language-server.cabal | 3 +++ src/Server.hs | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/agda-language-server.cabal b/agda-language-server.cabal index 56bd58f..a4865f7 100644 --- a/agda-language-server.cabal +++ b/agda-language-server.cabal @@ -110,6 +110,9 @@ library if flag(Agda-2-7-0-1) build-depends: Agda ==2.7.0.1 + if arch(wasm32) + build-depends: + unix >=2.8.0.0 && <2.9 executable als main-is: Main.hs diff --git a/src/Server.hs b/src/Server.hs index c9b1ffc..e92225e 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -28,6 +28,12 @@ import qualified Server.Handler as Handler import Switchboard (Switchboard, agdaCustomMethod) import qualified Switchboard +#if defined(wasm32_HOST_ARCH) +import Agda.Utils.IO (catchIO) +import System.IO (hPutStrLn, stderr) +import System.Posix.IO (stdInput, setFdOption, FdOption (..)) +#endif + -------------------------------------------------------------------------------- run :: Options -> IO Int @@ -44,6 +50,10 @@ run options = do -- Switchboard.destroy switchboard return 0 Nothing -> do + #if defined(wasm32_HOST_ARCH) + liftIO $ setFdOption stdInput NonBlockingRead True + `catchIO` (\ e -> hPutStrLn stderr $ "Failed to enable nonblocking on stdin: " ++ (show e) ++ "\nThe WASM module might not behave correctly.") + #endif runServer (serverDefn options) where serverDefn :: Options -> ServerDefinition Config