Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | From 2ef8a85933f3ac36b289979ff9edd49dd12d0d16 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 4 Aug 2017 09:04:07 -0700 |
| 4 | Subject: [PATCH] setup.py: Do not mix C and C++ compiler options |
| 5 | |
| 6 | EXTRA_ENV_COMPILE_ARGS is used both with CC and CXX |
| 7 | so using -std=c++11 or -std=gnu99 together will cause |
| 8 | build time errors espcially with clang |
| 9 | |
| 10 | error: invalid argument '-std=gnu99' not allowed with 'C++' |
| 11 | |
| 12 | gcc7 ( defaults are -std=gnu11 and -std=gnu++14 ) |
| 13 | as well clang default to these standards mode or newer |
| 14 | anyway |
| 15 | |
| 16 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 17 | |
| 18 | 1. Keep '-std=c++11' and '-std=gnu99' to fix native build error |
| 19 | with old gcc (such as gcc 5.4.0 on ubuntu 16.04), for clang |
| 20 | we will remove them through GRPC_PYTHON_CFLAGS at do_compile |
| 21 | in bb recipe. |
| 22 | |
| 23 | 2. While export CC="gcc ", cc_args is None, it will |
| 24 | cause subprocess.Popen always return 1. On centos 8, if you don't |
| 25 | install package libatomic, there will be a native build error |
| 26 | `cannot find /usr/lib64/libatomic.so.1.2.0'. |
| 27 | |
| 28 | Add no harm '-g' to cc_args if cc_args is empty. |
| 29 | |
| 30 | Upstream-Status: Inappropriate [oe specific] |
| 31 | Signed-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 | |
| 37 | diff --git a/setup.py b/setup.py |
| 38 | index 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) |
| 56 | diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py |
| 57 | index 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 | -- |
| 73 | 2.7.4 |
| 74 | |