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

Support GHC 9.4 #71

Merged
merged 4 commits into from
Nov 21, 2023
Merged
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
12 changes: 10 additions & 2 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- See the comments for 'ppProto'.

{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -Wall #-}

import Distribution.Simple
Expand All @@ -15,6 +16,10 @@ import Distribution.Types.ComponentLocalBuildInfo (ComponentLocalBuildInfo)
import Distribution.Verbosity (Verbosity)
import System.FilePath ((</>), normalise)

#if MIN_VERSION_Cabal(3,8,0)
import Distribution.Simple.PreProcess (unsorted)
#endif

main :: IO ()
main = defaultMainWithHooks customHooks

Expand Down Expand Up @@ -47,18 +52,21 @@ ppProto ::
ppProto _buildInfo localBuildInfo _componentLocalBuildInfo = PreProcessor
{ platformIndependent = True
, runPreProcessor = genProto localBuildInfo
#if MIN_VERSION_Cabal(3,8,0)
, ppOrdering = unsorted
#endif
}

genProto ::
LocalBuildInfo ->
(FilePath, FilePath) ->
(FilePath, FilePath) ->
Verbosity ->
IO ()
IO ()
genProto localBuildInfo (inBaseDir, inRelativeFile)
(outBaseDir, outRelativeFile) verbosity = do
let inFile = normalise (inBaseDir </> inRelativeFile)
outFile = normalise (outBaseDir </> outRelativeFile)
outFile = normalise (outBaseDir </> outRelativeFile)
info verbosity $ "compiling " ++ show inFile ++ " to " ++ show outFile
(cpfProg, _) <-
requireProgram verbosity cpfProgram (withPrograms localBuildInfo)
Expand Down
8 changes: 5 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/21.05";
nixpkgs.url = "github:NixOS/nixpkgs/23.05";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
Expand All @@ -11,15 +11,17 @@
outputs = { self, nixpkgs, flake-utils, gitignore }:
flake-utils.lib.eachSystem ["x86_64-linux" "x86_64-darwin"] (system:
let
ghc = "ghc8104";
ghc = "ghc94";

grpcOverlay = import nix/overlays/grpc.nix { };

haskellOverlay = import nix/overlays/haskell.nix {
inherit gitignore ghc;
};

pkgs = import nixpkgs {
inherit system;
overlays = [ haskellOverlay ];
overlays = [ grpcOverlay haskellOverlay ];
};
in {
packages.default = pkgs.haskell.packages.${ghc}.grpc-mqtt;
Expand Down
23 changes: 11 additions & 12 deletions grpc-mqtt.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ common common
DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable
DerivingStrategies DerivingVia FlexibleContexts FlexibleInstances
FunctionalDependencies GADTs ImportQualifiedPost InstanceSigs KindSignatures
LambdaCase MultiParamTypeClasses NamedFieldPuns NoImplicitPrelude
NumericUnderscores OverloadedStrings PatternSynonyms RankNTypes
ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications
LambdaCase MultiParamTypeClasses NamedFieldPuns NoImplicitPrelude
NumericUnderscores OverloadedStrings PatternSynonyms RankNTypes
ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications
TypeFamilies TypeOperators

build-depends:
, async >= 2.2.3 && < 2.3
, base >= 4.14 && < 4.15
, base >= 4.14 && < 4.18
, bytestring >= 0.10.6.0 && < 0.12.0
, containers >= 0.5 && < 0.7
, deepseq == 1.4.*
, grpc-haskell >= 0.3.0 && < 0.4
, grpc-haskell-core >= 0.5.0 && < 0.6
, mtl >= 2.2.2 && < 2.3
, net-mqtt >= 0.8.2 && < 0.9
, proto3-suite >= 0.5.2 && < 0.7
, proto3-suite >= 0.5.2 && < 0.8
, proto3-wire >= 1.2.2 && < 1.5
, relude >= 0.7.0 && < 0.8
, relude >= 0.7.0 && < 1.3
, stm >= 2.5.0 && < 2.6
, text >= 0.2 && < 1.3
, time >= 1.9.3 && < 1.10
, text >= 0.2 && < 2.2
, time >= 1.9.3 && < 1.13
, turtle < 1.6.0 || >= 1.6.1 && < 1.7.0
, vector >= 0.11 && < 0.13

library
import: common
ghc-options:
ghc-options:
-O2
-fregs-iterative

Expand Down Expand Up @@ -127,12 +127,11 @@ library
build-depends:
, conduit-extra >= 1.3.5 && < 1.4
, connection >= 0.3.1 && < 0.4
, ghc-prim >= 0.6.1 && < 0.7
, network-conduit-tls >= 1.3.2 && < 1.4
, nonce >= 1.0.7 && < 1.1
, pqueue >= 1.4.1.3 && < 1.6
, safe-exceptions >= 0.1.7 && < 0.2
, template-haskell >= 2.16.0 && < 2.17
, template-haskell >= 2.16.0 && < 2.20
, unliftio >= 0.2.15 && < 0.3
, unliftio-core >= 0.2.0 && < 0.3
, unordered-containers >= 0.2.13 && < 0.3
Expand Down Expand Up @@ -196,7 +195,7 @@ test-suite test
, grpc-mqtt
, hedgehog
, tasty
, tasty-hedgehog < 1.1.0.0
, tasty-hedgehog < 1.5.0.0
, tasty-hunit
, tls
, uuid
Expand Down
10 changes: 10 additions & 0 deletions nix/overlays/grpc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ }:

final: prev: {
grpc = final.callPackage (import ../packages/grpc.nix) {
# grpc builds with c++14 so abseil must also be built that way
abseil-cpp = final.abseil-cpp_202111.override {
cxxStandard = "14";
};
};
}
31 changes: 22 additions & 9 deletions nix/overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ final: prev: {
packages = prev.haskell.packages // {
"${ghc}" = prev.haskell.packages."${ghc}".override (old: {
overrides = prev.lib.fold prev.lib.composeExtensions (old.overrides or (_: _: { })) [
(hfinal: _: {
large-generics = hfinal.callPackage ../packages/large-generics.nix { };
large-records = hfinal.callPackage ../packages/large-records.nix { };
(hfinal: hprev: {
# Support text v2 if using GHC 9.4+; otherwise
# use an older version that works with GHC 8.10.7.
chell =
if builtins.compareVersions hfinal.ghc.version "9.4" < 0
then hprev.chell
else final.haskell.lib.doJailbreak (hfinal.callPackage ../packages/chell.nix { });

# The tests in data-diverse do not build with GHC 9.4.
data-diverse = hfinal.callPackage ../packages/data-diverse.nix { };

# Needed by threadscope-0.2.14.1.
ghc-events = hfinal.callPackage ../packages/ghc-events.nix { };

# Support GHC 9.4.
record-dot-preprocessor = hfinal.callPackage ../packages/record-dot-preprocessor.nix { };
})
(hfinal: hprev: {
net-mqtt = final.haskell.lib.dontCheck (hfinal.callPackage ../packages/net-mqtt.nix { });
net-mqtt = final.haskell.lib.dontCheck (hfinal.callPackage ../packages/net-mqtt.nix { });
})
(hfinal: hprev: {
proto3-wire = final.haskell.lib.dontCheck (hfinal.callPackage ../packages/proto3-wire.nix { });
Expand All @@ -25,10 +37,12 @@ final: prev: {
word-compat = final.haskell.lib.dontCheck (hfinal.callPackage ../packages/word-compat.nix { });
})
(hfinal: _: {
grpc-haskell = final.haskell.lib.dontCheck (hfinal.callPackage ../packages/grpc-haskell.nix { });
grpc-haskell-core = final.haskell.lib.dontCheck (hfinal.callPackage ../packages/grpc-haskell-core.nix {
gpr = final.grpc;
});
grpc-haskell = final.haskell.lib.doJailbreak
(final.haskell.lib.dontCheck (hfinal.callPackage ../packages/grpc-haskell.nix { }));
grpc-haskell-core = final.haskell.lib.doJailbreak
(final.haskell.lib.dontCheck (hfinal.callPackage ../packages/grpc-haskell-core.nix {
gpr = final.grpc;
}));
})
(hfinal: _: {
grpc-mqtt = (hfinal.callCabal2nix "grpc-mqtt" (gitignore.lib.gitignoreSource ../..) { }).overrideAttrs (old: {
Expand Down Expand Up @@ -59,7 +73,6 @@ final: prev: {
final.mosquitto
hsPkgs.hp2pretty
hsPkgs.proto3-suite
hsPkgs.threadscope
];

packages = pkgs: [pkgs.grpc-mqtt];
Expand Down
15 changes: 15 additions & 0 deletions nix/packages/chell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ mkDerivation, ansi-terminal, base, bytestring, lib, options
, patience, random, template-haskell, text, transformers
}:
mkDerivation {
pname = "chell";
version = "0.5.0.2";
sha256 = "bbbb035b800ee924e5d14f6598fc16512b5065773b1d57a8fe08f8626fe9c1c7";
libraryHaskellDepends = [
ansi-terminal base bytestring options patience random
template-haskell text transformers
];
homepage = "https://github.com/typeclasses/chell";
description = "A simple and intuitive library for automated testing";
license = lib.licenses.mit;
}
16 changes: 16 additions & 0 deletions nix/packages/data-diverse.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ mkDerivation, base, containers, criterion, deepseq, ghc-prim
, hashable, hspec, lib, tagged
}:
mkDerivation {
pname = "data-diverse";
version = "4.7.1.0";
sha256 = "98722c2a85d8a6c2a8fec04820459f32111edb7b20058303d88af3b5ea4f4d80";
libraryHaskellDepends = [
base containers deepseq ghc-prim hashable tagged
];
testHaskellDepends = [ base hspec tagged ];
benchmarkHaskellDepends = [ base criterion ];
homepage = "https://github.com/louispan/data-diverse#readme";
description = "Extensible records and polymorphic variants";
license = lib.licenses.bsd3;
}
18 changes: 18 additions & 0 deletions nix/packages/ghc-events.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ mkDerivation, array, base, binary, bytestring, containers, lib
, text, vector
}:
mkDerivation {
pname = "ghc-events";
version = "0.17.0.3";
sha256 = "bb8cd1998227a77d8874c2982fbf8e9ef210d80f7ae9c9bf3f6d90cdbce8a054";
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [
array base binary bytestring containers text vector
];
executableHaskellDepends = [ base containers ];
testHaskellDepends = [ base ];
description = "Library and tool for parsing .eventlog files from GHC";
license = lib.licenses.bsd3;
mainProgram = "ghc-events";
}
4 changes: 2 additions & 2 deletions nix/packages/grpc-haskell-core.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mkDerivation {
version = "0.5.0";
src = fetchgit {
url = "https://github.com/awakesecurity/gRPC-haskell.git";
sha256 = "17wjm9lbyzhm98g4g36v3jlnr00s5yzilrv90p12mqgn3ffhkg28";
rev = "d20c20d63c170b5eaf5725f03f7b7060352af402";
sha256 = "0jznxcgcg31blihr81q85q3xzssdy1vkg06my97w6hmrfpvrd8gx";
rev = "2f30434fe3526b306dcdb0da78dadf84efa315fc";
fetchSubmodules = true;
};
postUnpack = "sourceRoot+=/core; echo source root reset to $sourceRoot";
Expand Down
4 changes: 2 additions & 2 deletions nix/packages/grpc-haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ mkDerivation {
version = "0.3.0";
src = fetchgit {
url = "https://github.com/awakesecurity/gRPC-haskell.git";
sha256 = "17wjm9lbyzhm98g4g36v3jlnr00s5yzilrv90p12mqgn3ffhkg28";
rev = "d20c20d63c170b5eaf5725f03f7b7060352af402";
sha256 = "0jznxcgcg31blihr81q85q3xzssdy1vkg06my97w6hmrfpvrd8gx";
rev = "2f30434fe3526b306dcdb0da78dadf84efa315fc";
fetchSubmodules = true;
};
isLibrary = true;
Expand Down
106 changes: 106 additions & 0 deletions nix/packages/grpc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, buildPackages
, cmake
, zlib
, c-ares
, pkg-config
, re2
, openssl
, protobuf
, grpc
, abseil-cpp
, libnsl

# tests
, python3
}:

stdenv.mkDerivation rec {
pname = "grpc";
version = "1.46.3"; # N.B: if you change this, please update:
# pythonPackages.grpcio-tools
# pythonPackages.grpcio-status

src = fetchFromGitHub {
owner = "grpc";
repo = "grpc";
rev = "v${version}";
sha256 = "sha256-RiXtKlRtlbqwrSxI904dgSu3da0A6Fwk+/hWHIG7A5E=";
fetchSubmodules = true;
};

patches = [
# Fix build on armv6l (https://github.com/grpc/grpc/pull/21341)
(fetchpatch {
url = "https://github.com/grpc/grpc/commit/2f4cf1d9265c8e10fb834f0794d0e4f3ec5ae10e.patch";
sha256 = "0ams3jmgh9yzwmxcg4ifb34znamr7pb4qm0609kvil9xqvkqz963";
})

# Revert gRPC C++ Mutex to be an alias of Abseil, because it breaks dependent packages
(fetchpatch {
url = "https://github.com/grpc/grpc/commit/931f91b745cd5b2864a0d1787815871d0bd844ae.patch";
sha256 = "0vc93g2i4982ys4gzyaxdv9ni25yk10sxq3n7fkz8dypy8sylck7";
revert = true;
})
];

nativeBuildInputs = [ cmake pkg-config ]
++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) grpc;
propagatedBuildInputs = [ c-ares re2 zlib abseil-cpp ];
buildInputs = [ openssl protobuf ]
++ lib.optionals stdenv.isLinux [ libnsl ];

cmakeFlags = [
"-DgRPC_ZLIB_PROVIDER=package"
"-DgRPC_CARES_PROVIDER=package"
"-DgRPC_RE2_PROVIDER=package"
"-DgRPC_SSL_PROVIDER=package"
"-DgRPC_PROTOBUF_PROVIDER=package"
"-DgRPC_ABSL_PROVIDER=package"
"-DBUILD_SHARED_LIBS=ON"
"-DCMAKE_SKIP_BUILD_RPATH=OFF"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-D_gRPC_PROTOBUF_PROTOC_EXECUTABLE=${buildPackages.protobuf}/bin/protoc"
] ++ lib.optionals ((stdenv.hostPlatform.useLLVM or false) && lib.versionOlder stdenv.cc.cc.version "11.0") [
# Needs to be compiled with -std=c++11 for clang < 11. Interestingly this is
# only an issue with the useLLVM stdenv, not the darwin stdenv…
# https://github.com/grpc/grpc/issues/26473#issuecomment-860885484
"-DCMAKE_CXX_STANDARD=11"
];

# CMake creates a build directory by default, this conflicts with the
# basel BUILD file on case-insensitive filesystems.
preConfigure = ''
rm -vf BUILD
'';

# When natively compiling, grpc_cpp_plugin is executed from the build directory,
# needing to load dynamic libraries from the build directory, so we set
# LD_LIBRARY_PATH to enable this. When cross compiling we need to avoid this,
# since it can cause the grpc_cpp_plugin executable from buildPackages to
# crash if build and host architecture are compatible (e. g. pkgsLLVM).
preBuild = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
export LD_LIBRARY_PATH=$(pwd)''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
'';

NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=unknown-warning-option"
+ lib.optionalString stdenv.isAarch64 "-Wno-error=format-security";

enableParallelBuilds = true;

passthru.tests = {
inherit (python3.pkgs) grpcio-status grpcio-tools;
};

meta = with lib; {
description = "The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)";
license = licenses.asl20;
maintainers = with maintainers; [ lnl7 marsam ];
homepage = "https://grpc.io/";
platforms = platforms.all;
changelog = "https://github.com/grpc/grpc/releases/tag/v${version}";
};
}
Loading
Loading