Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WASI initialization support #73

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', '9.12']
fail-fast: false
steps:
- name: setup-ghc-wasm32-wasi
run: |
cd $(mktemp -d)
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
./setup.sh
~/.ghc-wasm/add_to_github_path.sh
env:
GHC_WASM_META_REV: f0faac335c6f5e967d1bdbfca5768232483fd2a8
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 @@ -93,7 +93,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 @@ -226,7 +230,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 !arch(wasm32)
ghc-options: -threaded
hs-source-dirs: tests
main-is: Initialization.hs
build-depends:
Expand Down