mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-23 03:29:42 +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
|
||||
, grpc, managed, pipes, proto3-wire, protobuf-wire, QuickCheck
|
||||
, random, safe, sorted-list, stdenv, stm, tasty, tasty-hunit
|
||||
, tasty-quickcheck, text, time, transformers, turtle, unix, vector
|
||||
, grpc, managed, optparse-generic, pipes, proto3-wire
|
||||
, protobuf-wire, QuickCheck, random, safe, sorted-list, stdenv, stm
|
||||
, system-filepath, tasty, tasty-hunit, tasty-quickcheck, text, time
|
||||
, transformers, turtle, unix, vector
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "grpc-haskell";
|
||||
|
@ -17,15 +18,15 @@ mkDerivation {
|
|||
librarySystemDepends = [ grpc ];
|
||||
libraryToolDepends = [ c2hs ];
|
||||
executableHaskellDepends = [
|
||||
async base bytestring containers proto3-wire protobuf-wire random
|
||||
text transformers
|
||||
async base bytestring containers optparse-generic proto3-wire
|
||||
protobuf-wire random system-filepath text transformers turtle
|
||||
];
|
||||
testHaskellDepends = [
|
||||
async base bytestring clock containers managed pipes protobuf-wire
|
||||
QuickCheck safe tasty tasty-hunit tasty-quickcheck text time
|
||||
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";
|
||||
license = stdenv.lib.licenses.asl20;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ synopsis: Haskell implementation of gRPC layered on shared C library.
|
|||
homepage: https://github.mv.awakenetworks.net/awakenetworks/gRPC-haskell
|
||||
license: Apache-2.0
|
||||
license-file: LICENSE
|
||||
author: Connor Clark
|
||||
author: Connor Clark
|
||||
maintainer: connor@awakenetworks.com
|
||||
copyright: Copyright 2016 Awake Networks
|
||||
category: Network
|
||||
|
@ -93,6 +93,24 @@ library
|
|||
CPP-Options: -DDEBUG
|
||||
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
|
||||
if flag(with-examples)
|
||||
build-depends:
|
||||
|
@ -221,4 +239,3 @@ benchmark bench
|
|||
CPP-Options: -DDEBUG
|
||||
CC-Options: -DGRPC_HASKELL_DEBUG
|
||||
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