Skip to content

Commit 9ee766f

Browse files
authored
[ git ] Merge pull request #37 from agda-web/wasm-tinker
Update ALS WASM to build with Agda v2.8.0
1 parent 0e5c44b commit 9ee766f

File tree

9 files changed

+50
-90
lines changed

9 files changed

+50
-90
lines changed

.github/workflows/wasm.yaml

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,43 @@ name: Compile WASM
22

33
on:
44
push:
5-
branches: [wasm]
5+
branches: [wasm, wasm-*]
66
tags:
77
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
88
pull_request:
9-
branches: [wasm]
9+
branches: [wasm, wasm-*]
1010

1111
env:
1212
GHC_WASM_META_FLAVOUR: '9.10'
13-
GHC_WASM_META_COMMIT_HASH: '7927129e42bcd6a54b9e06e26455803fa4878261'
13+
GHC_WASM_META_COMMIT_HASH: 'c3f44696d29aaeadd755d69c51735954bfcd59db'
1414

1515
jobs:
1616
build:
1717
name: Build
1818
runs-on: ubuntu-22.04
19+
strategy:
20+
matrix:
21+
agda:
22+
# undocumented usage; see https://stackoverflow.com/q/66025220
23+
- { name: '2.8.0', flag: '2-8-0', commit: 'e2f8c69414fa115328280ecc4de1d2b7a23be7fa' }
24+
- { name: '2.7.0.1', flag: '2-7-0', commit: '702c924fdab93aa8992adca84e72a91c490f7b1b' }
25+
- { name: '2.6.4.3', flag: '2-6-4', commit: '8f35851954c39dc3849095bfd018bed9bd1b32ad' }
26+
fail-fast: false
1927

2028
steps:
21-
- uses: actions/checkout@v4
29+
- uses: actions/checkout@v5
2230
with:
2331
path: als
24-
submodules: true
32+
submodules: recursive
33+
34+
- name: Checkout Agda submodule at v${{ matrix.agda.name }}
35+
run: |
36+
cd als/wasm-submodules/agda
37+
git fetch --depth 1 origin "${{ matrix.agda.commit }}"
38+
git checkout FETCH_HEAD
2539
2640
- name: Compute cache key
27-
run: echo "CI_CACHE_KEY=${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}" >> "$GITHUB_ENV"
41+
run: echo "CI_CACHE_KEY=${{ runner.os }}-${{ runner.arch }}-${{ env.GHC_WASM_META_COMMIT_HASH }}-flavor-${{ env.GHC_WASM_META_FLAVOUR }}-${{ matrix.agda.name }}" >> "$GITHUB_ENV"
2842

2943
- name: Try to restore cached .ghc-wasm
3044
id: ghc-wasm-cache-restore
@@ -84,29 +98,21 @@ jobs:
8498
working-directory: './als'
8599
run: |
86100
mv cabal.project.wasm32 cabal.project
87-
wasm32-wasi-cabal configure --flag=Agda-2-8-0
88-
89-
- name: 'Build dep: lsp-types'
90-
uses: nick-fields/retry@v3
91-
id: build-dep-lsp-types
92-
with:
93-
timeout_minutes: 10
94-
max_attempts: 2
95-
command: cd als && wasm32-wasi-cabal build lib:lsp-types
101+
wasm32-wasi-cabal configure --flag=Agda-${{ matrix.agda.flag }}
96102
97-
- name: 'Build dep: agda'
103+
- name: Build Agda as dependency
98104
id: build-dep-agda
99105
working-directory: './als'
100106
run: wasm32-wasi-cabal build lib:agda
101107

102108
- name: Cache dist-newstyle
103109
uses: actions/cache/save@v4
104-
if: steps.build-dep-lsp-types.outcome == 'success' && steps.build-dep-agda.outcome == 'success'
110+
if: steps.build-dep-agda.outcome == 'success'
105111
with:
106112
path: als/dist-newstyle
107113
key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('als/dist-newstyle/**') }}
108114

109-
- name: Build dependencies
115+
- name: Build dependencies other than Agda
110116
working-directory: './als'
111117
run: |
112118
# Setup network submodule autotools
@@ -121,7 +127,10 @@ jobs:
121127
run: |
122128
mkdir ~/out
123129
wasm32-wasi-cabal build
124-
cp $(wasm32-wasi-cabal list-bin als) ~/out
130+
ALS_PATH=$(wasm32-wasi-cabal list-bin als)
131+
stat --format="%s" "$ALS_PATH"
132+
time wasm-opt "$ALS_PATH" -Oz -o ~/out/als.wasm
133+
stat --format="%s" ~/out/als.wasm
125134
126135
- name: Clean up native/wasm cabal logs
127136
run: rm -rf ~/.cache/cabal/logs ~/.ghc-wasm/.cabal/logs
@@ -145,6 +154,6 @@ jobs:
145154
- name: Upload artifact
146155
uses: actions/upload-artifact@v4
147156
with:
148-
name: als
157+
name: als-wasm-${{ matrix.agda.name }}
149158
path: ~/out
150159
include-hidden-files: true

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = wasm-submodules/network
33
url = https://github.com/haskell-wasm/network
44

5+
[submodule "wasm-submodules/agda"]
6+
path = wasm-submodules/agda
7+
url = [email protected]:agda-web/agda.git

BUILDING_WASM.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,3 @@
55
3. In the project root, run `cp cabal.project{.wasm32,}`, and then `wasm32-wasi-cabal build`.
66

77
Note: This project uses a hybrid approach - most dependencies use cabal's git handling, but the network package remains as a git submodule due to autotools requirements.
8-
9-
The process might output the following:
10-
11-
```
12-
[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 )
13-
14-
wasm://wasm/001e3c92:1
15-
16-
17-
RuntimeError: table index is out of bounds
18-
at wasm://wasm/001e3c92:wasm-function[586]:0x45e40
19-
at wasm://wasm/001e3c92:wasm-function[365]:0x286e1
20-
at wasm://wasm/001e3c92:wasm-function[595]:0x46135
21-
at process.processImmediate (node:internal/timers:491:21)
22-
23-
Node.js v22.14.0
24-
```
25-
26-
At this moment, you should terminate the process and run it again.
27-
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.
28-
29-
If everything works properly, it should build a binary `als.wasm`.

agda-language-server.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ executable als
160160
if arch(wasm32)
161161
build-depends:
162162
unix >=2.8.0.0 && <2.9
163-
if !arch(wasm32)
163+
ghc-options: -with-rtsopts=-V1
164+
else
164165
ghc-options: -threaded -with-rtsopts=-N
165166

166167
test-suite als-test
@@ -241,5 +242,6 @@ test-suite als-test
241242
if arch(wasm32)
242243
build-depends:
243244
unix >=2.8.0.0 && <2.9
244-
if !arch(wasm32)
245+
ghc-options: -with-rtsopts=-V1
246+
else
245247
ghc-options: -threaded -with-rtsopts=-N

cabal.project

Lines changed: 0 additions & 28 deletions
This file was deleted.

cabal.project.wasm32

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
packages:
22
.
3+
wasm-submodules/agda
34
wasm-submodules/network
45

5-
source-repository-package
6-
type: git
7-
location: https://github.com/agda-web/agda.git
8-
tag: 87cac9ce17932321dc1a0fdaed83436de22fa0aa
9-
106
source-repository-package
117
type: git
128
location: https://github.com/haskell-wasm/foundation.git
@@ -18,11 +14,5 @@ source-repository-package
1814
location: https://github.com/k0001/network-simple.git
1915
tag: 2c3ab6e7aa2a86be692c55bf6081161d83d50c34
2016

21-
source-repository-package
22-
type: git
23-
location: https://github.com/agda-web/lsp.git
24-
tag: 9baf76e6d9965a3b6e8b3ecfcdf33c62b5628fd8
25-
subdir: lsp-types
26-
2717
package Agda
2818
flags: +optimise-heavily

src/Options.hs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,21 @@ versionNumber = 6
7777

7878
versionString :: String
7979
versionString =
80-
#ifdef wasm32_HOST_ARCH
81-
"Agda v2.7.0.1 Language Server v" <> show versionNumber <> " (WebAssembly build)"
82-
#elif MIN_VERSION_Agda(2,8,0)
83-
"Agda v2.8.0 Language Server v" <> show versionNumber
80+
#if MIN_VERSION_Agda(2,8,0)
81+
"Agda v2.8.0 Language Server v" <> show versionNumber <> suffix
8482
#elif MIN_VERSION_Agda(2,7,0)
85-
"Agda v2.7.0.1 Language Server v" <> show versionNumber
83+
"Agda v2.7.0.1 Language Server v" <> show versionNumber <> suffix
8684
#elif MIN_VERSION_Agda(2,6,4)
87-
"Agda v2.6.4.3 Language Server v" <> show versionNumber
85+
"Agda v2.6.4.3 Language Server v" <> show versionNumber <> suffix
8886
#else
8987
error "Unsupported Agda version"
9088
#endif
89+
where
90+
#ifdef wasm32_HOST_ARCH
91+
suffix = " (WebAssembly build)"
92+
#else
93+
suffix = ""
94+
#endif
9195

9296
usage :: String
9397
usage = versionString <> "\nUsage: als [Options...]\n"

src/Server.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
23

34
-- entry point of the LSP server
45

@@ -52,7 +53,7 @@ run options = do
5253
Nothing -> do
5354
#if defined(wasm32_HOST_ARCH)
5455
liftIO $ setFdOption stdInput NonBlockingRead True
55-
`catchIO` (\ e -> hPutStrLn stderr $ "Failed to enable nonblocking on stdin: " ++ (show e) ++ "\nThe WASM module might not behave correctly.")
56+
`catchIO` (\ (e :: IOError) -> hPutStrLn stderr $ "Failed to enable nonblocking on stdin: " ++ (show e) ++ "\nThe WASM module might not behave correctly.")
5657
#endif
5758
runServer (serverDefn options)
5859
where

wasm-submodules/agda

Submodule agda added at e2f8c69

0 commit comments

Comments
 (0)