diff --git a/third_party/grpc/BUILD b/third_party/grpc/BUILD index 1ff6b622b9c0c9..4e2afcb5dca533 100644 --- a/third_party/grpc/BUILD +++ b/third_party/grpc/BUILD @@ -18,7 +18,7 @@ load("//tools/distributions:distribution_rules.bzl", "distrib_java_import", "dis licenses(["notice"]) # Apache v2 -exports_files(["grpc_1.31.1.patch"]) +exports_files(["grpc_1.31.1.patch", "grpc_1.32.0.patch"]) package(default_visibility = ["//visibility:public"]) @@ -32,14 +32,14 @@ filegroup( distrib_jar_filegroup( name = "bootstrap-grpc-jars", srcs = [ - "grpc-api-1.31.1.jar", - "grpc-auth-1.31.1.jar", - "grpc-context-1.31.1.jar", - "grpc-core-1.31.1.jar", - "grpc-netty-1.31.1.jar", - "grpc-protobuf-1.31.1.jar", - "grpc-protobuf-lite-1.31.1.jar", - "grpc-stub-1.31.1.jar", + "grpc-api-1.32.2.jar", + "grpc-auth-1.32.2.jar", + "grpc-context-1.32.2.jar", + "grpc-core-1.32.2.jar", + "grpc-netty-1.32.2.jar", + "grpc-protobuf-1.32.2.jar", + "grpc-protobuf-lite-1.32.2.jar", + "grpc-stub-1.32.2.jar", ], enable_distributions = ["debian"], ) diff --git a/third_party/grpc/README.bazel.md b/third_party/grpc/README.bazel.md index faff9352ea28d8..c7a3ac2f8cb50f 100644 --- a/third_party/grpc/README.bazel.md +++ b/third_party/grpc/README.bazel.md @@ -1,24 +1,30 @@ # How to update the C++ sources of gRPC: 1. Update the gRPC definitions in WORKSPACE file, currently we use - https://github.com/grpc/grpc/archive/v1.31.1.tar.gz + https://github.com/grpc/grpc/archive/v1.32.2.tar.gz 2. Update the gRPC patch file if necessary, it mostly helps avoid unnecessary dependencies. 3. Update third_party/grpc/BUILD to redirect targets to @com_github_grpc_grpc if necessary. # How to update the BUILD/bzl sources of gRPC: 1. `git clone http://github.com/grpc/grpc.git` in a convenient directory -2. `git checkout ` (current is `v1.31.1`, commithash `7d7e456762`) +2. `git checkout ` (current is `v1.32.0`, commithash `414bb8322d`) 3. `mkdir -p third_party/grpc/bazel` 4. `cp /bazel/{BUILD,cc_grpc_library.bzl,generate_cc.bzl,protobuf.bzl} third_party/grpc/bazel` 5. In the `third_party/grpc` directory, apply local patches: - `patch -p3 < bazel_1.31.1.patch` + `patch -p3 < bazel_1.32.0.patch` # How to update the Java plugin: -1. Checkout tag `v1.31.1` from https://github.com/grpc/grpc-java +1. Checkout tag `v1.32.2` from https://github.com/grpc/grpc-java 2. `cp -R /compiler/src/java_plugin third_party/grpc/compiler/src` # How to update the Java code: -Download the necessary jars at version `1.31.1` from maven central. +Download the necessary jars at version `1.32.2` from maven central. + +# Submitting the change needs 3 pull requests + +1. Update third_party/grpc to include files from new version +2. Switch WORKSPACE, scripts/bootstrap/compile.sh and any other references to new version +3. Remove older version from third_party/grpc diff --git a/third_party/grpc/bazel/protobuf.bzl b/third_party/grpc/bazel/protobuf.bzl index dd2b5d30923a7c..c0abfb3ee44353 100644 --- a/third_party/grpc/bazel/protobuf.bzl +++ b/third_party/grpc/bazel/protobuf.bzl @@ -214,7 +214,12 @@ def get_out_dir(protos, context): path = out_dir, import_path = out_dir[out_dir.find(_VIRTUAL_IMPORTS) + 1:], ) - return struct(path = context.genfiles_dir.path, import_path = None) + + out_dir = context.genfiles_dir.path + ws_root = context.label.workspace_root + if ws_root: + out_dir = out_dir + "/" + ws_root + return struct(path = out_dir, import_path = None) def is_in_virtual_imports(source_file, virtual_folder = _VIRTUAL_IMPORTS): """Determines if source_file is virtual (is placed in _virtual_imports diff --git a/third_party/grpc/bazel_1.31.1.patch b/third_party/grpc/bazel_1.32.0.patch similarity index 100% rename from third_party/grpc/bazel_1.31.1.patch rename to third_party/grpc/bazel_1.32.0.patch diff --git a/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.cpp b/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.cpp index 695ef8581ba326..facb95de145cef 100644 --- a/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.cpp @@ -37,18 +37,22 @@ #define XSTR(s) STR(s) #endif -#ifndef FALLTHROUGH_INTENDED -#define FALLTHROUGH_INTENDED +#ifdef ABSL_FALLTHROUGH_INTENDED +#define FALLTHROUGH ABSL_FALLTHROUGH_INTENDED +#else +#define FALLTHROUGH #endif namespace java_grpc_generator { -using google::protobuf::FileDescriptor; -using google::protobuf::ServiceDescriptor; -using google::protobuf::MethodDescriptor; -using google::protobuf::Descriptor; -using google::protobuf::io::Printer; -using google::protobuf::SourceLocation; +namespace protobuf = google::protobuf; + +using protobuf::Descriptor; +using protobuf::FileDescriptor; +using protobuf::MethodDescriptor; +using protobuf::ServiceDescriptor; +using protobuf::SourceLocation; +using protobuf::io::Printer; using std::to_string; // java keywords from: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.9 @@ -162,7 +166,7 @@ static inline std::string MethodIdFieldName(const MethodDescriptor* method) { } static inline std::string MessageFullJavaName(const Descriptor* desc) { - return google::protobuf::compiler::java::ClassName(desc); + return protobuf::compiler::java::ClassName(desc); } // TODO(nmittler): Remove once protobuf includes javadoc methods in distribution. @@ -425,12 +429,12 @@ static void PrintMethodFields( " .setFullMethodName(generateFullMethodName(SERVICE_NAME, \"$method_name$\"))\n"); bool safe = method->options().idempotency_level() - == google::protobuf::MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS; + == protobuf::MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS; if (safe) { p->Print(*vars, " .setSafe(true)\n"); } else { bool idempotent = method->options().idempotency_level() - == google::protobuf::MethodOptions_IdempotencyLevel_IDEMPOTENT; + == protobuf::MethodOptions_IdempotencyLevel_IDEMPOTENT; if (idempotent) { p->Print(*vars, " .setIdempotent(true)\n"); } @@ -542,7 +546,7 @@ static void PrintStub( break; case BLOCKING_CLIENT_INTERFACE: interface = true; - FALLTHROUGH_INTENDED; + FALLTHROUGH; case BLOCKING_CLIENT_IMPL: call_type = BLOCKING_CALL; stub_name += "BlockingStub"; @@ -551,7 +555,7 @@ static void PrintStub( break; case FUTURE_CLIENT_INTERFACE: interface = true; - FALLTHROUGH_INTENDED; + FALLTHROUGH; case FUTURE_CLIENT_IMPL: call_type = FUTURE_CALL; stub_name += "FutureStub"; @@ -916,7 +920,7 @@ static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service, (*vars)["proto_base_descriptor_supplier"] = service->name() + "BaseDescriptorSupplier"; (*vars)["proto_file_descriptor_supplier"] = service->name() + "FileDescriptorSupplier"; (*vars)["proto_method_descriptor_supplier"] = service->name() + "MethodDescriptorSupplier"; - (*vars)["proto_class_name"] = google::protobuf::compiler::java::ClassName(service->file()); + (*vars)["proto_class_name"] = protobuf::compiler::java::ClassName(service->file()); p->Print( *vars, "private static abstract class $proto_base_descriptor_supplier$\n" @@ -1186,7 +1190,7 @@ void PrintImports(Printer* p) { } void GenerateService(const ServiceDescriptor* service, - google::protobuf::io::ZeroCopyOutputStream* out, + protobuf::io::ZeroCopyOutputStream* out, ProtoFlavor flavor, bool disable_version) { // All non-generated classes must be referred by fully qualified names to @@ -1242,7 +1246,7 @@ void GenerateService(const ServiceDescriptor* service, } std::string ServiceJavaPackage(const FileDescriptor* file) { - std::string result = google::protobuf::compiler::java::ClassName(file); + std::string result = protobuf::compiler::java::ClassName(file); size_t last_dot_pos = result.find_last_of('.'); if (last_dot_pos != std::string::npos) { result.resize(last_dot_pos); @@ -1252,7 +1256,7 @@ std::string ServiceJavaPackage(const FileDescriptor* file) { return result; } -std::string ServiceClassName(const google::protobuf::ServiceDescriptor* service) { +std::string ServiceClassName(const ServiceDescriptor* service) { return service->name() + "Grpc"; } diff --git a/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.h b/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.h index 66a4e9c9c43602..2ecc884efd4506 100644 --- a/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.h +++ b/third_party/grpc/compiler/src/java_plugin/cpp/java_generator.h @@ -47,24 +47,26 @@ class LogHelper { // Abort the program after logging the mesage. #define GRPC_CODEGEN_FAIL GRPC_CODEGEN_CHECK(false) -using namespace std; - namespace java_grpc_generator { +namespace impl { +namespace protobuf = google::protobuf; +} // namespace impl + enum ProtoFlavor { NORMAL, LITE }; // Returns the package name of the gRPC services defined in the given file. -std::string ServiceJavaPackage(const google::protobuf::FileDescriptor* file); +std::string ServiceJavaPackage(const impl::protobuf::FileDescriptor* file); // Returns the name of the outer class that wraps in all the generated code for // the given service. -std::string ServiceClassName(const google::protobuf::ServiceDescriptor* service); +std::string ServiceClassName(const impl::protobuf::ServiceDescriptor* service); // Writes the generated service interface into the given ZeroCopyOutputStream -void GenerateService(const google::protobuf::ServiceDescriptor* service, - google::protobuf::io::ZeroCopyOutputStream* out, +void GenerateService(const impl::protobuf::ServiceDescriptor* service, + impl::protobuf::io::ZeroCopyOutputStream* out, ProtoFlavor flavor, bool disable_version); diff --git a/third_party/grpc/compiler/src/java_plugin/cpp/java_plugin.cpp b/third_party/grpc/compiler/src/java_plugin/cpp/java_plugin.cpp index d8b10c52422dde..2eed9d260d1698 100644 --- a/third_party/grpc/compiler/src/java_plugin/cpp/java_plugin.cpp +++ b/third_party/grpc/compiler/src/java_plugin/cpp/java_plugin.cpp @@ -27,6 +27,8 @@ #include #include +namespace protobuf = google::protobuf; + static std::string JavaPackageToDir(const std::string& package_name) { std::string package_dir = package_name; for (size_t i = 0; i < package_dir.size(); ++i) { @@ -38,7 +40,7 @@ static std::string JavaPackageToDir(const std::string& package_name) { return package_dir; } -class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { +class JavaGrpcGenerator : public protobuf::compiler::CodeGenerator { public: JavaGrpcGenerator() {} virtual ~JavaGrpcGenerator() {} @@ -47,12 +49,12 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { return FEATURE_PROTO3_OPTIONAL; } - virtual bool Generate(const google::protobuf::FileDescriptor* file, + virtual bool Generate(const protobuf::FileDescriptor* file, const std::string& parameter, - google::protobuf::compiler::GeneratorContext* context, + protobuf::compiler::GeneratorContext* context, std::string* error) const override { std::vector > options; - google::protobuf::compiler::ParseGeneratorParameter(parameter, &options); + protobuf::compiler::ParseGeneratorParameter(parameter, &options); java_grpc_generator::ProtoFlavor flavor = java_grpc_generator::ProtoFlavor::NORMAL; @@ -69,10 +71,10 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { std::string package_name = java_grpc_generator::ServiceJavaPackage(file); std::string package_filename = JavaPackageToDir(package_name); for (int i = 0; i < file->service_count(); ++i) { - const google::protobuf::ServiceDescriptor* service = file->service(i); + const protobuf::ServiceDescriptor* service = file->service(i); std::string filename = package_filename + java_grpc_generator::ServiceClassName(service) + ".java"; - std::unique_ptr output( + std::unique_ptr output( context->Open(filename)); java_grpc_generator::GenerateService( service, output.get(), flavor, disable_version); @@ -83,5 +85,5 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { int main(int argc, char* argv[]) { JavaGrpcGenerator generator; - return google::protobuf::compiler::PluginMain(argc, argv, &generator); + return protobuf::compiler::PluginMain(argc, argv, &generator); } diff --git a/third_party/grpc/grpc-api-1.32.2.jar b/third_party/grpc/grpc-api-1.32.2.jar new file mode 100644 index 00000000000000..26b0ae4222e4b8 Binary files /dev/null and b/third_party/grpc/grpc-api-1.32.2.jar differ diff --git a/third_party/grpc/grpc-auth-1.32.2.jar b/third_party/grpc/grpc-auth-1.32.2.jar new file mode 100644 index 00000000000000..9470c72a2aa916 Binary files /dev/null and b/third_party/grpc/grpc-auth-1.32.2.jar differ diff --git a/third_party/grpc/grpc-context-1.32.2.jar b/third_party/grpc/grpc-context-1.32.2.jar new file mode 100644 index 00000000000000..91e94b65de02c1 Binary files /dev/null and b/third_party/grpc/grpc-context-1.32.2.jar differ diff --git a/third_party/grpc/grpc-core-1.32.2.jar b/third_party/grpc/grpc-core-1.32.2.jar new file mode 100644 index 00000000000000..60ec9075d491be Binary files /dev/null and b/third_party/grpc/grpc-core-1.32.2.jar differ diff --git a/third_party/grpc/grpc-netty-1.32.2.jar b/third_party/grpc/grpc-netty-1.32.2.jar new file mode 100644 index 00000000000000..a08935fdf059a2 Binary files /dev/null and b/third_party/grpc/grpc-netty-1.32.2.jar differ diff --git a/third_party/grpc/grpc-protobuf-1.32.2.jar b/third_party/grpc/grpc-protobuf-1.32.2.jar new file mode 100644 index 00000000000000..5f8e87f0fd64d4 Binary files /dev/null and b/third_party/grpc/grpc-protobuf-1.32.2.jar differ diff --git a/third_party/grpc/grpc-protobuf-lite-1.32.2.jar b/third_party/grpc/grpc-protobuf-lite-1.32.2.jar new file mode 100644 index 00000000000000..1ec35874d92e1c Binary files /dev/null and b/third_party/grpc/grpc-protobuf-lite-1.32.2.jar differ diff --git a/third_party/grpc/grpc-stub-1.32.2.jar b/third_party/grpc/grpc-stub-1.32.2.jar new file mode 100644 index 00000000000000..1b0b6a9b53292a Binary files /dev/null and b/third_party/grpc/grpc-stub-1.32.2.jar differ diff --git a/third_party/grpc/grpc_1.32.0.patch b/third_party/grpc/grpc_1.32.0.patch new file mode 100644 index 00000000000000..60f4d0090a98dd --- /dev/null +++ b/third_party/grpc/grpc_1.32.0.patch @@ -0,0 +1,90 @@ +commit bb0d04663c7dc6c0096f8717cb4ec26330a5ae40 +Author: Yun Peng +Date: Wed Jun 3 15:35:31 2020 +0200 + + Patch grpc v1.26.0 for Bazel build + + - Avoid loading dependencies that're not needed for the gRPC C++ + libraries + - Add bazel mirror URL for upb and cares + - Redirect zlib to @//third_party/zlib + +diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl +index 7bb6b8bdb9..7644107b70 100644 +--- a/bazel/grpc_build_system.bzl ++++ b/bazel/grpc_build_system.bzl +@@ -25,7 +25,7 @@ + + load("//bazel:cc_grpc_library.bzl", "cc_grpc_library") + load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library") +-load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") ++# load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") + + # The set of pollers to test against if a test exercises polling + POLLERS = ["epollex", "epoll1", "poll"] +@@ -181,13 +181,13 @@ def ios_cc_test( + testonly = 1, + ) + ios_test_deps = [ios_test_adapter, ":" + test_lib_ios] +- ios_unit_test( +- name = name + "_on_ios", +- size = kwargs.get("size"), +- tags = ios_tags, +- minimum_os_version = "9.0", +- deps = ios_test_deps, +- ) ++ # ios_unit_test( ++ # name = name + "_on_ios", ++ # size = kwargs.get("size"), ++ # tags = ios_tags, ++ # minimum_os_version = "9.0", ++ # deps = ios_test_deps, ++ # ) + + def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++", size = "medium", timeout = None, tags = [], exec_compatible_with = [], exec_properties = {}, shard_count = None, flaky = None): + copts = if_mac(["-DGRPC_CFSTREAM"]) +diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl +index 09fcad95a2..9b737e5deb 100644 +--- a/bazel/grpc_deps.bzl ++++ b/bazel/grpc_deps.bzl +@@ -33,7 +33,7 @@ def grpc_deps(): + + native.bind( + name = "madler_zlib", +- actual = "@zlib//:zlib", ++ actual = "@//third_party/zlib", + ) + + native.bind( +diff --git a/bazel/grpc_extra_deps.bzl b/bazel/grpc_extra_deps.bzl +index 4c1dfad2e8..f63c54ddef 100644 +--- a/bazel/grpc_extra_deps.bzl ++++ b/bazel/grpc_extra_deps.bzl +@@ -1,11 +1,6 @@ + """Loads the dependencies necessary for the external repositories defined in grpc_deps.bzl.""" + +-load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + load("@upb//bazel:workspace_deps.bzl", "upb_deps") +-load("@envoy_api//bazel:repositories.bzl", "api_dependencies") +-load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +-load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies") +-load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies") + + def grpc_extra_deps(): + """Loads the extra dependencies. +@@ -26,15 +21,5 @@ def grpc_extra_deps(): + grpc_extra_deps() + ``` + """ +- protobuf_deps() +- + upb_deps() + +- api_dependencies() +- +- go_rules_dependencies() +- go_register_toolchains() +- +- apple_rules_dependencies() +- +- apple_support_dependencies()