python_crosscompile_aarch64.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. set -ex
  7. PYTHON="/opt/python/cp38-cp38/bin/python"
  8. ./autogen.sh
  9. CXXFLAGS="-fPIC -g -O2" ./configure --host=aarch64
  10. make -j8
  11. # create a simple shell wrapper that runs crosscompiled protoc under qemu
  12. echo '#!/bin/bash' >protoc_qemu_wrapper.sh
  13. echo 'exec qemu-aarch64 "../src/protoc" "$@"' >>protoc_qemu_wrapper.sh
  14. chmod ugo+x protoc_qemu_wrapper.sh
  15. # PROTOC variable is by build_py step that runs under ./python directory
  16. export PROTOC=../protoc_qemu_wrapper.sh
  17. pushd python
  18. # NOTE: this step will use protoc_qemu_wrapper.sh to generate protobuf files.
  19. ${PYTHON} setup.py build_py
  20. # when crosscompiling for aarch64, --plat-name needs to be set explicitly
  21. # to end up with correctly named wheel file
  22. # the value should be manylinuxABC_ARCH and dockcross docker image
  23. # conveniently provides the value in the AUDITWHEEL_PLAT env
  24. plat_name_flag="--plat-name=$AUDITWHEEL_PLAT"
  25. # override the value of EXT_SUFFIX to make sure the crosscompiled .so files in the wheel have the correct filename suffix
  26. export 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"))')"
  27. # Build the python extension inplace to be able to python unittests later
  28. ${PYTHON} setup.py build_ext --cpp_implementation --compile_static_extension --inplace
  29. # Build the binary wheel (to check it with auditwheel)
  30. ${PYTHON} setup.py bdist_wheel --cpp_implementation --compile_static_extension $plat_name_flag