blob: bff50a0a112024ca28450ba530f2401e9b26e3c1 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From 2ef8a85933f3ac36b289979ff9edd49dd12d0d16 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 4 Aug 2017 09:04:07 -0700
4Subject: [PATCH] setup.py: Do not mix C and C++ compiler options
5
6EXTRA_ENV_COMPILE_ARGS is used both with CC and CXX
7so using -std=c++11 or -std=gnu99 together will cause
8build time errors espcially with clang
9
10error: invalid argument '-std=gnu99' not allowed with 'C++'
11
12gcc7 ( defaults are -std=gnu11 and -std=gnu++14 )
13 as well clang default to these standards mode or newer
14anyway
15
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17
181. Keep '-std=c++11' and '-std=gnu99' to fix native build error
19with old gcc (such as gcc 5.4.0 on ubuntu 16.04), for clang
20we will remove them through GRPC_PYTHON_CFLAGS at do_compile
21in bb recipe.
22
232. While export CC="gcc ", cc_args is None, it will
24cause subprocess.Popen always return 1. On centos 8, if you don't
25install package libatomic, there will be a native build error
26`cannot find /usr/lib64/libatomic.so.1.2.0'.
27
28Add no harm '-g' to cc_args if cc_args is empty.
29
30Upstream-Status: Inappropriate [oe specific]
31Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
32---
33 setup.py | 6 +++++-
34 src/python/grpcio/commands.py | 5 ++++-
35 2 files changed, 9 insertions(+), 2 deletions(-)
36
37diff --git a/setup.py b/setup.py
38index e950057..1b68221 100644
39--- a/setup.py
40+++ b/setup.py
41@@ -144,9 +144,13 @@ ENABLE_DOCUMENTATION_BUILD = os.environ.get(
42
43 def check_linker_need_libatomic():
44 """Test if linker on system needs libatomic."""
45+ compiler, cc_args = os.environ.get('CC').split(' ', 1) or 'gcc'
46+ if not cc_args:
47+ cc_args = "-g"
48+
49 code_test = (b'#include <atomic>\n' +
50 b'int main() { return std::atomic<int64_t>{}; }')
51- cc_test = subprocess.Popen(['cc', '-x', 'c++', '-std=c++11', '-'],
52+ cc_test = subprocess.Popen([compiler, cc_args, '-x', 'c++', '-std=c++11', '-'],
53 stdin=PIPE,
54 stdout=PIPE,
55 stderr=PIPE)
56diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py
57index 064dda9..a75d8b9 100644
58--- a/src/python/grpcio/commands.py
59+++ b/src/python/grpcio/commands.py
60@@ -216,7 +216,10 @@ class BuildExt(build_ext.build_ext):
61 when invoked in C mode. GCC is okay with this, while clang is not.
62 """
63 # TODO(lidiz) Remove the generated a.out for success tests.
64- cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'],
65+ compiler, cc_args = os.environ.get('CC').split(' ', 1) or 'gcc'
66+ if not cc_args:
67+ cc_args = "-g"
68+ cc_test = subprocess.Popen([compiler, cc_args, '-x', 'c', '-std=c++11', '-'],
69 stdin=subprocess.PIPE,
70 stdout=subprocess.PIPE,
71 stderr=subprocess.PIPE)
72--
732.7.4
74