Skip to content

Commit

Permalink
Update bundled gRPC to 1.18.0 and nanopb to 0.3.6
Browse files Browse the repository at this point in the history
And take the opportunity to align third_party/grpc/BUILD closer with
gRPC upstream's BUILD file (by adopting the same intermediate targets)
to make importing easier next time.

The MSYS2 patch is no longer needed judging by discussion in
https://groups.google.com/forum/#!msg/grpc-io/gd6sIuo6rjQ/eyEFarhABgAJ

Fixes #2804.
  • Loading branch information
tetromino authored and katre committed Feb 7, 2019
1 parent da75b71 commit 458ab03
Show file tree
Hide file tree
Showing 1,517 changed files with 171,703 additions and 78,611 deletions.
2,057 changes: 1,591 additions & 466 deletions third_party/grpc/BUILD

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions third_party/grpc/README.bazel.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# How to update the C++ sources of gRPC:

1. `git clone http://github.com/grpc/grpc.git` in a convenient directory
2. `git checkout <tag>` (current is `release-0_13`, commithash `78e04bbd`)
2. `git checkout <tag>` (current is `v1.18.0`, commithash `007b721f`)
3. `mkdir -p third_party/grpc/src`
4. `cp -R <gRPC git tree>/src/{compiler,core-cpp} third_party/grpc/src`
4. `cp -R <gRPC git tree>/src/{compiler,core,cpp} third_party/grpc/src`
5. `cp -R <gRPC git tree>/include third_party/grpc`
6. Update BUILD files by copying the rules from the BUILD file of gRPC
7. Patch in grpc.patch. It makes gRPC work under msys2.
6. `rm -rf third_party/grpc/src/core/tsi/test_creds`
7. Update BUILD files by copying the rules from the BUILD file of gRPC;
fix macros in third_party/grpc/build_defs.bzl if necessary
8. Update //third_party/nanopb if necessary


# How to update the Java plugin:
Expand Down
192 changes: 123 additions & 69 deletions third_party/grpc/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,42 @@ load("//third_party/grpc:build_defs.bzl", "java_grpc_library")
"""

def _path_ignoring_repository(f):
if (len(f.owner.workspace_root) == 0):
return f.short_path
# If |f| is a generated file, it will have "bazel-out/*/genfiles" prefix
# before "external/workspace", so we need to add the starting index of "external/workspace"
return f.path[f.path.find(f.owner.workspace_root)+len(f.owner.workspace_root)+1:]
if (len(f.owner.workspace_root) == 0):
return f.short_path

# If |f| is a generated file, it will have "bazel-out/*/genfiles" prefix
# before "external/workspace", so we need to add the starting index of "external/workspace"
return f.path[f.path.find(f.owner.workspace_root) + len(f.owner.workspace_root) + 1:]

def _gensource_impl(ctx):
if len(ctx.attr.srcs) > 1:
fail("Only one src value supported", "srcs")
for s in ctx.attr.srcs:
if s.label.package != ctx.label.package:
print(("in srcs attribute of {0}: Proto source with label {1} should be in "
+ "same package as consuming rule").format(ctx.label, s.label))
srcdotjar = ctx.new_file(ctx.label.name + ".jar")
srcs = [f for dep in ctx.attr.srcs for f in dep.proto.direct_sources]
includes = [f for dep in ctx.attr.srcs for f in dep.proto.transitive_imports.to_list()]
if len(ctx.attr.srcs) > 1:
fail("Only one src value supported", "srcs")
for s in ctx.attr.srcs:
if s.label.package != ctx.label.package:
print(("in srcs attribute of {0}: Proto source with label {1} should be in " +
"same package as consuming rule").format(ctx.label, s.label))
srcdotjar = ctx.new_file(ctx.label.name + ".jar")
srcs = [f for dep in ctx.attr.srcs for f in dep.proto.direct_sources]
includes = [f for dep in ctx.attr.srcs for f in dep.proto.transitive_imports.to_list()]

ctx.action(
command = " ".join([
ctx.executable._protoc.path,
"--plugin=protoc-gen-grpc-java={0}".format(ctx.executable._java_plugin.path),
"--grpc-java_out=enable_deprecated={0}:{1}".format(str(ctx.attr.enable_deprecated).lower(), srcdotjar.path)]
+ ["-I{0}={1}".format(_path_ignoring_repository(include), include.path) for include in includes]
+ [src.path for src in srcs]),
inputs = [ctx.executable._java_plugin, ctx.executable._protoc] + srcs + includes,
outputs = [srcdotjar],
use_default_shell_env=True)
ctx.action(
command = " ".join([
ctx.executable._protoc.path,
"--plugin=protoc-gen-grpc-java={0}".format(ctx.executable._java_plugin.path),
"--grpc-java_out=enable_deprecated={0}:{1}".format(str(ctx.attr.enable_deprecated).lower(), srcdotjar.path),
] +
["-I{0}={1}".format(_path_ignoring_repository(include), include.path) for include in includes] +
[src.path for src in srcs]),
inputs = [ctx.executable._java_plugin, ctx.executable._protoc] + srcs + includes,
outputs = [srcdotjar],
use_default_shell_env = True,
)

ctx.action(
command = "cp '%s' '%s'" % (srcdotjar.path, ctx.outputs.srcjar.path),
inputs = [srcdotjar],
outputs = [ctx.outputs.srcjar])
ctx.action(
command = "cp '%s' '%s'" % (srcdotjar.path, ctx.outputs.srcjar.path),
inputs = [srcdotjar],
outputs = [ctx.outputs.srcjar],
)

_java_grpc_gensource = rule(
attrs = {
Expand Down Expand Up @@ -65,44 +69,94 @@ _java_grpc_gensource = rule(
implementation = _gensource_impl,
)

def java_grpc_library(name, srcs, deps, enable_deprecated=None, visibility=None, constraints=None, **kwargs):
"""Generates and compiles gRPC Java sources for services defined in a proto
file. This rule is compatible with proto_library with java_api_version,
java_proto_library, and java_lite_proto_library.
Do note that this rule only scans through the proto file for RPC services. It
does not generate Java classes for proto messages. You will need a separate
proto_library with java_api_version, java_proto_library, or
java_lite_proto_library rule.
Args:
name: (str) A unique name for this rule. Required.
srcs: (list) a single proto_library target that contains the schema of the
service. Required.
deps: (list) a single java_proto_library target for the proto_library in
srcs. Required.
visibility: (list) the visibility list
**kwargs: Passed through to generated targets
"""
gensource_name = name + "_srcs"
_java_grpc_gensource(
name = gensource_name,
srcs = srcs,
enable_deprecated = enable_deprecated,
visibility = ["//visibility:private"],
tags = [
"avoid_dep",
],
**kwargs
)
native.java_library(
name = name,
srcs = [gensource_name],
visibility = visibility,
deps = [
"@io_bazel//third_party:javax_annotations",
"@io_bazel//third_party:jsr305",
"@io_bazel//third_party/grpc:grpc-jar",
"@io_bazel//third_party:guava",
"@com_google_protobuf//:protobuf_java",
] + deps,
**kwargs
)
def java_grpc_library(name, srcs, deps, enable_deprecated = None, visibility = None, constraints = None, **kwargs):
"""Generates and compiles gRPC Java sources for services defined in a proto
file. This rule is compatible with proto_library with java_api_version,
java_proto_library, and java_lite_proto_library.
Do note that this rule only scans through the proto file for RPC services. It
does not generate Java classes for proto messages. You will need a separate
proto_library with java_api_version, java_proto_library, or
java_lite_proto_library rule.
Args:
name: (str) A unique name for this rule. Required.
srcs: (list) a single proto_library target that contains the schema of the
service. Required.
deps: (list) a single java_proto_library target for the proto_library in
srcs. Required.
visibility: (list) the visibility list
**kwargs: Passed through to generated targets
"""
gensource_name = name + "_srcs"
_java_grpc_gensource(
name = gensource_name,
srcs = srcs,
enable_deprecated = enable_deprecated,
visibility = ["//visibility:private"],
tags = [
"avoid_dep",
],
**kwargs
)
native.java_library(
name = name,
srcs = [gensource_name],
visibility = visibility,
deps = [
"@io_bazel//third_party:javax_annotations",
"@io_bazel//third_party:jsr305",
"@io_bazel//third_party/grpc:grpc-jar",
"@io_bazel//third_party:guava",
"@com_google_protobuf//:protobuf_java",
] + deps,
**kwargs
)

def _get_external_deps(external_deps):
ret = []
for dep in external_deps:
ret += ["//third_party/" + dep]
return ret

# Simplified version of gRPC upstream's grpc_cc_library.
def grpc_cc_library(
name,
srcs = [],
public_hdrs = [],
hdrs = [],
external_deps = [],
deps = [],
standalone = False,
language = "C++",
testonly = False,
visibility = None,
alwayslink = 0,
data = []):
copts = []
if language.upper() == "C":
copts = select({
"//conditions:default": [
"-std=c99",
"-Wimplicit-function-declaration",
],
":windows": ["/we4013"],
})
native.cc_library(
name = name,
srcs = srcs,
defines = ["GRPC_ARES=0"], # Our use case doesn't need ares.
hdrs = hdrs + public_hdrs,
deps = deps + _get_external_deps(external_deps),
copts = copts,
visibility = visibility,
testonly = testonly,
linkopts = select({
"//conditions:default": ["-pthread"],
":windows": [],
}),
includes = [
".",
"include",
],
alwayslink = alwayslink,
data = data,
)
134 changes: 0 additions & 134 deletions third_party/grpc/grpc.patch
Original file line number Diff line number Diff line change
@@ -1,137 +1,3 @@
diff --git a/third_party/grpc/BUILD b/third_party/grpc/BUILD
index 51e861f..a635ebc 100644
--- a/third_party/grpc/BUILD
+++ b/third_party/grpc/BUILD
@@ -438,7 +438,7 @@ cc_library(
],
copts = [
"-std=gnu99",
- "-Wno-implicit-function-declaration",
+ "-w",
],
includes = [
".",
@@ -570,6 +570,7 @@ cc_library(
"include/grpc++/support/sync_stream.h",
"include/grpc++/support/time.h",
],
+ copts = ["-w"],
includes = [
".",
"include",
diff --git a/third_party/grpc/include/grpc/impl/codegen/port_platform.h b/third_party/grpc/include/grpc/impl/codegen/port_platform.h
index d265e9b..d22bffb 100644
--- a/third_party/grpc/include/grpc/impl/codegen/port_platform.h
+++ b/third_party/grpc/include/grpc/impl/codegen/port_platform.h
@@ -74,7 +74,45 @@
things. */

#if !defined(GPR_NO_AUTODETECT_PLATFORM)
-#if defined(_WIN64) || defined(WIN64)
+
+#if defined(__MSYS__)
+#define GPR_PLATFORM_STRING "msys2"
+#define GPR_POSIX_CRASH_HANDLER 1
+#ifndef _BSD_SOURCE
+#define _BSD_SOURCE
+#endif
+#ifndef _DEFAULT_SOURCE
+#define _DEFAULT_SOURCE
+#endif
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <features.h>
+#define GPR_CPU_POSIX 1
+#define GPR_GCC_ATOMIC 1
+#define GPR_GCC_TLS 1
+#define GPR_POSIX_MULTIPOLL_WITH_POLL
+#define GPR_POSIX_WAKEUP_FD 1
+#define GPR_POSIX_SOCKET 1
+#define GPR_POSIX_SOCKETADDR 1
+#define GPR_POSIX_ENV 1
+#define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1
+#define GPR_POSIX_SOCKETUTILS
+#define GPR_POSIX_FILE 1
+#define GPR_POSIX_STRING 1
+#define GPR_POSIX_SUBPROCESS 1
+#define GPR_POSIX_SYNC 1
+#define GPR_POSIX_TIME 1
+#define GPR_POSIX_LOG 1
+#define GPR_GETPID_IN_UNISTD_H 1
+#define GPR_HAVE_MSG_NOSIGNAL 1
+#ifdef _LP64
+#define GPR_ARCH_64 1
+#else /* _LP64 */
+#define GPR_ARCH_32 1
+#endif /* _LP64 */
+
+#elif defined(_WIN64) || defined(WIN64)
#define GPR_PLATFORM_STRING "windows"
#define GPR_WIN32 1
#define GPR_ARCH_64 1
diff --git a/third_party/grpc/src/core/iomgr/tcp_server_posix.c b/third_party/grpc/src/core/iomgr/tcp_server_posix.c
index 5e07f82..44b970d 100644
--- a/third_party/grpc/src/core/iomgr/tcp_server_posix.c
+++ b/third_party/grpc/src/core/iomgr/tcp_server_posix.c
@@ -280,13 +280,38 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
goto error;
}

- if (!grpc_set_socket_nonblocking(fd, 1) || !grpc_set_socket_cloexec(fd, 1) ||
- (addr->sa_family != AF_UNIX && (!grpc_set_socket_low_latency(fd, 1) ||
- !grpc_set_socket_reuse_addr(fd, 1))) ||
- !grpc_set_socket_no_sigpipe_if_possible(fd)) {
- gpr_log(GPR_ERROR, "Unable to configure socket %d: %s", fd,
- strerror(errno));
- goto error;
+
+ if (!grpc_set_socket_nonblocking(fd, 1)) {
+ gpr_log(GPR_ERROR, "Unable to set socket %d to nonblocking mode: %s", fd,
+ strerror(errno));
+ goto error;
+ }
+ if (!grpc_set_socket_cloexec(fd, 1)) {
+ gpr_log(GPR_ERROR, "Unable to set socket %d to close-on-exec: %s", fd,
+ strerror(errno));
+ goto error;
+ }
+
+ if (addr->sa_family != AF_UNIX) {
+ if (!grpc_set_socket_low_latency(fd, 1)) {
+ gpr_log(GPR_ERROR, "Unable to set socket %d to low-latency mode: %s", fd,
+ strerror(errno));
+ goto error;
+ }
+
+#if !defined(__MSYS__)
+ if (!grpc_set_socket_reuse_addr(fd, 1)) {
+ gpr_log(GPR_ERROR, "Unable to set SO_REUSEADDR on socket %d: %s", fd,
+ strerror(errno));
+ goto error;
+ }
+#endif
+
+ if (!grpc_set_socket_no_sigpipe_if_possible(fd)) {
+ gpr_log(GPR_ERROR, "Unable to set SO_NOSIGPIPE on socket %d: %s", fd,
+ strerror(errno));
+ goto error;
+ }
}

GPR_ASSERT(addr_len < ~(socklen_t)0);
diff --git a/third_party/grpc/src/core/support/log_linux.c b/third_party/grpc/src/core/support/log_linux.c
index d66b7a3..93a0c1b 100644
--- a/third_party/grpc/src/core/support/log_linux.c
+++ b/third_party/grpc/src/core/support/log_linux.c
@@ -51,7 +51,6 @@
#include <stdarg.h>
#include <string.h>
#include <time.h>
-#include <linux/unistd.h>
#include <sys/syscall.h>
#include <unistd.h>

diff --git a/tools/build_rules/genproto.bzl b/tools/build_rules/genproto.bzl
index 62284a3..bc76cd1 100644
--- a/tools/build_rules/genproto.bzl
Expand Down
Loading

0 comments on commit 458ab03

Please sign in to comment.