From 571c75aa330663e51e9eed3ad5b9f9d3898f3dcc Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Thu, 13 Apr 2017 16:39:37 -0700 Subject: [PATCH 1/3] Switch to Makefile based build on mac --- PYTHON-MANIFEST.in | 1 + setup.py | 18 ++++++++++++++---- src/python/grpcio/commands.py | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/PYTHON-MANIFEST.in b/PYTHON-MANIFEST.in index 846530532df..65876342198 100644 --- a/PYTHON-MANIFEST.in +++ b/PYTHON-MANIFEST.in @@ -17,3 +17,4 @@ include src/python/grpcio/support.py include src/python/grpcio/README.rst include requirements.txt include etc/roots.pem +include Makefile diff --git a/setup.py b/setup.py index 6ea79fc20a7..df97731ca02 100644 --- a/setup.py +++ b/setup.py @@ -102,7 +102,7 @@ ENABLE_DOCUMENTATION_BUILD = os.environ.get( 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' + EXTRA_ENV_COMPILE_ARGS = '' if 'win32' in sys.platform and sys.version_info < (3, 5): # We use define flags here and don't directly add to DEFINE_MACROS below to # ensure that the expert user/builder has a way of turning it off (via the @@ -114,7 +114,9 @@ if EXTRA_ENV_COMPILE_ARGS is None: EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime64 -D_timeb=__timeb64' elif 'win32' in sys.platform: EXTRA_ENV_COMPILE_ARGS += ' -D_PYTHON_MSVC' - elif "linux" in sys.platform or "darwin" in sys.platform: + elif "linux" in sys.platform: + EXTRA_ENV_COMPILE_ARGS += ' -std=c++11 -fvisibility=hidden -fno-wrapv' + elif "darwin" in sys.platform: EXTRA_ENV_COMPILE_ARGS += ' -fvisibility=hidden -fno-wrapv' if EXTRA_ENV_LINK_ARGS is None: @@ -172,7 +174,7 @@ LDFLAGS = tuple(EXTRA_LINK_ARGS) CFLAGS = tuple(EXTRA_COMPILE_ARGS) if "linux" in sys.platform or "darwin" in sys.platform: pymodinit_type = 'PyObject*' if PY3 else 'void' - pymodinit = 'extern "C" __attribute__((visibility ("default"))) {}'.format(pymodinit_type) + pymodinit = '__attribute__((visibility ("default"))) {}'.format(pymodinit_type) DEFINE_MACROS += (('PyMODINIT_FUNC', pymodinit),) # By default, Python3 distutils enforces compatibility of @@ -192,14 +194,22 @@ def cython_extensions_and_necessity(): cython_module_files = [os.path.join(PYTHON_STEM, name.replace('.', '/') + '.pyx') for name in CYTHON_EXTENSION_MODULE_NAMES] + if "darwin" in sys.platform: + extra_objects = ['libs/opt/libares.a', + 'libs/opt/libboringssl.a', + 'libs/opt/libgpr.a', + 'libs/opt/libgrpc.a'] + CORE_C_FILES = [] + else: + extra_objects = [] extensions = [ _extension.Extension( name=module_name, - language='c++', sources=[module_file] + list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES), include_dirs=list(EXTENSION_INCLUDE_DIRECTORIES), libraries=list(EXTENSION_LIBRARIES), define_macros=list(DEFINE_MACROS), + extra_objects=extra_objects, extra_compile_args=list(CFLAGS), extra_link_args=list(LDFLAGS), ) for (module_name, module_file) in zip(list(CYTHON_EXTENSION_MODULE_NAMES), cython_module_files) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index f196b028a76..f6a66f1f418 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -266,6 +266,25 @@ class BuildExt(build_ext.build_ext): LINK_OPTIONS = {} def build_extensions(self): + if "darwin" in sys.platform: + target_path = os.path.abspath( + os.path.join(os.path.dirname(os.path.realpath(__file__)), + '..', '..', '..', 'libs', 'opt')) + targets = [os.path.join(target_path, 'libboringssl.a'), + os.path.join(target_path, 'libares.a'), + os.path.join(target_path, 'libgpr.a'), + os.path.join(target_path, 'libgrpc.a')] + make_process = subprocess.Popen(['make'] + targets, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + make_out, make_err = make_process.communicate() + if make_out and make_process.returncode != 0: + sys.stdout.write(make_out + '\n') + if make_err: + sys.stderr.write(make_err + '\n') + if make_process.returncode != 0: + raise Exception("make command failed!") + compiler = self.compiler.compiler_type if compiler in BuildExt.C_OPTIONS: for extension in self.extensions: From 2d9c9d940efbc19e3be8d37da54155109d9b1aa5 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Thu, 13 Apr 2017 17:07:32 -0700 Subject: [PATCH 2/3] linux fix --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index df97731ca02..047f0f1f5c3 100644 --- a/setup.py +++ b/setup.py @@ -199,13 +199,14 @@ def cython_extensions_and_necessity(): 'libs/opt/libboringssl.a', 'libs/opt/libgpr.a', 'libs/opt/libgrpc.a'] - CORE_C_FILES = [] + core_c_files = [] else: + core_c_files = list(CORE_C_FILES) extra_objects = [] extensions = [ _extension.Extension( name=module_name, - sources=[module_file] + list(CYTHON_HELPER_C_FILES) + list(CORE_C_FILES), + sources=[module_file] + list(CYTHON_HELPER_C_FILES) + core_c_files, include_dirs=list(EXTENSION_INCLUDE_DIRECTORIES), libraries=list(EXTENSION_LIBRARIES), define_macros=list(DEFINE_MACROS), From 1f24b2ad8a5b56db4ec2fa6e187ead604194d1c1 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Thu, 13 Apr 2017 17:34:52 -0700 Subject: [PATCH 3/3] Changes --- PYTHON-MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PYTHON-MANIFEST.in b/PYTHON-MANIFEST.in index 65876342198..8be0af964f0 100644 --- a/PYTHON-MANIFEST.in +++ b/PYTHON-MANIFEST.in @@ -7,7 +7,7 @@ graft include/grpc graft third_party/boringssl graft third_party/nanopb graft third_party/zlib -graft third_party/c-ares +graft third_party/cares include src/python/grpcio/_spawn_patch.py include src/python/grpcio/commands.py include src/python/grpcio/grpc_version.py