New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crosscompile python aarch64 wheels with dockcross #25418
Changes from all commits
2820f85
60db2a4
9ccb8e0
ed8f029
5849d85
fdd3bee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a x64 cython, but that doesn't really matter it seems. Even the python itself is a x64 python. That seems correct as we're crosscompiling and we need to run the build on a x64 machine (and cython is what invokes the build commands). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,33 @@ export GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS=${GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS | |
mkdir -p "${ARTIFACTS_OUT}" | ||
ARTIFACT_DIR="$PWD/${ARTIFACTS_OUT}" | ||
|
||
# check whether we are crosscompiling. AUDITWHEEL_ARCH is set by the dockcross docker image. | ||
if [ "$AUDITWHEEL_ARCH" == "aarch64" ] | ||
then | ||
# when crosscompiling for aarch64, --plat-name needs to be set explicitly | ||
# to end up with correctly named wheel file | ||
# the value should be manylinuxABC_ARCH and dockcross docker image | ||
# conveniently provides the value in the AUDITWHEEL_PLAT env | ||
WHEEL_PLAT_NAME_FLAG="--plat-name=$AUDITWHEEL_PLAT" | ||
|
||
# override the value of EXT_SUFFIX to make sure the crosscompiled .so files in the wheel have the correct filename suffix | ||
GRPC_PYTHON_OVERRIDE_EXT_SUFFIX="$(${PYTHON} -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX").replace("-x86_64-linux-gnu.so", "-aarch64-linux-gnu.so"))')" | ||
export GRPC_PYTHON_OVERRIDE_EXT_SUFFIX | ||
|
||
# Set to empty string to disable the option (see https://github.com/grpc/grpc/issues/24498) | ||
# TODO: enable ASM optimizations for crosscompiled wheels | ||
export GRPC_BUILD_WITH_BORING_SSL_ASM="" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe link to the PR changing the BoringSSL ASM enable flag? #25444 |
||
fi | ||
|
||
# Build the source distribution first because MANIFEST.in cannot override | ||
# exclusion of built shared objects among package resources (for some | ||
# inexplicable reason). | ||
${SETARCH_CMD} "${PYTHON}" setup.py sdist | ||
|
||
# Wheel has a bug where directories don't get excluded. | ||
# https://bitbucket.org/pypa/wheel/issues/99/cannot-exclude-directory | ||
${SETARCH_CMD} "${PYTHON}" setup.py bdist_wheel | ||
# shellcheck disable=SC2086 | ||
${SETARCH_CMD} "${PYTHON}" setup.py bdist_wheel $WHEEL_PLAT_NAME_FLAG | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote (SC2086) seems applicable to this shell command. Quoting variables should fix the shellcheck complain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That wouldn't work. WHEEL_PLAT_NAME_FLAG can be empty and in that case |
||
|
||
GRPCIO_STRIP_TEMPDIR=$(mktemp -d) | ||
GRPCIO_TAR_GZ_LIST=( dist/grpcio-*.tar.gz ) | ||
|
@@ -78,9 +97,10 @@ mv "${GRPCIO_STRIPPED_TAR_GZ}" "${GRPCIO_TAR_GZ}" | |
${SETARCH_CMD} "${PYTHON}" tools/distrib/python/grpcio_tools/setup.py sdist | ||
|
||
# Build gRPC tools package binary distribution | ||
${SETARCH_CMD} "${PYTHON}" tools/distrib/python/grpcio_tools/setup.py bdist_wheel | ||
# shellcheck disable=SC2086 | ||
${SETARCH_CMD} "${PYTHON}" tools/distrib/python/grpcio_tools/setup.py bdist_wheel $WHEEL_PLAT_NAME_FLAG | ||
|
||
if [ "$GRPC_BUILD_MANYLINUX_WHEEL" != "" ] | ||
if [ "$GRPC_RUN_AUDITWHEEL_REPAIR" != "" ] | ||
then | ||
for wheel in dist/*.whl; do | ||
"${AUDITWHEEL}" show "$wheel" | tee /dev/stderr | grep -E -w "$AUDITWHEEL_PLAT" | ||
|
@@ -136,12 +156,15 @@ then | |
cp -r src/python/grpcio_status/dist/* "$ARTIFACT_DIR" | ||
fi | ||
|
||
# Ensure the generated artifacts are valid. | ||
"${PYTHON}" -m pip install virtualenv | ||
"${PYTHON}" -m virtualenv venv || { "${PYTHON}" -m pip install virtualenv==16.7.9 && "${PYTHON}" -m virtualenv venv; } | ||
venv/bin/python -m pip install "twine<=2.0" | ||
venv/bin/python -m twine check dist/* tools/distrib/python/grpcio_tools/dist/* | ||
rm -rf venv/ | ||
if [ "$GRPC_SKIP_TWINE_CHECK" == "" ] | ||
then | ||
# Ensure the generated artifacts are valid. | ||
"${PYTHON}" -m pip install virtualenv | ||
"${PYTHON}" -m virtualenv venv || { "${PYTHON}" -m pip install virtualenv==16.7.9 && "${PYTHON}" -m virtualenv venv; } | ||
venv/bin/python -m pip install "twine<=2.0" | ||
venv/bin/python -m twine check dist/* tools/distrib/python/grpcio_tools/dist/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for skipping twine checks? We are following manylinux2014, should be supported by PyPI official packages? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to skip auditwheel and twine check for now, since when crosscompiling we're running on x64 image, but we got aarch64 wheel. To perform checks, you'd likely need to run the check under qemu (available in the docker image), but also on aarch64 version of python etc. |
||
rm -rf venv/ | ||
fi | ||
|
||
cp -r dist/* "$ARTIFACT_DIR" | ||
cp -r tools/distrib/python/grpcio_tools/dist/* "$ARTIFACT_DIR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these installing the aarch64 dev libs? When I tried it, it pulled in the x86 version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, this is installing x86 libs. I guess the reason why this doesn't matter is that they are actually not strictly required for a successful build (I copied the line from x64 dockerfile and didn't investigate whether they are really needed).