summaryrefslogtreecommitdiff
path: root/grpc/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'grpc/setup.py')
-rw-r--r--grpc/setup.py93
1 files changed, 65 insertions, 28 deletions
diff --git a/grpc/setup.py b/grpc/setup.py
index 4b8c9d40..c93d419f 100644
--- a/grpc/setup.py
+++ b/grpc/setup.py
@@ -73,6 +73,7 @@ UPB_GRPC_GENERATED_INCLUDE = (os.path.join('src', 'core', 'ext',
'upb-generated'),)
UPBDEFS_GRPC_GENERATED_INCLUDE = (os.path.join('src', 'core', 'ext',
'upbdefs-generated'),)
+XXHASH_INCLUDE = (os.path.join('third_party', 'xxhash'),)
ZLIB_INCLUDE = (os.path.join('third_party', 'zlib'),)
README = os.path.join(PYTHON_STEM, 'README.rst')
@@ -106,37 +107,62 @@ CLASSIFIERS = [
'License :: OSI Approved :: Apache Software License',
]
-BUILD_WITH_BORING_SSL_ASM = os.environ.get('GRPC_BUILD_WITH_BORING_SSL_ASM',
- True)
+
+def _env_bool_value(env_name, default):
+ """Parses a bool option from an environment variable"""
+ return os.environ.get(env_name, default).upper() not in ['FALSE', '0', '']
+
+
+BUILD_WITH_BORING_SSL_ASM = _env_bool_value('GRPC_BUILD_WITH_BORING_SSL_ASM',
+ 'True')
+
+# Export this environment variable to override the platform variant that will
+# be chosen for boringssl assembly optimizations. This option is useful when
+# crosscompiling and the host platform as obtained by distutils.utils.get_platform()
+# doesn't match the platform we are targetting.
+# Example value: "linux-aarch64"
+BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM = os.environ.get(
+ 'GRPC_BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM', '')
# Environment variable to determine whether or not the Cython extension should
# *use* Cython or use the generated C files. Note that this requires the C files
# to have been generated by building first *with* Cython support. Even if this
# is set to false, if the script detects that the generated `.c` file isn't
# present, then it will still attempt to use Cython.
-BUILD_WITH_CYTHON = os.environ.get('GRPC_PYTHON_BUILD_WITH_CYTHON', False)
+BUILD_WITH_CYTHON = _env_bool_value('GRPC_PYTHON_BUILD_WITH_CYTHON', 'False')
# Export this variable to use the system installation of openssl. You need to
# have the header files installed (in /usr/include/openssl) and during
# runtime, the shared library must be installed
-BUILD_WITH_SYSTEM_OPENSSL = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_OPENSSL',
- False)
+BUILD_WITH_SYSTEM_OPENSSL = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_OPENSSL',
+ 'False')
# Export this variable to use the system installation of zlib. You need to
# have the header files installed (in /usr/include/) and during
# runtime, the shared library must be installed
-BUILD_WITH_SYSTEM_ZLIB = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_ZLIB', False)
+BUILD_WITH_SYSTEM_ZLIB = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_ZLIB',
+ 'False')
# Export this variable to use the system installation of cares. You need to
# have the header files installed (in /usr/include/) and during
# runtime, the shared library must be installed
-BUILD_WITH_SYSTEM_CARES = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_CARES',
- False)
+BUILD_WITH_SYSTEM_CARES = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_CARES',
+ 'False')
# Export this variable to use the system installation of re2. You need to
# have the header files installed (in /usr/include/re2) and during
# runtime, the shared library must be installed
-BUILD_WITH_SYSTEM_RE2 = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_RE2', False)
+BUILD_WITH_SYSTEM_RE2 = _env_bool_value('GRPC_PYTHON_BUILD_SYSTEM_RE2', 'False')
+
+# Export this variable to force building the python extension with a statically linked libstdc++.
+# At least on linux, this is normally not needed as we can build manylinux-compatible wheels on linux just fine
+# without statically linking libstdc++ (which leads to a slight increase in the wheel size).
+# This option is useful when crosscompiling wheels for aarch64 where
+# it's difficult to ensure that the crosscompilation toolchain has a high-enough version
+# of GCC (we require >4.9) but still uses old-enough libstdc++ symbols.
+# TODO(jtattermusch): remove this workaround once issues with crosscompiler version are resolved.
+BUILD_WITH_STATIC_LIBSTDCXX = _env_bool_value(
+ 'GRPC_PYTHON_BUILD_WITH_STATIC_LIBSTDCXX', 'False')
# For local development use only: This skips building gRPC Core and its
# dependencies, including protobuf and boringssl. This allows "incremental"
@@ -149,23 +175,23 @@ BUILD_WITH_SYSTEM_RE2 = os.environ.get('GRPC_PYTHON_BUILD_SYSTEM_RE2', False)
# make HAS_SYSTEM_OPENSSL_ALPN=0
#
# TODO(ericgribkoff) Respect the BUILD_WITH_SYSTEM_* flags alongside this option
-USE_PREBUILT_GRPC_CORE = os.environ.get('GRPC_PYTHON_USE_PREBUILT_GRPC_CORE',
- False)
+USE_PREBUILT_GRPC_CORE = _env_bool_value('GRPC_PYTHON_USE_PREBUILT_GRPC_CORE',
+ 'False')
# If this environmental variable is set, GRPC will not try to be compatible with
# libc versions old than the one it was compiled against.
-DISABLE_LIBC_COMPATIBILITY = os.environ.get(
- 'GRPC_PYTHON_DISABLE_LIBC_COMPATIBILITY', False)
+DISABLE_LIBC_COMPATIBILITY = _env_bool_value(
+ 'GRPC_PYTHON_DISABLE_LIBC_COMPATIBILITY', 'False')
# Environment variable to determine whether or not to enable coverage analysis
# in Cython modules.
-ENABLE_CYTHON_TRACING = os.environ.get('GRPC_PYTHON_ENABLE_CYTHON_TRACING',
- False)
+ENABLE_CYTHON_TRACING = _env_bool_value('GRPC_PYTHON_ENABLE_CYTHON_TRACING',
+ 'False')
# Environment variable specifying whether or not there's interest in setting up
# documentation building.
-ENABLE_DOCUMENTATION_BUILD = os.environ.get(
- 'GRPC_PYTHON_ENABLE_DOCUMENTATION_BUILD', False)
+ENABLE_DOCUMENTATION_BUILD = _env_bool_value(
+ 'GRPC_PYTHON_ENABLE_DOCUMENTATION_BUILD', 'False')
def check_linker_need_libatomic():
@@ -239,6 +265,9 @@ if EXTRA_ENV_LINK_ARGS is None:
EXTRA_COMPILE_ARGS = shlex.split(EXTRA_ENV_COMPILE_ARGS)
EXTRA_LINK_ARGS = shlex.split(EXTRA_ENV_LINK_ARGS)
+if BUILD_WITH_STATIC_LIBSTDCXX:
+ EXTRA_LINK_ARGS.append('-static-libstdc++')
+
CYTHON_EXTENSION_PACKAGE_NAMES = ()
CYTHON_EXTENSION_MODULE_NAMES = ('grpc._cython.cygrpc',)
@@ -271,7 +300,8 @@ EXTENSION_INCLUDE_DIRECTORIES = ((PYTHON_STEM,) + CORE_INCLUDE + ABSL_INCLUDE +
ADDRESS_SORTING_INCLUDE + CARES_INCLUDE +
RE2_INCLUDE + SSL_INCLUDE + UPB_INCLUDE +
UPB_GRPC_GENERATED_INCLUDE +
- UPBDEFS_GRPC_GENERATED_INCLUDE + ZLIB_INCLUDE)
+ UPBDEFS_GRPC_GENERATED_INCLUDE +
+ XXHASH_INCLUDE + ZLIB_INCLUDE)
EXTENSION_LIBRARIES = ()
if "linux" in sys.platform:
@@ -301,17 +331,22 @@ asm_files = []
asm_key = ''
if BUILD_WITH_BORING_SSL_ASM and not BUILD_WITH_SYSTEM_OPENSSL:
+ boringssl_asm_platform = BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM if BUILD_OVERRIDE_BORING_SSL_ASM_PLATFORM else util.get_platform(
+ )
LINUX_X86_64 = 'linux-x86_64'
LINUX_ARM = 'linux-arm'
- if LINUX_X86_64 == util.get_platform():
+ LINUX_AARCH64 = 'linux-aarch64'
+ if LINUX_X86_64 == boringssl_asm_platform:
asm_key = 'crypto_linux_x86_64'
- elif LINUX_ARM == util.get_platform():
+ elif LINUX_ARM == boringssl_asm_platform:
asm_key = 'crypto_linux_arm'
- elif "mac" in util.get_platform() and "x86_64" in util.get_platform():
+ elif LINUX_AARCH64 == boringssl_asm_platform:
+ asm_key = 'crypto_linux_aarch64'
+ elif "mac" in boringssl_asm_platform and "x86_64" in boringssl_asm_platform:
asm_key = 'crypto_mac_x86_64'
else:
print("ASM Builds for BoringSSL currently not supported on:",
- util.get_platform())
+ boringssl_asm_platform)
if asm_key:
asm_files = grpc_core_dependencies.ASM_SOURCE_FILES[asm_key]
else:
@@ -354,14 +389,16 @@ if "linux" in sys.platform or "darwin" in sys.platform:
# By default, Python3 distutils enforces compatibility of
# c plugins (.so files) with the OSX version Python was built with.
# We need OSX 10.10, the oldest which supports C++ thread_local.
+# Python 3.9: Mac OS Big Sur sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') returns int (11)
if 'darwin' in sys.platform:
mac_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
- if mac_target and (pkg_resources.parse_version(mac_target) <
- pkg_resources.parse_version('10.10.0')):
- os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
- os.environ['_PYTHON_HOST_PLATFORM'] = re.sub(
- r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.10-\1',
- util.get_platform())
+ if mac_target:
+ mac_target = pkg_resources.parse_version(str(mac_target))
+ if mac_target < pkg_resources.parse_version('10.10.0'):
+ os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.10'
+ os.environ['_PYTHON_HOST_PLATFORM'] = re.sub(
+ r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.10-\1',
+ util.get_platform())
def cython_extensions_and_necessity():