Skip to content
/ bond Public
forked from microsoft/bond

Commit

Permalink
[c++ grpc] Fix includes when bond::Void is used
Browse files Browse the repository at this point in the history
When a service contains events or parameterless methods, the generated
code uses bond::Void as the request/result type. To serialize
bond::Void, bond_reflection.h needs to be included.

The generated service code now includes bond_reflection.h if any service
contains an event or a parameterless method.

Fixes microsoft#735
  • Loading branch information
chwarr committed Nov 29, 2017
1 parent 46527ce commit 2b73e2c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ different versioning scheme, following the Haskell community's
has required Boost 1.58 or later since version 5.2.0, but this was not
enforced.
* gRPC v1.7.1 is now required to use Bond-over-gRPC.
* Fixed includes for gRPC services with events or parameterless methods.
[Issue #735](https://github.com/Microsoft/bond/issues/735)

## 7.0.2: 2017-10-30 ##
* `gbc` & compiler library: 0.10.1.0
Expand Down
10 changes: 10 additions & 0 deletions compiler/src/Language/Bond/Codegen/Cpp/Grpc_h.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module Language.Bond.Codegen.Cpp.Grpc_h (grpc_h) where

import System.FilePath
import Data.Maybe(isNothing)
import Data.Monoid
import Prelude
import qualified Data.Text.Lazy as L
Expand All @@ -27,6 +28,7 @@ grpc_h export_attribute cpp file imports declarations = ("_grpc.h", [lt|
#include "#{file}_reflection.h"
#include "#{file}_types.h"
#{newlineSep 0 includeImport imports}
#{includeBondReflection}
#include <bond/core/bonded.h>
#include <bond/ext/grpc/bond_utils.h>
#include <bond/ext/grpc/client_callback.h>
Expand Down Expand Up @@ -79,6 +81,14 @@ grpc_h export_attribute cpp file imports declarations = ("_grpc.h", [lt|
paramsText = toLazyText params
padLeft = if L.head paramsText == ':' then [lt| |] else mempty

includeBondReflection =
if usesBondVoid then [lt|#include <bond/core/bond_reflection.h>|] else mempty
where usesBondVoid = any declUses declarations
declUses Service {serviceMethods = methods } = any methodUses methods
declUses _ = False
methodUses Function {methodInput = input } = isNothing input
methodUses Event {} = True

grpc s@Service{..} = [lt|
#{template}class #{declName} final
{
Expand Down
1 change: 1 addition & 0 deletions compiler/tests/generated/generic_service_grpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "generic_service_reflection.h"
#include "generic_service_types.h"

#include <bond/core/bond_reflection.h>
#include <bond/core/bonded.h>
#include <bond/ext/grpc/bond_utils.h>
#include <bond/ext/grpc/client_callback.h>
Expand Down
1 change: 1 addition & 0 deletions compiler/tests/generated/service_attributes_grpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "service_attributes_reflection.h"
#include "service_attributes_types.h"


#include <bond/core/bonded.h>
#include <bond/ext/grpc/bond_utils.h>
#include <bond/ext/grpc/client_callback.h>
Expand Down
1 change: 1 addition & 0 deletions compiler/tests/generated/service_grpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "service_types.h"
#include "basic_types_grpc.h"
#include "namespace_basic_types_grpc.h"
#include <bond/core/bond_reflection.h>
#include <bond/core/bonded.h>
#include <bond/ext/grpc/bond_utils.h>
#include <bond/ext/grpc/client_callback.h>
Expand Down

0 comments on commit 2b73e2c

Please sign in to comment.