From 3f9773d03979379a64a392cae3f98f2d0718ca78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CB=8Cbod=CA=B2=C9=AA=CB=88=C9=A1r=CA=B2im?= Date: Thu, 19 Sep 2024 20:32:09 +0200 Subject: [PATCH] CI: add WASM job (#656) * Don't build tests with threaded runtime on WASM * Skip lifting tests on WASM * Tests: improve reporting of mismatches for IO tests * Add WASM CI job * CI: upgrade incantations for emualted tests --- .github/workflows/ci.yml | 42 ++++++++++++++++++++++++++++++++++++---- bytestring.cabal | 4 +++- cabal.project.wasi | 5 +++++ tests/Lift.hs | 4 ++++ tests/Properties.hs | 16 +++++++-------- 5 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 cabal.project.wasi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15985bfda..1a195b532 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,7 +127,7 @@ jobs: arch: ['s390x', 'ppc64le'] steps: - uses: actions/checkout@v4 - - uses: uraimo/run-on-arch-action@v2.5.0 + - uses: uraimo/run-on-arch-action@v2.7.2 timeout-minutes: 60 with: arch: ${{ matrix.arch }} @@ -135,11 +135,10 @@ jobs: githubToken: ${{ github.token }} install: | apt-get update -y - apt-get install -y curl ghc libghc-tasty-quickcheck-dev libghc-syb-dev + apt-get install -y ghc libghc-tasty-quickcheck-dev libghc-syb-dev run: | - curl -s https://hackage.haskell.org/package/data-array-byte-0.1/data-array-byte-0.1.tar.gz | tar xz ghc --version - ghc --make -XHaskell2010 -XBangPatterns -XDeriveDataTypeable -XDeriveGeneric -XDeriveLift -XFlexibleContexts -XFlexibleInstances -XLambdaCase -XMagicHash -XMultiWayIf -XNamedFieldPuns -XPatternSynonyms -XRankNTypes -XScopedTypeVariables -XStandaloneDeriving -XTupleSections -XTypeApplications -XTypeOperators -XUnboxedTuples -optP-Wall -optP-Werror=undef -DPURE_HASKELL=0 -Iinclude -itests:tests/builder:data-array-byte-0.1 -o Main cbits/*.c tests/Main.hs +RTS -s + ghc --make -XHaskell2010 -XBangPatterns -XDeriveDataTypeable -XDeriveGeneric -XDeriveLift -XFlexibleContexts -XFlexibleInstances -XLambdaCase -XMagicHash -XMultiWayIf -XNamedFieldPuns -XPatternSynonyms -XRankNTypes -XScopedTypeVariables -XStandaloneDeriving -XTupleSections -XTypeApplications -XTypeOperators -XUnboxedTuples -optP-Wall -optP-Werror=undef -DPURE_HASKELL=0 -Iinclude -itests:tests/builder -o Main cbits/*.c tests/Main.hs +RTS -s ./Main +RTS -s bounds-checking: @@ -232,3 +231,38 @@ jobs: name: Run build (arm64v8 linux) with: args: sh -c "cabal update && cabal test" + + wasi: + runs-on: ubuntu-latest + needs: build + env: + GHC_WASM_META_REV: a04cc1a2206d2030326e1d49be9c6a94ee4283a3 + strategy: + matrix: + ghc: ['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: + FLAVOUR: ${{ matrix.ghc }} + - uses: actions/checkout@v4 + - uses: actions/cache@v3 + with: + path: | + ~/.ghc-wasm/.cabal/store + key: wasi-${{ runner.os }}-${{ env.GHC_WASM_META_REV }}-flavour-${{ matrix.ghc }}-${{ github.sha }} + restore-keys: | + wasi-${{ runner.os }}-${{ env.GHC_WASM_META_REV }}-flavour-${{ matrix.ghc }}- + - name: Build + run: | + mv cabal.project.wasi cabal.project.local + wasm32-wasi-cabal build --enable-tests + wasm32-wasi-cabal list-bin test:bytestring-tests + - name: Test + run: | + wasmtime.sh $(wasm32-wasi-cabal list-bin test:bytestring-tests) diff --git a/bytestring.cabal b/bytestring.cabal index 03f09c085..20cc13eaf 100644 --- a/bytestring.cabal +++ b/bytestring.cabal @@ -220,7 +220,9 @@ test-suite bytestring-tests syb ghc-options: -fwarn-unused-binds - -threaded -rtsopts + -rtsopts + if !arch(wasm32) + ghc-options: -threaded benchmark bytestring-bench import: language diff --git a/cabal.project.wasi b/cabal.project.wasi new file mode 100644 index 000000000..1ce82edb0 --- /dev/null +++ b/cabal.project.wasi @@ -0,0 +1,5 @@ +-- https://github.com/haskellari/splitmix/pull/73 +source-repository-package + type: git + location: https://github.com/amesgen/splitmix + tag: 5f5b766d97dc735ac228215d240a3bb90bc2ff75 diff --git a/tests/Lift.hs b/tests/Lift.hs index b65130b4c..31d5a7868 100644 --- a/tests/Lift.hs +++ b/tests/Lift.hs @@ -13,6 +13,9 @@ import qualified Data.ByteString.Short as SBS import qualified Language.Haskell.TH.Syntax as TH testSuite :: TestTree +#ifdef wasm32_HOST_ARCH +testSuite = testGroup "Skipped, requires -fexternal-interpreter" [] +#else testSuite = testGroup "Lift" [ testGroup "strict" [ testProperty "normal" $ @@ -62,3 +65,4 @@ testSuite = testGroup "Lift" #endif ] ] +#endif diff --git a/tests/Properties.hs b/tests/Properties.hs index d04ea5209..a1d9528d8 100644 --- a/tests/Properties.hs +++ b/tests/Properties.hs @@ -450,7 +450,7 @@ prop_read_write_file_P x = ioProperty $ do P.writeFile fn x y <- P.readFile fn removeFile fn - return (x == y) + return (x === y) prop_read_write_file_C x = ioProperty $ do (fn, h) <- openTempFile "." "prop-compiled.tmp" @@ -458,7 +458,7 @@ prop_read_write_file_C x = ioProperty $ do C.writeFile fn x y <- C.readFile fn removeFile fn - return (x == y) + return (x === y) prop_read_write_file_L x = ioProperty $ do (fn, h) <- openTempFile "." "prop-compiled.tmp" @@ -466,7 +466,7 @@ prop_read_write_file_L x = ioProperty $ do L.writeFile fn x y <- L.readFile fn L.length y `seq` removeFile fn - return (x == y) + return (x === y) prop_read_write_file_D x = ioProperty $ do (fn, h) <- openTempFile "." "prop-compiled.tmp" @@ -474,7 +474,7 @@ prop_read_write_file_D x = ioProperty $ do D.writeFile fn x y <- D.readFile fn D.length y `seq` removeFile fn - return (x == y) + return (x === y) ------------------------------------------------------------------------ @@ -485,7 +485,7 @@ prop_append_file_P x y = ioProperty $ do P.appendFile fn y z <- P.readFile fn removeFile fn - return (z == x `P.append` y) + return (z === x `P.append` y) prop_append_file_C x y = ioProperty $ do (fn, h) <- openTempFile "." "prop-compiled.tmp" @@ -494,7 +494,7 @@ prop_append_file_C x y = ioProperty $ do C.appendFile fn y z <- C.readFile fn removeFile fn - return (z == x `C.append` y) + return (z === x `C.append` y) prop_append_file_L x y = ioProperty $ do (fn, h) <- openTempFile "." "prop-compiled.tmp" @@ -503,7 +503,7 @@ prop_append_file_L x y = ioProperty $ do L.appendFile fn y z <- L.readFile fn L.length y `seq` removeFile fn - return (z == x `L.append` y) + return (z === x `L.append` y) prop_append_file_D x y = ioProperty $ do (fn, h) <- openTempFile "." "prop-compiled.tmp" @@ -512,7 +512,7 @@ prop_append_file_D x y = ioProperty $ do D.appendFile fn y z <- D.readFile fn D.length y `seq` removeFile fn - return (z == x `D.append` y) + return (z === x `D.append` y) prop_packAddress = C.pack "this is a test" ==