Skip to content

Commit

Permalink
Merge pull request #285 from HeinrichApfelmus/HeinrichApfelmus/bump
Browse files Browse the repository at this point in the history
Bump for compatibility with GHC 9.12
  • Loading branch information
HeinrichApfelmus authored Dec 25, 2024
2 parents 3426533 + fbb8f43 commit edadda7
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 164 deletions.
100 changes: 53 additions & 47 deletions .github/workflows/build-haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,93 @@ jobs:
name: ${{ matrix.os }}-ghc-${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.allow-failure }}
env:
cabal-build-dir: b
strategy:
matrix:
allow-failure:
- false
os:
- ubuntu-latest
cabal:
- latest
# Cabal 3.12 does not work due to 'entropy' dependency.
- '3.10'
ghc:
- 8.0.2
- 8.2.2
- 8.4.4
- 8.6.5
- 8.8.4
- 8.10.7
- 9.2.8
- 9.4.7
- 9.6.5
- 9.8.2
- 9.10.1
- '8.0'
- '8.2'
- '8.4'
- '8.6'
- '8.8'
- '8.10'
- '9.2'
- '9.4'
- '9.6'
- '9.8'
- '9.10'
include:
- allow-failure: true
os: ubuntu-latest
cabal: '3.12'
ghc: '9.12'
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Environment
uses: haskell-actions/setup@v2
id: setup-haskell-cabal
id: setup
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- name: Configure
run: >
cabal configure
--builddir=${{ env.cabal-build-dir }}
--enable-tests
--enable-benchmarks
--enable-documentation
--test-show-details=direct
--write-ghc-environment-files=always
- name: Freeze
run: >
cabal freeze
--builddir=${{ env.cabal-build-dir }}
run: |
cabal configure \
--enable-tests \
--enable-benchmarks \
--enable-documentation \
--test-show-details=direct \
--write-ghc-environment-files=always
cabal build all --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Cache
uses: actions/cache@v3
# For a description of how the Caching works, see
# https://github.com/haskell-actions/setup?tab=readme-ov-file#model-cabal-workflow-with-caching
- name: Dependencies (Restore from cache)
uses: actions/cache/restore@v4
id: cache
env:
hash: ${{ hashFiles('cabal.project.freeze') }}
key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}
hash: ${{ hashFiles('**/plan.json') }}
with:
key: ${{ matrix.os }}-ghc-${{ matrix.ghc }}-${{ env.hash }}
restore-keys: |
${{ matrix.os }}-ghc-${{ matrix.ghc }}-
path: |
${{ steps.setup-haskell-cabal.outputs.cabal-store }}
${{ env.cabal-build-dir }}
key: ${{ env.key }}-${{ env.hash }}
restore-keys: ${{ env.key }}-
path: ${{ steps.setup.outputs.cabal-store }}

- name: Dependencies
run: >
cabal build all
--builddir=${{ env.cabal-build-dir }}
--only-dependencies
- name: Dependencies (Install)
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here,
# so that we do not have to rebuild them should the subsequent steps fail.
- name: Dependencies (Save cache)
uses: actions/cache/save@v4
# If we had an exact cache hit,
# trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
key: ${{ steps.cache.outputs.cache-primary-key }}
path: ${{ steps.setup.outputs.cabal-store }}

- name: Build
run: >
cabal build all
--builddir=${{ env.cabal-build-dir }}
--enable-tests
--enable-benchmarks
--ghc-options=-Wall
- name: Test
run: >
cabal test all
--builddir=${{ env.cabal-build-dir }}
- name: Benchmark
run: >
cabal bench all
--builddir=${{ env.cabal-build-dir }}
|| true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog for the `threepenny-gui` package

**0.9.4.2** – Maintenance and snapshot release

* Bump dependencies for compatibility with GHC-9.12.

**0.9.4.1** – Maintenance and snapshot release

* Bump dependencies for compatibility with GHC-9.8.
Expand Down
11 changes: 11 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ flags: +buildExamples

package snap-server
flags: +openssl

if (impl(ghc == 9.12.1))
constraints:
, hashable >= 1.5
, template-haskell >= 2.23

allow-newer:
, *:time
, *:ghc-prim
, *:template-haskell
, *:base
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# If we are building a haskell project (e.g. the current directory)
# we'd use this to get the haskell packages from the current project.
project = pkgs.haskell-nix.project' {
compiler-nix-name = "ghc964";
compiler-nix-name = "ghc966";
src = ./.;
projectFileName = "cabal.project";

Expand Down
82 changes: 59 additions & 23 deletions src/Foreign/JavaScript/Types.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}
module Foreign.JavaScript.Types where

import Control.Concurrent.STM
( STM
, TMVar
, TQueue
, TVar
)
import Control.DeepSeq
( NFData (..)
, force
)
import Data.Aeson
( toJSON
, (.=)
, (.:)
)
import Data.ByteString.Char8
( ByteString
)
import Data.Map
( Map
)
import Data.String
( fromString
)
import Data.Text
( Text
)
import Data.Typeable
( Typeable
)
import Snap.Core
( Cookie(..)
)
import System.IO
( stderr
)

import qualified Control.Concurrent.STM as STM
import qualified Control.Exception as E
import Control.Concurrent.STM as STM
import Control.Concurrent.MVar
import Control.DeepSeq
import Data.Aeson as JSON
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS (hPutStrLn)
import Data.Map as Map
import Data.String
import Data.Text
import Data.Typeable
import Snap.Core (Cookie(..))
import System.IO (stderr)
import qualified Data.Aeson as JSON
import qualified Data.ByteString.Char8 as BS (hPutStrLn)
import qualified Data.Map as Map

import Control.Concurrent.MVar
import Foreign.RemotePtr

{-----------------------------------------------------------------------------
Expand Down Expand Up @@ -196,8 +226,8 @@ data ClientMsg
| Quit
deriving (Eq, Show)

instance FromJSON ClientMsg where
parseJSON (Object msg) = do
instance JSON.FromJSON ClientMsg where
parseJSON (JSON.Object msg) = do
tag <- msg .: "tag"
case (tag :: Text) of
"Event" -> Event <$> (msg .: "name") <*> (msg .: "arguments")
Expand All @@ -209,8 +239,10 @@ readClient :: Comm -> STM ClientMsg
readClient c = do
msg <- readComm c
case JSON.fromJSON msg of
Error s -> error $ "Foreign.JavaScript: Error parsing client message " ++ show s
Success x -> return x
JSON.Error s ->
error $ "Foreign.JavaScript: Error parsing client message " ++ show s
JSON.Success x
-> pure x

-- | Messages sent by the Haskell server.
data ServerMsg
Expand All @@ -226,11 +258,15 @@ instance NFData ServerMsg where
rnf (Debug x) = rnf x
rnf (Timestamp ) = ()

instance ToJSON ServerMsg where
toJSON (Debug x) = object [ "tag" .= t "Debug" , "contents" .= toJSON x]
toJSON (Timestamp ) = object [ "tag" .= t "Timestamp" ]
toJSON (RunEval x) = object [ "tag" .= t "RunEval" , "contents" .= toJSON x]
toJSON (CallEval x) = object [ "tag" .= t "CallEval", "contents" .= toJSON x]
instance JSON.ToJSON ServerMsg where
toJSON (Debug x) =
JSON.object [ "tag" .= t "Debug", "contents" .= toJSON x]
toJSON Timestamp =
JSON.object [ "tag" .= t "Timestamp" ]
toJSON (RunEval x) =
JSON.object [ "tag" .= t "RunEval", "contents" .= toJSON x]
toJSON (CallEval x) =
JSON.object [ "tag" .= t "CallEval", "contents" .= toJSON x]

t :: String -> Text
t s = fromString s
Expand Down Expand Up @@ -335,8 +371,8 @@ data Window = Window
newPartialWindow :: IO Window
newPartialWindow = do
ptr <- newRemotePtr "" () =<< newVendor
b1 <- newTMVarIO id
b2 <- newTVarIO NoBuffering
b1 <- STM.newTMVarIO id
b2 <- STM.newTVarIO NoBuffering
let nop = const $ return ()
Window undefined [] nop undefined b1 b2 (return ()) nop nop ptr <$> newVendor <*> newVendor

Expand Down
Loading

0 comments on commit edadda7

Please sign in to comment.