config.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Define custom utilities
  2. # Test for OSX with [ -n "$IS_OSX" ]
  3. function pre_build {
  4. # Any stuff that you need to do before you start building the wheels
  5. # Runs in the root directory of this repository.
  6. pushd protobuf
  7. if [ "$PLAT" == "aarch64" ]
  8. then
  9. local configure_host_flag="--host=aarch64"
  10. fi
  11. # Build protoc and libprotobuf
  12. ./autogen.sh
  13. CXXFLAGS="-fPIC -g -O2" ./configure $configure_host_flag
  14. make -j8
  15. if [ "$PLAT" == "aarch64" ]
  16. then
  17. # we are crosscompiling for aarch64 while running on x64
  18. # the simplest way for build_py command to be able to generate
  19. # the protos is by running the protoc process under
  20. # an emulator. That way we don't have to build a x64 version
  21. # of protoc. The qemu-arm emulator is already included
  22. # in the dockcross docker image.
  23. # Running protoc under an emulator is fast as protoc doesn't
  24. # really do much.
  25. # create a simple shell wrapper that runs crosscompiled protoc under qemu
  26. echo '#!/bin/bash' >protoc_qemu_wrapper.sh
  27. echo 'exec qemu-aarch64 "../src/protoc" "$@"' >>protoc_qemu_wrapper.sh
  28. chmod ugo+x protoc_qemu_wrapper.sh
  29. # PROTOC variable is by build_py step that runs under ./python directory
  30. export PROTOC=../protoc_qemu_wrapper.sh
  31. fi
  32. # Generate python dependencies.
  33. pushd python
  34. python setup.py build_py
  35. popd
  36. popd
  37. }
  38. function bdist_wheel_cmd {
  39. # Builds wheel with bdist_wheel, puts into wheelhouse
  40. #
  41. # It may sometimes be useful to use bdist_wheel for the wheel building
  42. # process. For example, versioneer has problems with versions which are
  43. # fixed with bdist_wheel:
  44. # https://github.com/warner/python-versioneer/issues/121
  45. local abs_wheelhouse=$1
  46. # Modify build version
  47. pwd
  48. ls
  49. if [ "$PLAT" == "aarch64" ]
  50. then
  51. # when crosscompiling for aarch64, --plat-name needs to be set explicitly
  52. # to end up with correctly named wheel file
  53. # the value should be manylinuxABC_ARCH and dockcross docker image
  54. # conveniently provides the value in the AUDITWHEEL_PLAT env
  55. local plat_name_flag="--plat-name=$AUDITWHEEL_PLAT"
  56. # override the value of EXT_SUFFIX to make sure the crosscompiled .so files in the wheel have the correct filename suffix
  57. 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"))')"
  58. fi
  59. python setup.py bdist_wheel --cpp_implementation --compile_static_extension $plat_name_flag
  60. cp dist/*.whl $abs_wheelhouse
  61. }
  62. function build_wheel {
  63. build_wheel_cmd "bdist_wheel_cmd" $@
  64. }
  65. function run_tests {
  66. # Runs tests on installed distribution from an empty directory
  67. python --version
  68. python -c "from google.protobuf.pyext import _message;"
  69. }
  70. if [ "$PLAT" == "aarch64" ]
  71. then
  72. # when crosscompiling for aarch64, override the default multibuild's repair_wheelhouse logic
  73. # since "auditwheel repair" doesn't work for crosscompiled wheels
  74. function repair_wheelhouse {
  75. echo "Skipping repair_wheelhouse since auditwheel requires build architecture to match wheel architecture."
  76. }
  77. fi