forked from grpc/grpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crosscompile python aarch64 wheels with dockcross (grpc#25418)
* build aarch64 python wheels via crosscompilation * yapf format code * fix shellcheck complaints * fix python37 aarch64 wheel build * build python wheels on linux aarch64 with static libstdc++ * yapf format code
- Loading branch information
1 parent
0e3a02e
commit fcd43e9
Showing
6 changed files
with
163 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,16 @@ | |
# to have been generated by building first *with* Cython support. | ||
BUILD_WITH_CYTHON = os.environ.get('GRPC_PYTHON_BUILD_WITH_CYTHON', 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 = os.environ.get( | ||
'GRPC_PYTHON_BUILD_WITH_STATIC_LIBSTDCXX', False) | ||
|
||
|
||
def check_linker_need_libatomic(): | ||
"""Test if linker on system needs libatomic.""" | ||
|
@@ -95,6 +105,24 @@ def check_linker_need_libatomic(): | |
return cpp_test.returncode == 0 | ||
|
||
|
||
class BuildExt(build_ext.build_ext): | ||
"""Custom build_ext command.""" | ||
|
||
def get_ext_filename(self, ext_name): | ||
# since python3.5, python extensions' shared libraries use a suffix that corresponds to the value | ||
# of sysconfig.get_config_var('EXT_SUFFIX') and contains info about the architecture the library targets. | ||
# E.g. on x64 linux the suffix is ".cpython-XYZ-x86_64-linux-gnu.so" | ||
# When crosscompiling python wheels, we need to be able to override this suffix | ||
# so that the resulting file name matches the target architecture and we end up with a well-formed | ||
# wheel. | ||
filename = build_ext.build_ext.get_ext_filename(self, ext_name) | ||
orig_ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') | ||
new_ext_suffix = os.getenv('GRPC_PYTHON_OVERRIDE_EXT_SUFFIX') | ||
if new_ext_suffix and filename.endswith(orig_ext_suffix): | ||
filename = filename[:-len(orig_ext_suffix)] + new_ext_suffix | ||
return filename | ||
|
||
|
||
# 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 | ||
|
@@ -159,6 +187,9 @@ def check_linker_need_libatomic(): | |
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++') | ||
|
||
CC_FILES = [os.path.normpath(cc_file) for cc_file in protoc_lib_deps.CC_FILES] | ||
PROTO_FILES = [ | ||
os.path.normpath(proto_file) for proto_file in protoc_lib_deps.PROTO_FILES | ||
|
@@ -245,22 +276,23 @@ def extension_modules(): | |
return extensions | ||
|
||
|
||
setuptools.setup( | ||
name='grpcio-tools', | ||
version=grpc_version.VERSION, | ||
description='Protobuf code generator for gRPC', | ||
long_description=open(_README_PATH, 'r').read(), | ||
author='The gRPC Authors', | ||
author_email='[email protected]', | ||
url='https://grpc.io', | ||
license='Apache License 2.0', | ||
classifiers=CLASSIFIERS, | ||
ext_modules=extension_modules(), | ||
packages=setuptools.find_packages('.'), | ||
install_requires=[ | ||
'protobuf>=3.5.0.post1, < 4.0dev', | ||
'grpcio>={version}'.format(version=grpc_version.VERSION), | ||
'setuptools', | ||
], | ||
package_data=package_data(), | ||
) | ||
setuptools.setup(name='grpcio-tools', | ||
version=grpc_version.VERSION, | ||
description='Protobuf code generator for gRPC', | ||
long_description=open(_README_PATH, 'r').read(), | ||
author='The gRPC Authors', | ||
author_email='[email protected]', | ||
url='https://grpc.io', | ||
license='Apache License 2.0', | ||
classifiers=CLASSIFIERS, | ||
ext_modules=extension_modules(), | ||
packages=setuptools.find_packages('.'), | ||
install_requires=[ | ||
'protobuf>=3.5.0.post1, < 4.0dev', | ||
'grpcio>={version}'.format(version=grpc_version.VERSION), | ||
'setuptools', | ||
], | ||
package_data=package_data(), | ||
cmdclass={ | ||
'build_ext': BuildExt, | ||
}) |
31 changes: 31 additions & 0 deletions
31
tools/dockerfile/grpc_artifact_python_manylinux2014_aarch64/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2020 The gRPC Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# The aarch64 wheels are being crosscompiled to allow running the build | ||
# on x64 machine. The dockcross/manylinux2014-aarch64 image is a x86_64 | ||
# image with crosscompilation toolchain installed. | ||
# Use an older version of dockcross image that has gcc4.9.4 because it was built | ||
# before https://github.com/dockcross/dockcross/pull/449 | ||
FROM dockcross/manylinux2014-aarch64:20200929-608e6ac | ||
|
||
# Update the package manager | ||
RUN yum update -y && yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel | ||
|
||
################################### | ||
# Install Python build requirements | ||
RUN /opt/python/cp35-cp35m/bin/pip install --upgrade cython | ||
RUN /opt/python/cp36-cp36m/bin/pip install --upgrade cython | ||
RUN /opt/python/cp37-cp37m/bin/pip install --upgrade cython | ||
RUN /opt/python/cp38-cp38/bin/pip install --upgrade cython | ||
RUN /opt/python/cp39-cp39/bin/pip install --upgrade cython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters