mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-26 21:19:43 +01:00
Add compile-proto-file
helper cli tool (#87)
* Add compile-proto-file helper cli tool (.proto -> ast -> .hs) * Update default.nix
This commit is contained in:
parent
24681a619b
commit
db3d66c4eb
3 changed files with 52 additions and 8 deletions
13
default.nix
13
default.nix
|
@ -1,7 +1,8 @@
|
||||||
{ mkDerivation, async, base, bytestring, c2hs, clock, containers
|
{ mkDerivation, async, base, bytestring, c2hs, clock, containers
|
||||||
, grpc, managed, pipes, proto3-wire, protobuf-wire, QuickCheck
|
, grpc, managed, optparse-generic, pipes, proto3-wire
|
||||||
, random, safe, sorted-list, stdenv, stm, tasty, tasty-hunit
|
, protobuf-wire, QuickCheck, random, safe, sorted-list, stdenv, stm
|
||||||
, tasty-quickcheck, text, time, transformers, turtle, unix, vector
|
, system-filepath, tasty, tasty-hunit, tasty-quickcheck, text, time
|
||||||
|
, transformers, turtle, unix, vector
|
||||||
}:
|
}:
|
||||||
mkDerivation {
|
mkDerivation {
|
||||||
pname = "grpc-haskell";
|
pname = "grpc-haskell";
|
||||||
|
@ -17,15 +18,15 @@ mkDerivation {
|
||||||
librarySystemDepends = [ grpc ];
|
librarySystemDepends = [ grpc ];
|
||||||
libraryToolDepends = [ c2hs ];
|
libraryToolDepends = [ c2hs ];
|
||||||
executableHaskellDepends = [
|
executableHaskellDepends = [
|
||||||
async base bytestring containers proto3-wire protobuf-wire random
|
async base bytestring containers optparse-generic proto3-wire
|
||||||
text transformers
|
protobuf-wire random system-filepath text transformers turtle
|
||||||
];
|
];
|
||||||
testHaskellDepends = [
|
testHaskellDepends = [
|
||||||
async base bytestring clock containers managed pipes protobuf-wire
|
async base bytestring clock containers managed pipes protobuf-wire
|
||||||
QuickCheck safe tasty tasty-hunit tasty-quickcheck text time
|
QuickCheck safe tasty tasty-hunit tasty-quickcheck text time
|
||||||
transformers turtle unix
|
transformers turtle unix
|
||||||
];
|
];
|
||||||
homepage = "http://github.com/aloiscochard/grpc-haskell";
|
homepage = "https://github.mv.awakenetworks.net/awakenetworks/gRPC-haskell";
|
||||||
description = "Haskell implementation of gRPC layered on shared C library";
|
description = "Haskell implementation of gRPC layered on shared C library";
|
||||||
license = stdenv.lib.licenses.asl20;
|
license = stdenv.lib.licenses.asl20;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,24 @@ library
|
||||||
CPP-Options: -DDEBUG
|
CPP-Options: -DDEBUG
|
||||||
CC-Options: -DGRPC_HASKELL_DEBUG -std=c99
|
CC-Options: -DGRPC_HASKELL_DEBUG -std=c99
|
||||||
|
|
||||||
|
executable compile-proto-file
|
||||||
|
build-depends: base >=4.8 && <5.0
|
||||||
|
, async
|
||||||
|
, bytestring == 0.10.*
|
||||||
|
, containers ==0.5.*
|
||||||
|
, grpc-haskell
|
||||||
|
, optparse-generic
|
||||||
|
, proto3-wire
|
||||||
|
, protobuf-wire
|
||||||
|
, system-filepath
|
||||||
|
, text
|
||||||
|
, transformers
|
||||||
|
, turtle
|
||||||
|
default-language: Haskell2010
|
||||||
|
ghc-options: -Wall -g -threaded -rtsopts -with-rtsopts=-N -O2
|
||||||
|
hs-source-dirs: tools/compile-proto-file
|
||||||
|
main-is: Main.hs
|
||||||
|
|
||||||
executable hellos-server
|
executable hellos-server
|
||||||
if flag(with-examples)
|
if flag(with-examples)
|
||||||
build-depends:
|
build-depends:
|
||||||
|
@ -221,4 +239,3 @@ benchmark bench
|
||||||
CPP-Options: -DDEBUG
|
CPP-Options: -DDEBUG
|
||||||
CC-Options: -DGRPC_HASKELL_DEBUG
|
CC-Options: -DGRPC_HASKELL_DEBUG
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
|
26
tools/compile-proto-file/Main.hs
Normal file
26
tools/compile-proto-file/Main.hs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE TypeOperators #-}
|
||||||
|
|
||||||
|
import Data.Monoid ((<>))
|
||||||
|
import Data.Protobuf.Wire.DotProto.Generate
|
||||||
|
import Filesystem.Path.CurrentOS (encodeString)
|
||||||
|
import Options.Generic
|
||||||
|
import Prelude hiding (FilePath)
|
||||||
|
import Turtle (FilePath)
|
||||||
|
|
||||||
|
data Args = Args
|
||||||
|
{ proto :: FilePath <?> "Path to input .proto file"
|
||||||
|
} deriving (Generic, Show)
|
||||||
|
instance ParseRecord Args
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
protoPath <- encodeString . unHelpful . proto <$> getRecord "Dumps a compiled .proto file to stdout"
|
||||||
|
readDotProtoWithContext protoPath >>= \case
|
||||||
|
Left err -> fail (show err)
|
||||||
|
Right (dp, ctx) -> case renderHsModuleForDotProto dp ctx of
|
||||||
|
Left err -> fail ("Error compiling " <> protoPath <> ": " <> show err)
|
||||||
|
Right src -> putStrLn src
|
Loading…
Reference in a new issue