diff options
author | Masood Malekghassemi <soltanmm@users.noreply.github.com> | 2016-01-12 09:21:57 -0800 |
---|---|---|
committer | Masood Malekghassemi <soltanmm@users.noreply.github.com> | 2016-01-14 06:55:06 -0800 |
commit | 1d177817958efb72679c55c9ef2136d15c5d9636 (patch) | |
tree | 6ab68bdae3f43e8781dba6d5309b900231e95597 /src | |
parent | 59994bcc3e7a3f16e9380b610aaf1f8afa08aa39 (diff) |
Check compiler versions at Python setup time
Diffstat (limited to 'src')
-rw-r--r-- | src/python/grpcio/commands.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 6a7df8e1c1..e1a3f4bed3 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -40,6 +40,17 @@ import setuptools from setuptools.command import build_py from setuptools.command import test +# Because we need to support building without Cython but simultaneously need to +# subclass its command class when we need to and because distutils requires a +# special hook to acquire a command class, we attempt to import Cython's +# build_ext, and if that fails we import setuptools'. +try: + # Due to the strange way Cython's Distutils module re-imports build_ext, we + # import the build_ext class directly. + from Cython.Distutils.build_ext import build_ext +except ImportError: + from setuptools.command.build_ext import build_ext + PYTHON_STEM = os.path.dirname(os.path.abspath(__file__)) CONF_PY_ADDENDUM = """ @@ -168,6 +179,26 @@ class BuildPy(build_py.build_py): build_py.build_py.run(self) +class BuildExt(build_ext): + """Custom build_ext command to enable compiler-specific flags.""" + + C_OPTIONS = { + 'unix': ('-pthread', '-std=gnu99'), + 'msvc': (), + } + LINK_OPTIONS = {} + + def build_extensions(self): + compiler = self.compiler.compiler_type + if compiler in BuildExt.C_OPTIONS: + for extension in self.extensions: + extension.extra_compile_args += list(BuildExt.C_OPTIONS[compiler]) + if compiler in BuildExt.LINK_OPTIONS: + for extension in self.extensions: + extension.extra_link_args += list(BuildExt.LINK_OPTIONS[compiler]) + build_ext.build_extensions(self) + + class Gather(setuptools.Command): """Command to gather project dependencies.""" |