Skip to content

Commit

Permalink
Support ghc v9.4 and large-records v0.4 (#243)
Browse files Browse the repository at this point in the history
* Support ghc v9.4 and large-records v0.4

...and large-generics v0.2.1.
  • Loading branch information
j6carey authored Sep 28, 2023
1 parent 6807f65 commit 88ca7ae
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 34 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- ghc8107
- ghc902
- ghc924
- ghc946
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.cabal-sandbox/
Setup.hs
cabal.sandbox.config
cabal.project.local
cabal.project.local*
dist/
dist-newstyle/
.stack-work/
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 0.7.0
* Support GHC 9.2.
* Support GHC 9.2, 9.4.
* Support proto files without a package declaration.
* Modify "Eq (Enumerated a)" to identify "Enumerated (Right e)"
with "Enumerated (Left (fromProtoEnum e))" because those two
Expand Down
10 changes: 4 additions & 6 deletions nix/nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
args:

let
# nixos-22.05 as on 2023-07-17
rev = "380be19fbd2d9079f677978361792cb25e8a3635";
sha256 = "154x9swf494mqwi4z8nbq2f0sp8pwp4fvx51lqzindjfbb9yxxv5";

nixpkgs = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256;
# release: nixpkgs-23.05pre491123.261abe8a44a7
# commit: 261abe8a44a7e8392598d038d2e01f7b33cf26d0
url = "https://hydra.nixos.org/build/236149912/download/2/nixpkgs-23.05pre491123.261abe8a44a7.tar.xz";
sha256 = "0yhf6zbnkj3a7wfas5clli5qk4xl0cw5zq5w4fzvd724za5nb04f";
};
in import nixpkgs ({ config = { }; } // args)
4 changes: 2 additions & 2 deletions nix/overlays/haskell-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ in {
source = pkgsNew.fetchFromGitHub {
owner = "awakesecurity";
repo = "proto3-wire";
rev = "ee6ca644eef86cc5f31da85fb48e10b20ab0e1a1";
sha256 = "sha256-g15oAYmhfv8DVgmQTZkcCgOYRFkxl2PQi30qXXXhBLs=";
rev = "6dcc557fc9d3ffcbfe45c6bea4969830f9e0de9c";
sha256 = "hSbnZ4vbaWdMgRuj2kbtlLu8caRzdrgEvttYTz4ywr0=";
};
in haskellPackagesNew.callCabal2nix "proto3-wire" source { };

Expand Down
12 changes: 3 additions & 9 deletions nix/packages/large-generics.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
{ mkDerivation, aeson, base, deepseq, fetchgit, generic-deriving
{ mkDerivation, aeson, base, deepseq, generic-deriving
, generics-sop, lib, microlens, mtl, primitive, QuickCheck
, sop-core, tasty, tasty-hunit, tasty-quickcheck
}:
mkDerivation {
pname = "large-generics";
version = "0.2.0.0";
src = fetchgit {
url = "https://github.com/well-typed/large-records";
sha256 = "0rzssshn6jjdp2l0gx2k60wca17ha62gxq51xyd4rl3vgh2ql7n0";
rev = "f13dd4514a247dca4a24a7668d702695748f8105";
fetchSubmodules = true;
};
postUnpack = "sourceRoot+=/large-generics; echo source root reset to $sourceRoot";
version = "0.2.1";
sha256 = "3f50991fa9504d5269a4db89548e25c5d969511951ba5adbd60e00125490632b";
libraryHaskellDepends = [
aeson base deepseq generics-sop primitive sop-core
];
Expand Down
17 changes: 6 additions & 11 deletions nix/packages/large-records.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
{ mkDerivation, base, containers, fetchgit, generic-deriving, ghc
{ mkDerivation, base, containers, generic-deriving, ghc
, large-generics, lib, mtl, newtype, primitive
, record-dot-preprocessor, record-hasfield, syb, tasty, tasty-hunit
, template-haskell, transformers
}:
mkDerivation {
pname = "large-records";
version = "0.2.2.0";
src = fetchgit {
url = "https://github.com/well-typed/large-records";
sha256 = "0rzssshn6jjdp2l0gx2k60wca17ha62gxq51xyd4rl3vgh2ql7n0";
rev = "f13dd4514a247dca4a24a7668d702695748f8105";
fetchSubmodules = true;
};
postUnpack = "sourceRoot+=/large-records; echo source root reset to $sourceRoot";
version = "0.4";
sha256 = "de51d5f473ca9e57b818221e9bf776e6f68ca90e5cbca1171dc14ce690a7093c";
libraryHaskellDepends = [
base containers ghc large-generics mtl primitive record-hasfield
syb template-haskell transformers
base containers ghc large-generics mtl primitive
record-dot-preprocessor record-hasfield syb template-haskell
transformers
];
testHaskellDepends = [
base generic-deriving large-generics mtl newtype
Expand Down
9 changes: 5 additions & 4 deletions proto3-suite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ library

other-modules: Turtle.Compat

build-depends: aeson >= 1.1.1.0 && < 2.1,
build-depends: aeson >= 1.1.1.0 && < 2.2,
aeson-pretty,
attoparsec >= 0.13.0.1,
base >=4.8 && <5.0,
Expand Down Expand Up @@ -129,7 +129,7 @@ library
split,
system-filepath,
time,
text >= 0.2 && <1.3,
text >= 0.2 && <2.1,
text-short >=0.1.3 && <0.2,
transformers >=0.4 && <0.6,
turtle < 1.6.0 || >= 1.6.1 && < 1.7.0,
Expand Down Expand Up @@ -191,7 +191,7 @@ test-suite tests
Test.Proto.Parse.Option

build-depends:
aeson >= 1.1.1.0 && < 2.1
aeson >= 1.1.1.0 && < 2.2
, attoparsec >= 0.13.0.1
, base >=4.8 && <5.0
, base64-bytestring >= 1.0.0.1 && < 1.3
Expand All @@ -209,11 +209,12 @@ test-suite tests
, proto3-suite
, proto3-wire >= 1.2 && < 1.5
, QuickCheck >=2.10 && <2.15
, record-hasfield
, tasty >= 0.11 && <1.5
, tasty-hedgehog
, tasty-hunit >= 0.9 && <0.11
, tasty-quickcheck >= 0.8.4 && <0.11
, text >= 0.2 && <1.3
, text >= 0.2 && <2.1
, text-short >=0.1.3 && <0.2
, transformers >=0.4 && <0.6
, turtle
Expand Down
36 changes: 36 additions & 0 deletions src/Proto3/Suite/DotProto/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1969,9 +1969,45 @@ defaultImports recordStyle ImportCustomisation{ icUsesGrpc, icStringType = Strin
RegularRecords -> []
LargeRecords ->
[ importDecl_ (m "Data.Record.Generic") & qualified lrNS & everything
-- "large-records" stopped exporting "grnf"; we try
-- to get it directly from "large-generics" if we can.
--
-- Ideally we would generate CPP conditionals so that
-- the version check happens when the generated code
-- is built, but as yet it is unclear how to do that.
--
-- As a result, we have to enable the version check
-- based on the package version available when building
-- compile-proto-file, and only if large record support
-- is enabled in the library code.
#ifdef LARGE_RECORDS
#if MIN_VERSION_large_generics(0,2,1)
, importDecl_ (m "Data.Record.Generic.NFData") & qualified lrNS & everything
#endif
#endif
, importDecl_ (m "Data.Record.Generic.Rep") & qualified lrNS & everything
, importDecl_ (m "Data.Record.Generic.Rep.Internal") & qualified lrNS & everything
, importDecl_ (m "Data.Record.Plugin.Runtime") & qualified lrNS & everything
-- <https://hackage.haskell.org/package/large-records-0.4/changelog>
-- says that as of large-records-0.4 the plugin does not generate
-- imports, and that "code must now import Data.Record.Plugin to
-- bring largeRecord into scope (necessary for ANN annotations)."
-- We also seem to need to import some Prelude identifiers.
--
-- Ideally we would generate CPP conditionals so that
-- the version check happens when the generated code
-- is built, but as yet it is unclear how to do that.
--
-- As a result, we have to enable the version check
-- based on the package version available when building
-- compile-proto-file, and only if large record support
-- is enabled in the library code.
#ifdef LARGE_RECORDS
#if MIN_VERSION_large_records(0,4,0)
, importDecl_ (m "Data.Record.Plugin") & unqualified & selecting [i"largeRecord"]
, importDecl_ (m "Prelude") & unqualified & selecting [i"Eq", i"Int", i"Ord", i"Show", i"error"]
#endif
#endif
]
where
m = Module
Expand Down
6 changes: 6 additions & 0 deletions src/Proto3/Suite/JSONPB/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ import qualified Data.Aeson as A (Encoding, FromJSON (..),
(.!=))
import qualified Data.Aeson.Encoding as E
import qualified Data.Aeson.Encoding.Internal as E
#if !MIN_VERSION_aeson(2,1,0)
import qualified Data.Aeson.Internal as A (formatError, iparse)
#endif
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as A
#endif
Expand All @@ -83,6 +85,10 @@ import qualified Data.Aeson.Types as A (Object, Pair, Parser,
Series,
explicitParseField,
explicitParseFieldMaybe,
#if MIN_VERSION_aeson(2,1,0)
formatError,
iparse,
#endif
object,
#if !(MIN_VERSION_aeson(2,0,2))
toJSONKeyText,
Expand Down

0 comments on commit 88ca7ae

Please sign in to comment.