mu-haskell
mu-haskell copied to clipboard
Imports in protobuf
It seems they are not supported. The template haskell code just ignores them (except for google.protobuf.Empty).
You are right, our first iteration just ignored them. The reason is that it's not easy to track where in the filesystem or in the web you can find each import. If you have references, I am happy to give it a go in the next weeks (we also accept PRs, of course!).
I think it is sufficient to only look for the files in filesystem. There is no standard place to look, the protoc binary accepts a --proto-path argument which specifies where the imports will be looked for.
For reference, the language guide does a decent job of explaining this.
I don't know if I will get any time to make a PR for this, I am just hacking around on the weekends for now, so I wouldn't make any promises 😄
I am getting this error on a gRPC definition with imports. Calls without imports work. Is it correct to think this error is a manifestation of the import limitation?
src/Schema.hs:1:1: error:
Exception when trying to run compile-time code:
this should never happen
CallStack (from HasCallStack):
error, called at src/Mu/Quasi/ProtoBuf.hs:72:27 in mu-protobuf-0.4.2.0-JgUiVj2yesRLbegUU1AGsL:Mu.Quasi.ProtoBuf
Code: grpc
"PubSubSchema" id "googleapis/google/pubsub/v1/pubsub.proto"
|
1 | {-# LANGUAGE DataKinds #-}
| ^
Hey! @rossabaker seems related, we are currently discussing how to solve this and will likely come up with a fix soon, thanks!! 🙌🏻
Thanks, @kutyel! I ran into this on the googleapis, if you're looking for a good real-world example. We're enjoying the library very much, and I'll be more than happy to test.
Just ran into something like this as well. One of the methods by which this is handled in the proto-lens library is through using extra-src-files in the package.yaml/cabal file. Perhaps the TH could get at that info and just iterate through the .proto files?
Does this error related to this issue?
/usr/src/app/src/Ladder.hs:30:46: error:
• Expected kind ‘Mu.Rpc.Package
ghc-prim-0.6.1:GHC.Types.Symbol
ghc-prim-0.6.1:GHC.Types.Symbol
ghc-prim-0.6.1:GHC.Types.Symbol
(Mu.Rpc.TypeRef ghc-prim-0.6.1:GHC.Types.Symbol)’,
but ‘Service’ has kind ‘Mu.Rpc.Package
ghc-prim-0.6.1:GHC.Types.Symbol
ghc-prim-0.6.1:GHC.Types.Symbol
ghc-prim-0.6.1:GHC.Types.Symbol
(Mu.Rpc.TypeRef *)’
• In the second argument of ‘SingleServerT’, namely ‘Service’
In the type ‘SingleServerT i Service m _’
In the type signature:
server :: (MonadServer m) => SingleServerT i Service m _
|
30 | server :: (MonadServer m) => SingleServerT i Service m _
I have to work around this by expending TemplateHaskell splice to:
type MySchema =
'[ 'DRecord "HelloRequest" '[ 'FieldDef "name" ('TPrimitive Text)],
'DRecord "HelloReply" '[ 'FieldDef "message" ('TPrimitive Text)]
]
type instance
AnnotatedSchema ProtoBufAnnotation MySchema =
'[ 'AnnField "HelloRequest" "name" ('ProtoBufId 1 '[]),
'AnnField "HelloReply" "message" ('ProtoBufId 1 '[])
]
type Service =
'Package ('Just "myservice") '[ 'Service "Service" '[ 'Method "SayHello" '[ 'ArgSingle ('Nothing :: Maybe Symbol) ('SchemaRef MySchema "HelloRequest")] ('RetSingle ('SchemaRef MySchema "HelloReply"))]]
And then add a :: Package' at the end of the type definition of the Service.