@@ -6,15 +6,38 @@ function pre_build {
6
6
# Runs in the root directory of this repository.
7
7
pushd protobuf
8
8
9
- yum install -y devtoolset-2-libatomic-devel
9
+ if [ " $PLAT " == " aarch64" ]
10
+ then
11
+ local configure_host_flag=" --host=aarch64"
12
+ else
13
+ yum install -y devtoolset-2-libatomic-devel
14
+ fi
10
15
11
- # Build protoc
16
+ # Build protoc and libprotobuf
12
17
./autogen.sh
13
- ./configure
14
-
15
- CXXFLAGS=" -fPIC -g -O2" ./configure
18
+ CXXFLAGS=" -fPIC -g -O2" ./configure $configure_host_flag
16
19
make -j8
17
20
21
+ if [ " $PLAT " == " aarch64" ]
22
+ then
23
+ # we are crosscompiling for aarch64 while running on x64
24
+ # the simplest way for build_py command to be able to generate
25
+ # the protos is by running the protoc process under
26
+ # an emulator. That way we don't have to build a x64 version
27
+ # of protoc. The qemu-arm emulator is already included
28
+ # in the dockcross docker image.
29
+ # Running protoc under an emulator is fast as protoc doesn't
30
+ # really do much.
31
+
32
+ # create a simple shell wrapper that runs crosscompiled protoc under qemu
33
+ echo ' #!/bin/bash' > protoc_qemu_wrapper.sh
34
+ echo ' exec qemu-aarch64 "../src/protoc" "$@"' >> protoc_qemu_wrapper.sh
35
+ chmod ugo+x protoc_qemu_wrapper.sh
36
+
37
+ # PROTOC variable is by build_py step that runs under ./python directory
38
+ export PROTOC=../protoc_qemu_wrapper.sh
39
+ fi
40
+
18
41
# Generate python dependencies.
19
42
pushd python
20
43
python setup.py build_py
@@ -35,7 +58,20 @@ function bdist_wheel_cmd {
35
58
# Modify build version
36
59
pwd
37
60
ls
38
- python setup.py bdist_wheel --cpp_implementation --compile_static_extension
61
+
62
+ if [ " $PLAT " == " aarch64" ]
63
+ then
64
+ # when crosscompiling for aarch64, --plat-name needs to be set explicitly
65
+ # to end up with correctly named wheel file
66
+ # the value should be manylinuxABC_ARCH and dockcross docker image
67
+ # conveniently provides the value in the AUDITWHEEL_PLAT env
68
+ local plat_name_flag=" --plat-name=$AUDITWHEEL_PLAT "
69
+
70
+ # override the value of EXT_SUFFIX to make sure the crosscompiled .so files in the wheel have the correct filename suffix
71
+ 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"))' ) "
72
+ fi
73
+
74
+ python setup.py bdist_wheel --cpp_implementation --compile_static_extension $plat_name_flag
39
75
cp dist/* .whl $abs_wheelhouse
40
76
}
41
77
@@ -48,3 +84,12 @@ function run_tests {
48
84
python --version
49
85
python -c " from google.protobuf.pyext import _message;"
50
86
}
87
+
88
+ if [ " $PLAT " == " aarch64" ]
89
+ then
90
+ # when crosscompiling for aarch64, override the default multibuild's repair_wheelhouse logic
91
+ # since "auditwheel repair" doesn't work for crosscompiled wheels
92
+ function repair_wheelhouse {
93
+ echo " Skipping repair_wheelhouse since auditwheel requires build architecture to match wheel architecture."
94
+ }
95
+ fi
0 commit comments