Skip to content

Commit cea9e31

Browse files
committed
Add WASI initialization support
1 parent adc777f commit cea9e31

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.github/workflows/simple.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,29 @@ jobs:
4444

4545
- name: Test
4646
run: cabal test all --enable-tests --test-show-details=direct
47+
wasi:
48+
runs-on: ubuntu-latest
49+
strategy:
50+
matrix:
51+
ghc: ['9.6', '9.8', '9.10', '9.12']
52+
fail-fast: false
53+
steps:
54+
- name: setup-ghc-wasm32-wasi
55+
run: |
56+
cd $(mktemp -d)
57+
curl -L https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta/-/archive/$GHC_WASM_META_REV/ghc-wasm-meta.tar.gz | tar xz --strip-components=1
58+
./setup.sh
59+
~/.ghc-wasm/add_to_github_path.sh
60+
env:
61+
GHC_WASM_META_REV: f0faac335c6f5e967d1bdbfca5768232483fd2a8
62+
FLAVOUR: ${{ matrix.ghc }}
63+
- uses: actions/checkout@v4
64+
- name: Build
65+
run: |
66+
wasm32-wasi-cabal build splitmix splitmix:test:examples splitmix:test:initialization
67+
- name: Test
68+
run: |
69+
for test in examples initialization; do
70+
echo --- Running test $test ---
71+
wasmtime $(wasm32-wasi-cabal list-bin splitmix:test:$test)
72+
done

cbits-wasi/init.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdint.h>
2+
#include <sys/random.h>
3+
4+
uint64_t splitmix_init() {
5+
uint64_t result;
6+
int r = getentropy(&result, sizeof(uint64_t));
7+
return r == 0 ? result : 0xfeed1000;
8+
}

splitmix.cabal

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ library
9393
c-sources: cbits-win/init.c
9494

9595
else
96-
c-sources: cbits-unix/init.c
96+
if arch(wasm32)
97+
c-sources: cbits-wasi/init.c
98+
99+
else
100+
c-sources: cbits-unix/init.c
97101

98102
else
99103
cpp-options: -DSPLITMIX_INIT_COMPAT=1
@@ -226,7 +230,9 @@ test-suite splitmix-testu01
226230
test-suite initialization
227231
default-language: Haskell2010
228232
type: exitcode-stdio-1.0
229-
ghc-options: -Wall -threaded -rtsopts
233+
ghc-options: -Wall -rtsopts
234+
if !arch(wasm32)
235+
ghc-options: -threaded
230236
hs-source-dirs: tests
231237
main-is: Initialization.hs
232238
build-depends:

0 commit comments

Comments
 (0)