config.sh 3.2 KB

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