aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/distrib/python/grpcio_tools/setup.py15
-rwxr-xr-xtools/run_tests/build_python.sh15
2 files changed, 24 insertions, 6 deletions
diff --git a/tools/distrib/python/grpcio_tools/setup.py b/tools/distrib/python/grpcio_tools/setup.py
index afb6063906..e025158a82 100644
--- a/tools/distrib/python/grpcio_tools/setup.py
+++ b/tools/distrib/python/grpcio_tools/setup.py
@@ -32,6 +32,7 @@ import errno
import os
import os.path
import pkg_resources
+import platform
import shlex
import shutil
import sys
@@ -45,6 +46,9 @@ from setuptools.command import build_ext
os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.abspath('.'))
+import protoc_lib_deps
+import grpc_version
+
PY3 = sys.version_info.major == 3
# There are some situations (like on Windows) where CC, CFLAGS, and LDFLAGS are
@@ -60,8 +64,9 @@ EXTRA_LINK_ARGS = shlex.split(os.environ.get('GRPC_PYTHON_LDFLAGS',
GRPC_PYTHON_TOOLS_PACKAGE = 'grpc.tools'
GRPC_PYTHON_PROTO_RESOURCES_NAME = '_proto'
-import protoc_lib_deps
-import grpc_version
+DEFINE_MACROS = (('HAVE_PTHREAD', 1),)
+if "win32" in sys.platform and '64bit' in platform.architecture()[0]:
+ DEFINE_MACROS += (('MS_WIN64', 1),)
# By default, Python3 distutils enforces compatibility of
# c plugins (.so files) with the OSX version Python3 was built with.
@@ -108,9 +113,9 @@ def protoc_ext_module():
protoc_lib_deps.CC_INCLUDE,
],
language='c++',
- define_macros=[('HAVE_PTHREAD', 1)],
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
+ define_macros=list(DEFINE_MACROS),
+ extra_compile_args=list(EXTRA_COMPILE_ARGS),
+ extra_link_args=list(EXTRA_LINK_ARGS),
)
return plugin_ext
diff --git a/tools/run_tests/build_python.sh b/tools/run_tests/build_python.sh
index 687b04e954..63b15dd09e 100755
--- a/tools/run_tests/build_python.sh
+++ b/tools/run_tests/build_python.sh
@@ -40,7 +40,7 @@ VENV_RELATIVE_PYTHON=${3:-bin/python}
TOOLCHAIN=${4:-unix}
ROOT=`pwd`
-export CFLAGS="-I$ROOT/include -std=gnu99 -fno-wrapv"
+export CFLAGS="-I$ROOT/include -std=gnu99 -fno-wrapv $CFLAGS"
export GRPC_PYTHON_BUILD_WITH_CYTHON=1
# Default python on the host to fall back to when instantiating e.g. the
@@ -61,6 +61,19 @@ if [ "${PLATFORM/Darwin}" = "$PLATFORM" ]; then
fi
fi
fi
+# TODO(atash) consider conceptualizing MinGW as a first-class platform and move
+# these flags into our `setup.py`s
+if [ "${PLATFORM/MINGW}" != "$PLATFORM" ]; then
+ # We're on MinGW, and our CFLAGS and LDFLAGS will be eaten by the void. Use
+ # our work-around environment variables instead.
+ PYTHON_MSVCR=`$PYTHON -c "from distutils.cygwinccompiler import get_msvcr; print(get_msvcr()[0])"`
+ export GRPC_PYTHON_LDFLAGS="-static-libgcc -static-libstdc++ -mcrtdll=$PYTHON_MSVCR -static -lpthread"
+ # See https://sourceforge.net/p/mingw-w64/bugs/363/
+ export GRPC_PYTHON_CFLAGS="-D_ftime=_ftime64 -D_timeb=__timeb64"
+ # TODO(atash) set these flags for only grpcio-tools (they don't do any harm to
+ # grpcio, but they result in noisy warnings).
+ export GRPC_PYTHON_CFLAGS="-frtti -std=c++11 $GRPC_PYTHON_CFLAGS"
+fi
# Find `realpath`
if [ -x "$(command -v realpath)" ]; then