From 0ee1243fb6b29ef6574ba85806633af68fd9ca67 Mon Sep 17 00:00:00 2001 From: Mike Sarahan Date: Tue, 18 Feb 2020 13:53:05 -0600 Subject: [PATCH] fix win setup cmds --- setup.py | 30 ++++++++++++++++-------------- src/python/grpcio/commands.py | 15 +++++++++------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index 8809e57..628fcf2 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,6 @@ # limitations under the License. """A setup module for the GRPC Python package.""" -from distutils import cygwinccompiler from distutils import extension as _extension from distutils import util import os @@ -144,14 +143,18 @@ ENABLE_DOCUMENTATION_BUILD = os.environ.get( def check_linker_need_libatomic(): """Test if linker on system needs libatomic.""" - code_test = (b'#include \n' + - b'int main() { return std::atomic{}; }') - cc_test = subprocess.Popen(['cc', '-x', 'c++', '-std=c++11', '-'], - stdin=PIPE, - stdout=PIPE, - stderr=PIPE) - cc_test.communicate(input=code_test) - return cc_test.returncode != 0 + if sys.platform == 'win32': + result = False + else: + code_test = (b'#include \n' + + b'int main() { return std::atomic{}; }') + cc_test = subprocess.Popen(['cc', '-x', 'c++', '-std=c++11', '-'], + stdin=PIPE, + stdout=PIPE, + stderr=PIPE) + cc_test.communicate(input=code_test) + result = cc_test.returncode != 0 + return result # Patch ccompiler not to pass -std=c++11 for C code. # This is neccessary on macOS to avoid: @@ -183,7 +186,6 @@ def monkeypatch_spawn_using_cxx11_for_cxx_only(): EXTRA_ENV_COMPILE_ARGS = os.environ.get('GRPC_PYTHON_CFLAGS', None) EXTRA_ENV_LINK_ARGS = os.environ.get('GRPC_PYTHON_LDFLAGS', None) if EXTRA_ENV_COMPILE_ARGS is None: - EXTRA_ENV_COMPILE_ARGS = ' -std=c++11' if 'win32' in sys.platform: if sys.version_info < (3, 5): EXTRA_ENV_COMPILE_ARGS += ' -D_hypot=hypot' @@ -195,13 +197,11 @@ if EXTRA_ENV_COMPILE_ARGS is None: EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime32 -D_timeb=__timeb32 -D_ftime_s=_ftime32_s' else: EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime64 -D_timeb=__timeb64' - else: - # We need to statically link the C++ Runtime, only the C runtime is - # available dynamically - EXTRA_ENV_COMPILE_ARGS += ' /MT' elif "linux" in sys.platform: + EXTRA_ENV_COMPILE_ARGS = ' -std=c++11' EXTRA_ENV_COMPILE_ARGS += ' -std=gnu99 -fvisibility=hidden -fno-wrapv -fno-exceptions' elif "darwin" in sys.platform: + EXTRA_ENV_COMPILE_ARGS = ' -std=c++11' EXTRA_ENV_COMPILE_ARGS += ' -stdlib=libc++ -fvisibility=hidden -fno-wrapv -fno-exceptions' if EXTRA_ENV_LINK_ARGS is None: @@ -211,6 +211,7 @@ if EXTRA_ENV_LINK_ARGS is None: if check_linker_need_libatomic(): EXTRA_ENV_LINK_ARGS += ' -latomic' elif "win32" in sys.platform and sys.version_info < (3, 5): + from distutils import cygwinccompiler msvcr = cygwinccompiler.get_msvcr()[0] EXTRA_ENV_LINK_ARGS += ( ' -static-libgcc -static-libstdc++ -mcrtdll={msvcr}' @@ -344,6 +345,7 @@ def cython_extensions_and_necessity(): need_cython = need_cython or not commands.check_and_update_cythonization(extensions) # TODO: the strategy for conditional compiling and exposing the aio Cython # dependencies will be revisited by https://github.com/grpc/grpc/issues/19728 + return commands.try_cythonize(extensions, linetracing=ENABLE_CYTHON_TRACING, mandatory=BUILD_WITH_CYTHON), need_cython CYTHON_EXTENSION_MODULES, need_cython = cython_extensions_and_necessity() diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 064dda9..822f4c1 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -216,12 +216,15 @@ class BuildExt(build_ext.build_ext): when invoked in C mode. GCC is okay with this, while clang is not. """ # TODO(lidiz) Remove the generated a.out for success tests. - cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - _, cc_err = cc_test.communicate(input=b'int main(){return 0;}') - return not 'invalid argument' in str(cc_err) + if sys.platform == "win32": + return False + else: + cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + _, cc_err = cc_test.communicate(input=b'int main(){return 0;}') + return not 'invalid argument' in str(cc_err) # This special conditioning is here due to difference of compiler # behavior in gcc and clang. The clang doesn't take --stdc++11 -- 2.20.1.windows.1