mu-haskell icon indicating copy to clipboard operation
mu-haskell copied to clipboard

Imports in protobuf

Open akshaymankar opened this issue 4 years ago • 7 comments

It seems they are not supported. The template haskell code just ignores them (except for google.protobuf.Empty).

akshaymankar avatar Nov 13 '20 14:11 akshaymankar

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!).

serras avatar Nov 17 '20 09:11 serras

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 😄

akshaymankar avatar Nov 17 '20 18:11 akshaymankar

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 #-}
  | ^

rossabaker avatar Apr 15 '21 12:04 rossabaker

Hey! @rossabaker seems related, we are currently discussing how to solve this and will likely come up with a fix soon, thanks!! 🙌🏻

kutyel avatar Apr 16 '21 08:04 kutyel

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.

rossabaker avatar Apr 17 '21 03:04 rossabaker

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?

ProofOfKeags avatar May 14 '21 20:05 ProofOfKeags

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.

david9991 avatar Dec 13 '22 06:12 david9991