aboutsummaryrefslogtreecommitdiffhomepage
path: root/setup.py
diff options
context:
space:
mode:
authorGravatar Masood Malekghassemi <atash@google.com>2016-06-03 19:29:12 -0700
committerGravatar Masood Malekghassemi <atash@google.com>2016-07-08 12:36:04 -0700
commit586e3835fe01257299a8573df3e7540e5778bc45 (patch)
tree66f9d3f872d803c20faab14683141cc18c89473e /setup.py
parentaf26ce6f4383a6c0e70d4c58f276ec4f2a722dfa (diff)
Make Python build standalone on Windows
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/setup.py b/setup.py
index d9c46ba77a..c6d3da7299 100644
--- a/setup.py
+++ b/setup.py
@@ -31,6 +31,7 @@
import os
import os.path
+import platform
import shlex
import shutil
import sys
@@ -56,10 +57,15 @@ os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.abspath(PYTHON_STEM))
# Break import-style to ensure we can actually find our in-repo dependencies.
+import build
import commands
import grpc_core_dependencies
import grpc_version
+# TODO(atash) make this conditional on being on a mingw32 build
+build.monkeypatch_unix_compiler()
+
+
LICENSE = '3-clause BSD'
# Environment variable to determine whether or not the Cython extension should
@@ -72,6 +78,14 @@ BUILD_WITH_CYTHON = os.environ.get('GRPC_PYTHON_BUILD_WITH_CYTHON', False)
ENABLE_CYTHON_TRACING = os.environ.get(
'GRPC_PYTHON_ENABLE_CYTHON_TRACING', False)
+# There are some situations (like on Windows) where CC, CFLAGS, and LDFLAGS are
+# entirely ignored/dropped/forgotten by distutils and its Cygwin/MinGW support.
+# We use these environment variables to thus get around that without locking
+# ourselves in w.r.t. the multitude of operating systems this ought to build on.
+# By default we assume a GCC-like compiler.
+EXTRA_COMPILE_ARGS = shlex.split(os.environ.get('GRPC_PYTHON_CFLAGS', ''))
+EXTRA_LINK_ARGS = shlex.split(os.environ.get('GRPC_PYTHON_LDFLAGS', ''))
+
CYTHON_EXTENSION_PACKAGE_NAMES = ()
CYTHON_EXTENSION_MODULE_NAMES = ('grpc._cython.cygrpc',)
@@ -81,9 +95,7 @@ CYTHON_HELPER_C_FILES = (
os.path.join(PYTHON_STEM, 'grpc/_cython/imports.generated.c'),
)
-CORE_C_FILES = ()
-if not "win32" in sys.platform:
- CORE_C_FILES += tuple(grpc_core_dependencies.CORE_SOURCE_FILES)
+CORE_C_FILES = tuple(grpc_core_dependencies.CORE_SOURCE_FILES)
EXTENSION_INCLUDE_DIRECTORIES = (
(PYTHON_STEM,) + CORE_INCLUDE + BORINGSSL_INCLUDE + ZLIB_INCLUDE)
@@ -93,12 +105,17 @@ if "linux" in sys.platform:
EXTENSION_LIBRARIES += ('rt',)
if not "win32" in sys.platform:
EXTENSION_LIBRARIES += ('m',)
+if "win32" in sys.platform:
+ EXTENSION_LIBRARIES += ('ws2_32',)
DEFINE_MACROS = (('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600), ('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),)
+if "win32" in sys.platform:
+ DEFINE_MACROS += (('OPENSSL_WINDOWS', 1), ('WIN32_LEAN_AND_MEAN', 1),)
+ if '64bit' in platform.architecture()[0]:
+ DEFINE_MACROS += (('MS_WIN64', 1),)
-LDFLAGS = shlex.split(os.environ.get('GRPC_PYTHON_LDFLAGS', ''))
-CFLAGS = shlex.split(os.environ.get('GRPC_PYTHON_CFLAGS', ''))
-
+LDFLAGS = tuple(EXTRA_LINK_ARGS)
+CFLAGS = tuple(EXTRA_COMPILE_ARGS)
if "linux" in sys.platform:
LDFLAGS += ('-Wl,-wrap,memcpy',)
if "linux" in sys.platform or "darwin" in sys.platform: