Skip to content

Commit e755b80

Browse files
pau-baigetapazylbe
authored andcommitted
Add patch to fix gRPC compilation issue with gcc-9.2.1-31 (#319)
Add patch to fix gRPC compilation issue with gcc-9.2.1-31 (cherry picked from commit a2b6565)
1 parent 11874ed commit e755b80

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

tools/build/rules/repository.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _github_repository_impl(ctx):
7171
stripPrefix = args.strip_prefix,
7272
sha256 = ctx.attr.sha256,
7373
)
74+
_apply_patch(ctx)
7475
_add_build_file(ctx)
7576

7677
_github_repository = repository_rule(
@@ -81,6 +82,7 @@ _github_repository = repository_rule(
8182
branch = attr.string(),
8283
commit = attr.string(),
8384
sha256 = attr.string(),
85+
patch_file = attr.string(),
8486
),
8587
)
8688

@@ -112,6 +114,20 @@ def maybe_repository(repo_rule, name, locals, **kwargs):
112114
build_file = build_file
113115
)
114116

117+
def _apply_patch(ctx):
118+
if ctx.attr.patch_file:
119+
ctx.symlink(Label(ctx.attr.patch_file), "patch_to_repository.patch")
120+
cmd = "cd \"{}\" && /usr/bin/patch -p1 -i patch_to_repository.patch".format(ctx.path("."))
121+
print("Applying patch: " + cmd)
122+
bash_exe = "bash"
123+
if ctx.os.name.startswith("windows"):
124+
bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "c:/tools/msys64/usr/bin/bash.exe"
125+
result = ctx.execute([bash_exe, "--login", "-c", cmd])
126+
if result.return_code:
127+
fail("Failed to apply patch: (%d)\n%s" % (result.return_code, result.stderr))
128+
else:
129+
print("Patch applied successfully")
130+
115131
# This is *not* a complete maven implementation, it's just good enough for our rules.
116132

117133
_MAVEN_URL = "https://repo.maven.apache.org/maven2"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (C) 2020 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Empty build file to make this directory a bazel package.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
From f4f551a3fbb18ff2dc49940fe31a2ee115c9a302 Mon Sep 17 00:00:00 2001
2+
From: Juanli Shen <[email protected]>
3+
Date: Fri, 23 Aug 2019 08:46:09 -0700
4+
Subject: [PATCH] Fix gettid() naming conflict
5+
6+
---
7+
src/core/lib/gpr/log_linux.cc | 6 ++++--
8+
src/core/lib/iomgr/ev_epollex_linux.cc | 6 ++++--
9+
2 files changed, 8 insertions(+), 4 deletions(-)
10+
11+
diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc
12+
index 561276f0c2..81026e5689 100644
13+
--- a/src/core/lib/gpr/log_linux.cc
14+
+++ b/src/core/lib/gpr/log_linux.cc
15+
@@ -40,7 +40,9 @@
16+
#include <time.h>
17+
#include <unistd.h>
18+
19+
-static long gettid(void) { return syscall(__NR_gettid); }
20+
+// Not naming it as gettid() to avoid duplicate declarations when compiled with
21+
+// GCC 9.1.
22+
+static long local_gettid(void) { return syscall(__NR_gettid); }
23+
24+
void gpr_log(const char* file, int line, gpr_log_severity severity,
25+
const char* format, ...) {
26+
@@ -70,7 +72,7 @@ void gpr_default_log(gpr_log_func_args* args) {
27+
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
28+
struct tm tm;
29+
static __thread long tid = 0;
30+
- if (tid == 0) tid = gettid();
31+
+ if (tid == 0) tid = local_gettid();
32+
33+
timer = static_cast<time_t>(now.tv_sec);
34+
final_slash = strrchr(args->file, '/');
35+
diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc
36+
index c2d80c08dd..991c061219 100644
37+
--- a/src/core/lib/iomgr/ev_epollex_linux.cc
38+
+++ b/src/core/lib/iomgr/ev_epollex_linux.cc
39+
@@ -1077,7 +1077,9 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
40+
}
41+
42+
#ifndef NDEBUG
43+
-static long gettid(void) { return syscall(__NR_gettid); }
44+
+// Not naming it as gettid() to avoid duplicate declarations when compiled with
45+
+// GCC 9.1.
46+
+static long local_gettid(void) { return syscall(__NR_gettid); }
47+
#endif
48+
49+
/* pollset->mu lock must be held by the caller before calling this.
50+
@@ -1097,7 +1099,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
51+
#define WORKER_PTR (&worker)
52+
#endif
53+
#ifndef NDEBUG
54+
- WORKER_PTR->originator = gettid();
55+
+ WORKER_PTR->originator = local_gettid();
56+
#endif
57+
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
58+
gpr_log(GPR_INFO,
59+
--
60+
2.27.0.rc2.251.g90737beb825-goog
61+

tools/build/workspace.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ def gapid_dependencies(android = True, mingw = True, locals = {}):
7272
# v1.20.1
7373
commit = "7741e806a213cba63c96234f16d712a8aa101a49",
7474
sha256 = "9ed7d944d8d07deac365c9edcda10ce8159c1436119e1b0792a1e830cb20606c",
75+
# This patch works around a naming conflict in grpc which leads to
76+
# compilation issues in recent gcc/glibc. This issue is fixed on recent
77+
# grpc versions (since
78+
# https://github.com/grpc/grpc/commit/de6255941a5e1c2fb2d50e57f84e38c09f45023d),
79+
# but updating our grpc version leads to errors in compiling the abseil
80+
# dependency of grpc
81+
# (https://github.com/abseil/abseil-cpp/issues/326). We tried to pull
82+
# abseil ourselves and patch it, but abseil also fails to compile with
83+
# gcc on windows, so we choose to patch grpc directly. Once grpc has a
84+
# version that builds fine on all our targets, we can update grpc and
85+
# drop this patch.
86+
patch_file = "@gapid//tools/build/third_party/com_github_grpc_grpc:com_github_grpc_grpc_fix.patch",
7587
)
7688
_grpc_deps(locals)
7789

0 commit comments

Comments
 (0)