diff --git a/bazel/objc_grpc_library.bzl b/bazel/objc_grpc_library.bzl index 48f7576e2e8..bfc04d11c8e 100644 --- a/bazel/objc_grpc_library.bzl +++ b/bazel/objc_grpc_library.bzl @@ -67,6 +67,7 @@ def objc_grpc_library(name, deps, srcs = [], use_well_known_protos = False, **kw srcs = arc_srcs, defines = [ "GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0", + "GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0", ], includes = [ "_generated_protos", diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index d7a67c093f9..8cc3fdfe172 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -132,6 +132,8 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { static const ::std::string kNonNullBegin = "NS_ASSUME_NONNULL_BEGIN\n"; static const ::std::string kNonNullEnd = "NS_ASSUME_NONNULL_END\n"; static const ::std::string kProtocolOnly = "GPB_GRPC_PROTOCOL_ONLY"; + static const ::std::string kForwardDeclare = + "GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO"; ::std::string file_name = google::protobuf::compiler::objectivec::FilePath(file); @@ -161,6 +163,13 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { { // Generate .pbrpc.h + ::std::string imports; + if (framework.empty()) { + imports = LocalImport(file_name + ".pbobjc.h"); + } else { + imports = FrameworkImport(file_name + ".pbobjc.h", framework); + } + ::std::string system_imports; if (grpc_local_import) { system_imports = @@ -200,6 +209,12 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::std::string class_declarations = grpc_objective_c_generator::GetAllMessageClasses(file); + ::std::string class_imports; + for (int i = 0; i < file->dependency_count(); i++) { + class_imports += ImportProtoHeaders( + file->dependency(i), " ", framework, pb_runtime_import_prefix); + } + ::std::string ng_protocols; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); @@ -222,9 +237,12 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { Write(context, file_name + ".pbrpc.h", file_header + SystemImport("Foundation/Foundation.h") + "\n" + + PreprocIfNot(kForwardDeclare, imports) + "\n" + PreprocIfNot(kProtocolOnly, system_imports) + "\n" + - class_declarations + "\n" + forward_declarations + "\n" + - kNonNullBegin + "\n" + ng_protocols + protocols + "\n" + + class_declarations + "\n" + + PreprocIfNot(kForwardDeclare, class_imports) + "\n" + + forward_declarations + "\n" + kNonNullBegin + "\n" + + ng_protocols + protocols + "\n" + PreprocIfNot(kProtocolOnly, interfaces) + "\n" + kNonNullEnd + "\n"); } diff --git a/src/objective-c/grpc_objc_internal_library.bzl b/src/objective-c/grpc_objc_internal_library.bzl index cb39ab071be..ad212d13715 100644 --- a/src/objective-c/grpc_objc_internal_library.bzl +++ b/src/objective-c/grpc_objc_internal_library.bzl @@ -166,6 +166,7 @@ def local_objc_grpc_library(name, deps, testing = True, srcs = [], use_well_know srcs = arc_srcs, defines = [ "GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0", + "GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=0", ], includes = ["_generated_protos"], deps = library_deps, diff --git a/src/objective-c/tests/RemoteTestClient/RemoteTest.podspec b/src/objective-c/tests/RemoteTestClient/RemoteTest.podspec index b74352cf747..be0ed3e2673 100644 --- a/src/objective-c/tests/RemoteTestClient/RemoteTest.podspec +++ b/src/objective-c/tests/RemoteTestClient/RemoteTest.podspec @@ -49,7 +49,7 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { # This is needed by all pods that depend on Protobuf: - 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1', + 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1 GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=1', # This is needed by all pods that depend on gRPC-RxLibrary: 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', } diff --git a/test/cpp/ios/RemoteTestClientCpp/RemoteTestCpp.podspec b/test/cpp/ios/RemoteTestClientCpp/RemoteTestCpp.podspec index c328f930b1a..e113703bcc9 100644 --- a/test/cpp/ios/RemoteTestClientCpp/RemoteTestCpp.podspec +++ b/test/cpp/ios/RemoteTestClientCpp/RemoteTestCpp.podspec @@ -38,7 +38,7 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { # This is needed by all pods that depend on Protobuf: - 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1', + 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1 GPB_GRPC_FORWARD_DECLARE_MESSAGE_PROTO=1', # This is needed by all pods that depend on gRPC-RxLibrary: 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', }