Skip to content

Commit

Permalink
Add WASI initialization support
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen committed May 14, 2024
1 parent 33872e2 commit 5f5b766
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,29 @@ jobs:

- name: Test
run: cabal test all --enable-tests --test-show-details=direct
wasi:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: ['9.6', '9.8', '9.10']
fail-fast: false
steps:
- name: setup-ghc-wasm32-wasi
run: |
cd $(mktemp -d)
curl -L https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/$GHC_WASM_META_REV/ghc-wasm-meta.tar.gz | tar xz --strip-components=1
./setup.sh
~/.ghc-wasm/add_to_github_path.sh
env:
GHC_WASM_META_REV: 00304b294d10eacedbb7c4a9a034ff89fc198a5a
FLAVOUR: ${{ matrix.ghc }}
- uses: actions/checkout@v4
- name: Build
run: |
wasm32-wasi-cabal build splitmix splitmix:test:examples splitmix:test:initialization
- name: Test
run: |
for test in examples initialization; do
echo --- Running test $test ---
wasmtime $(wasm32-wasi-cabal list-bin splitmix:test:$test)
done
8 changes: 8 additions & 0 deletions cbits-wasi/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdint.h>
#include <sys/random.h>

uint64_t splitmix_init() {
uint64_t result;
int r = getentropy(&result, sizeof(uint64_t));
return r == 0 ? result : 0xfeed1000;
}
10 changes: 8 additions & 2 deletions splitmix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ library
c-sources: cbits-win/init.c

else
c-sources: cbits-unix/init.c
if arch(wasm32)
c-sources: cbits-wasi/init.c

else
c-sources: cbits-unix/init.c

else
cpp-options: -DSPLITMIX_INIT_COMPAT=1
Expand Down Expand Up @@ -225,7 +229,9 @@ test-suite splitmix-testu01
test-suite initialization
default-language: Haskell2010
type: exitcode-stdio-1.0
ghc-options: -Wall -threaded -rtsopts
ghc-options: -Wall -rtsopts
if !os(wasi)
ghc-options: -threaded
hs-source-dirs: tests
main-is: Initialization.hs
build-depends:
Expand Down

0 comments on commit 5f5b766

Please sign in to comment.