1#!/bin/bash 2# 3# Builds protobuf python including the C++ extension with aarch64 crosscompiler. 4# The outputs of this script are laid out so that we can later test them under an aarch64 emulator. 5# NOTE: This script is expected to run under the dockcross/manylinux2014-aarch64 docker image. 6 7set -ex 8 9PYTHON="/opt/python/cp38-cp38/bin/python" 10 11./autogen.sh 12CXXFLAGS="-fPIC -g -O2" ./configure --host=aarch64 13make -j8 14 15# create a simple shell wrapper that runs crosscompiled protoc under qemu 16echo '#!/bin/bash' >protoc_qemu_wrapper.sh 17echo 'exec qemu-aarch64 "../src/protoc" "$@"' >>protoc_qemu_wrapper.sh 18chmod ugo+x protoc_qemu_wrapper.sh 19 20# PROTOC variable is by build_py step that runs under ./python directory 21export PROTOC=../protoc_qemu_wrapper.sh 22 23pushd python 24 25# NOTE: this step will use protoc_qemu_wrapper.sh to generate protobuf files. 26${PYTHON} setup.py build_py 27 28# when crosscompiling for aarch64, --plat-name needs to be set explicitly 29# to end up with correctly named wheel file 30# the value should be manylinuxABC_ARCH and dockcross docker image 31# conveniently provides the value in the AUDITWHEEL_PLAT env 32plat_name_flag="--plat-name=$AUDITWHEEL_PLAT" 33 34# override the value of EXT_SUFFIX to make sure the crosscompiled .so files in the wheel have the correct filename suffix 35export PROTOCOL_BUFFERS_OVERRIDE_EXT_SUFFIX="$(${PYTHON} -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX").replace("-x86_64-linux-gnu.so", "-aarch64-linux-gnu.so"))')" 36 37# Build the python extension inplace to be able to python unittests later 38${PYTHON} setup.py build_ext --cpp_implementation --compile_static_extension --inplace 39 40# Build the binary wheel (to check it with auditwheel) 41${PYTHON} setup.py bdist_wheel --cpp_implementation --compile_static_extension $plat_name_flag 42