From b9ed537f64d933faa1921ace390d1dbea36a475d Mon Sep 17 00:00:00 2001 From: intractable Date: Wed, 30 Jun 2021 12:31:45 -0500 Subject: [PATCH] Minor cleanup (#130) * Remove unnecessary self-dependency * Regenerate core/default.nix and build -core via callCabal2nix * grpc-haskell-core: -Wall -Werror and fix warnings * grpc-haskell: -Wall -Werror and fix warnings * Update documentation * Remove LD_LIBRARY_PATH sets from usesGRPC ...as they no longer seem to be needed. * Remove dead code * Remove core/default.nix ...as suggested by @evanrelf. --- README.md | 2 +- core/default.nix | 25 ------------------- core/grpc-haskell-core.cabal | 4 +-- core/src/Network/GRPC/LowLevel/Call.hs | 8 +++--- .../Network/GRPC/LowLevel/CompletionQueue.hs | 2 +- .../GRPC/LowLevel/CompletionQueue/Internal.hs | 2 +- core/src/Network/GRPC/Unsafe.chs | 1 - core/src/Network/GRPC/Unsafe/Metadata.chs | 1 - core/tests/LowLevelTests.hs | 5 ++-- core/tests/LowLevelTests/Op.hs | 2 +- core/tests/UnsafeTests.hs | 1 - examples/echo/echo-hs/EchoClient.hs | 1 - examples/echo/echo-hs/EchoServer.hs | 1 - grpc-haskell.cabal | 19 +++++++------- release.nix | 22 +++++----------- 15 files changed, 27 insertions(+), 69 deletions(-) delete mode 100644 core/default.nix diff --git a/README.md b/README.md index f2ada28..820fb8c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ have extended and released under the same [`LICENSE`](./LICENSE) Installation ------------ -**The current version of this library requires gRPC version 1.2.0. Newer versions may work but have not been tested.** +**The current version of this library requires gRPC version 1.34.1. Newer versions may work but have not been tested.** Usage ----- diff --git a/core/default.nix b/core/default.nix deleted file mode 100644 index 5bfb04b..0000000 --- a/core/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ mkDerivation, async, base, bytestring, c2hs, clock, containers -, grpc, managed, pipes, proto3-suite, proto3-wire, QuickCheck, safe -, sorted-list, stdenv, stm, tasty, tasty-hunit, tasty-quickcheck -, text, time, transformers, turtle, unix, vector -}: -mkDerivation { - pname = "grpc-haskell-core"; - version = "0.0.0.0"; - src = ./.; - libraryHaskellDepends = [ - async base bytestring clock containers managed pipes proto3-suite - proto3-wire safe sorted-list stm tasty tasty-hunit tasty-quickcheck - transformers vector - ]; - librarySystemDepends = [ grpc ]; - libraryToolDepends = [ c2hs ]; - testHaskellDepends = [ - async base bytestring clock containers managed pipes proto3-suite - QuickCheck safe tasty tasty-hunit tasty-quickcheck text time - transformers turtle unix - ]; - homepage = "https://github.com/awakenetworks/gRPC-haskell"; - description = "Haskell implementation of gRPC layered on shared C library"; - license = stdenv.lib.licenses.asl20; -} diff --git a/core/grpc-haskell-core.cabal b/core/grpc-haskell-core.cabal index d80bbb7..f88a634 100644 --- a/core/grpc-haskell-core.cabal +++ b/core/grpc-haskell-core.cabal @@ -68,7 +68,7 @@ library , grpc/slice.h build-tools: c2hs default-language: Haskell2010 - ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-unused-do-bind + ghc-options: -Wall -Werror -fwarn-incomplete-patterns -fno-warn-unused-do-bind include-dirs: include hs-source-dirs: src default-extensions: CPP @@ -103,7 +103,7 @@ test-suite tests LowLevelTests.Op, UnsafeTests default-language: Haskell2010 - ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-unused-do-bind -g -threaded -rtsopts + ghc-options: -Wall -Werror -fwarn-incomplete-patterns -fno-warn-unused-do-bind -g -threaded -rtsopts hs-source-dirs: tests main-is: Properties.hs type: exitcode-stdio-1.0 diff --git a/core/src/Network/GRPC/LowLevel/Call.hs b/core/src/Network/GRPC/LowLevel/Call.hs index 6c108d9..9962ce0 100644 --- a/core/src/Network/GRPC/LowLevel/Call.hs +++ b/core/src/Network/GRPC/LowLevel/Call.hs @@ -5,7 +5,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} @@ -212,8 +212,8 @@ destroyClientCall cc = do C.grpcCallUnref (unsafeCC cc) destroyServerCall :: ServerCall a -> IO () -destroyServerCall sc@ServerCall{ unsafeSC = c, .. } = do +destroyServerCall sc@ServerCall{ unsafeSC } = do grpcDebug "destroyServerCall(R): entered." debugServerCall sc - grpcDebug $ "Destroying server-side call object: " ++ show c - C.grpcCallUnref c + grpcDebug $ "Destroying server-side call object: " ++ show unsafeSC + C.grpcCallUnref unsafeSC diff --git a/core/src/Network/GRPC/LowLevel/CompletionQueue.hs b/core/src/Network/GRPC/LowLevel/CompletionQueue.hs index ae7a9d7..a1edbc8 100644 --- a/core/src/Network/GRPC/LowLevel/CompletionQueue.hs +++ b/core/src/Network/GRPC/LowLevel/CompletionQueue.hs @@ -71,7 +71,7 @@ createCompletionQueue _ = do -- Throws 'CallError' if 'grpcCallStartBatch' returns a non-OK code. startBatch :: CompletionQueue -> C.Call -> C.OpArray -> Int -> C.Tag -> IO (Either GRPCIOError ()) -startBatch cq@CompletionQueue{..} call opArray opArraySize tag = +startBatch cq call opArray opArraySize tag = withPermission Push cq $ fmap throwIfCallError $ do grpcDebug $ "startBatch: calling grpc_call_start_batch with pointers: " ++ show call ++ " " ++ show opArray diff --git a/core/src/Network/GRPC/LowLevel/CompletionQueue/Internal.hs b/core/src/Network/GRPC/LowLevel/CompletionQueue/Internal.hs index db63632..8fd2d54 100644 --- a/core/src/Network/GRPC/LowLevel/CompletionQueue/Internal.hs +++ b/core/src/Network/GRPC/LowLevel/CompletionQueue/Internal.hs @@ -104,7 +104,7 @@ withPermission op cq act = bracket acquire release $ \gotResource -> -- 'serverRequestCall', this will block forever unless a timeout is given. pluck :: CompletionQueue -> C.Tag -> Maybe TimeoutSeconds -> IO (Either GRPCIOError ()) -pluck cq@CompletionQueue{..} tag mwait = do +pluck cq tag mwait = do grpcDebug $ "pluck: called with tag=" ++ show tag ++ ",mwait=" ++ show mwait withPermission Pluck cq $ pluck' cq tag mwait diff --git a/core/src/Network/GRPC/Unsafe.chs b/core/src/Network/GRPC/Unsafe.chs index 6eb08b8..8967537 100644 --- a/core/src/Network/GRPC/Unsafe.chs +++ b/core/src/Network/GRPC/Unsafe.chs @@ -7,7 +7,6 @@ import Control.Exception (bracket) import Control.Monad import Data.ByteString (ByteString, useAsCString) -import Data.Semigroup (Semigroup) import Foreign.C.String (CString, peekCString) import Foreign.Marshal.Alloc (free) diff --git a/core/src/Network/GRPC/Unsafe/Metadata.chs b/core/src/Network/GRPC/Unsafe/Metadata.chs index 270ca0a..57db2ae 100644 --- a/core/src/Network/GRPC/Unsafe/Metadata.chs +++ b/core/src/Network/GRPC/Unsafe/Metadata.chs @@ -12,7 +12,6 @@ import Data.Function (on) import Data.ByteString (ByteString, useAsCString, useAsCStringLen) import Data.List (sortBy, groupBy) -import Data.Semigroup (Semigroup((<>))) import qualified Data.SortedList as SL import qualified Data.Map.Strict as M import Data.Ord (comparing) diff --git a/core/tests/LowLevelTests.hs b/core/tests/LowLevelTests.hs index 75867ab..7663cb3 100644 --- a/core/tests/LowLevelTests.hs +++ b/core/tests/LowLevelTests.hs @@ -22,7 +22,6 @@ import Data.List (find) import qualified Data.Map.Strict as M import qualified Data.Set as S import GHC.Exts (fromList, toList) -import Network.GRPC.Unsafe.ChannelArgs (Arg(..)) import Network.GRPC.LowLevel import qualified Network.GRPC.LowLevel.Call.Unregistered as U import qualified Network.GRPC.LowLevel.Client.Unregistered as U @@ -183,7 +182,7 @@ testSSL = Nothing) } server = TestServer serverConf' $ \s -> do - r <- U.serverHandleNormalCall s mempty $ \U.ServerCall{..} body -> do + r <- U.serverHandleNormalCall s mempty $ \U.ServerCall{} body -> do body @?= "hi" return ("reply test", mempty, StatusOk, "") r @?= Right () @@ -282,7 +281,7 @@ testAuthMetadataTransfer = serverProcessor) } server = TestServer serverConf' $ \s -> do - r <- U.serverHandleNormalCall s mempty $ \U.ServerCall{..} body -> do + r <- U.serverHandleNormalCall s mempty $ \U.ServerCall{} body -> do body @?= "hi" return ("reply test", mempty, StatusOk, "") r @?= Right () diff --git a/core/tests/LowLevelTests/Op.hs b/core/tests/LowLevelTests/Op.hs index dae4ba7..ade46ec 100644 --- a/core/tests/LowLevelTests/Op.hs +++ b/core/tests/LowLevelTests/Op.hs @@ -27,7 +27,7 @@ testCancelFromServer = testCase "Client/Server - client receives server cancellation" $ runSerialTest $ \grpc -> withClientServerUnaryCall grpc $ - \(Client {..}, Server {..}, ClientCall {..}, sc@ServerCall {..}) -> do + \(Client {..}, Server {}, ClientCall {..}, sc@ServerCall {}) -> do serverCallCancel sc StatusPermissionDenied "TestStatus" clientRes <- runOps unsafeCC clientCQ clientRecvOps case clientRes of diff --git a/core/tests/UnsafeTests.hs b/core/tests/UnsafeTests.hs index e335324..b009e9c 100644 --- a/core/tests/UnsafeTests.hs +++ b/core/tests/UnsafeTests.hs @@ -20,7 +20,6 @@ import Network.GRPC.Unsafe.Slice import Network.GRPC.Unsafe.Time import System.Clock import Test.QuickCheck.Gen -import qualified Test.QuickCheck.Property as QC import Test.Tasty import Test.Tasty.HUnit as HU (testCase, (@?=)) import Test.Tasty.QuickCheck as QC diff --git a/examples/echo/echo-hs/EchoClient.hs b/examples/echo/echo-hs/EchoClient.hs index 1a72fd0..a51c238 100644 --- a/examples/echo/echo-hs/EchoClient.hs +++ b/examples/echo/echo-hs/EchoClient.hs @@ -12,7 +12,6 @@ import Data.ByteString (ByteString) import Data.Maybe (fromMaybe) import qualified Data.Text.Lazy as TL import Echo -import GHC.Generics (Generic) import Network.GRPC.HighLevel.Client import Network.GRPC.LowLevel import Options.Generic diff --git a/examples/echo/echo-hs/EchoServer.hs b/examples/echo/echo-hs/EchoServer.hs index b147117..653d727 100644 --- a/examples/echo/echo-hs/EchoServer.hs +++ b/examples/echo/echo-hs/EchoServer.hs @@ -9,7 +9,6 @@ import Data.ByteString (ByteString) import Data.Maybe (fromMaybe) -import GHC.Generics (Generic) import Network.GRPC.HighLevel.Generated (GRPCMethodType (..), Host (..), Port (..), ServerRequest (..), diff --git a/grpc-haskell.cabal b/grpc-haskell.cabal index d149a41..5bdd245 100644 --- a/grpc-haskell.cabal +++ b/grpc-haskell.cabal @@ -42,7 +42,7 @@ library Network.GRPC.HighLevel.Server.Unregistered Network.GRPC.HighLevel.Client default-language: Haskell2010 - ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-unused-do-bind + ghc-options: -Wall -Werror -fwarn-incomplete-patterns -fno-warn-unused-do-bind hs-source-dirs: src default-extensions: CPP CC-Options: -std=c99 @@ -66,7 +66,7 @@ executable hellos-server else buildable: False default-language: Haskell2010 - ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 hs-source-dirs: examples/hellos/hellos-server main-is: Main.hs @@ -86,7 +86,7 @@ executable hellos-client else buildable: False default-language: Haskell2010 - ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 hs-source-dirs: examples/hellos/hellos-client main-is: Main.hs @@ -110,7 +110,7 @@ executable echo-server else buildable: False default-language: Haskell2010 - ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 hs-source-dirs: examples/echo/echo-hs main-is: EchoServer.hs @@ -135,7 +135,7 @@ executable arithmetic-server else buildable: False default-language: Haskell2010 - ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 hs-source-dirs: examples/tutorial/ main-is: ArithmeticServer.hs @@ -159,7 +159,7 @@ executable arithmetic-client else buildable: False default-language: Haskell2010 - ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 hs-source-dirs: examples/tutorial/ main-is: ArithmeticClient.hs @@ -184,14 +184,13 @@ executable echo-client else buildable: False default-language: Haskell2010 - ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2 + ghc-options: -Wall -Werror -g -threaded -rtsopts -with-rtsopts=-N -O2 hs-source-dirs: examples/echo/echo-hs main-is: EchoClient.hs test-suite tests build-depends: base >=4.8 && <5.0 - , grpc-haskell , bytestring ==0.10.* , unix , time @@ -212,7 +211,7 @@ test-suite tests other-modules: GeneratedTests default-language: Haskell2010 - ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-unused-do-bind -g -threaded -rtsopts + ghc-options: -Wall -Werror -fwarn-incomplete-patterns -fno-warn-unused-do-bind -g -threaded -rtsopts hs-source-dirs: tests main-is: Properties.hs type: exitcode-stdio-1.0 @@ -233,7 +232,7 @@ benchmark bench , random >=1.0.0 hs-source-dirs: bench main-is: Bench.hs - ghc-options: -Wall -O2 -threaded -rtsopts -with-rtsopts=-N + ghc-options: -Wall -Werror -O2 -threaded -rtsopts -with-rtsopts=-N if flag(debug) CPP-Options: -DDEBUG CC-Options: -DGRPC_HASKELL_DEBUG diff --git a/release.nix b/release.nix index 8d8542a..a5848e1 100644 --- a/release.nix +++ b/release.nix @@ -94,9 +94,11 @@ let grpc-haskell-core = pkgsNew.haskell.lib.buildFromSdist (pkgsNew.usesGRPC - (pkgsNew.haskell.lib.overrideCabal - (haskellPackagesNew.callPackage ./core { }) - (_: { buildDepends = [ haskellPackagesNew.c2hs ]; }))); + (haskellPackagesNew.callCabal2nix "grpc-haskell-core" ./core { + gpr = pkgsNew.grpc; + } + ) + ); grpc-haskell-no-tests = pkgsNew.haskell.lib.buildFromSdist (pkgsNew.usesGRPC @@ -120,7 +122,6 @@ let ]); python = pkgsNew.python.withPackages (pkgs: [ - # pkgs.protobuf3_0 pkgs.grpcio-tools ]); @@ -173,11 +174,6 @@ let }; }; - protobuf3_2NoCheck = - pkgsNew.stdenv.lib.overrideDerivation - pkgsNew.pythonPackages.protobuf - (oldAttrs : {doCheck = false; doInstallCheck = false;}); - test-grpc-haskell = pkgsNew.mkShell { nativeBuildInputs = [ @@ -190,21 +186,15 @@ let }; usesGRPC = haskellPackage: + # TODO: Try using pkgsNew.fixDarwinDylibNames (see PR#129). pkgsNew.haskell.lib.overrideCabal haskellPackage (oldAttributes: { preBuild = (oldAttributes.preBuild or "") + pkgsNew.lib.optionalString pkgsNew.stdenv.isDarwin '' export DYLD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH - '' + - pkgsNew.lib.optionalString pkgsNew.stdenv.isLinux '' - export LD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH ''; - shellHook = (oldAttributes.shellHook or "") + pkgsNew.lib.optionalString pkgsNew.stdenv.isDarwin '' export DYLD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH - '' + - pkgsNew.lib.optionalString pkgsNew.stdenv.isLinux '' - export LD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH ''; } );