Skip to content

Commit 9d4e98d

Browse files
authored
Move logic for static cross-compile for linux-aarch64 to pom file (#906)
Motivation: Let's try to keep logic together to make it easier to keep track of changes Modifications: Move logic for cross compile to pom file. Result: Easier to maintain
1 parent 329c7b6 commit 9d4e98d

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

boringssl-static/pom.xml

+4-7
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@
711711
<jniClassifier>${os.detected.name}-aarch_64</jniClassifier>
712712
<jniArch>aarch_64</jniArch>
713713
<javaModuleNameClassifier>${os.detected.name}.aarch_64</javaModuleNameClassifier>
714+
<crossCompile>linux</crossCompile>
714715
</properties>
715716

716717
<build>
@@ -757,10 +758,6 @@
757758
</files>
758759
<content>release 7.6</content>
759760
</requireFilesContent>
760-
<requireProperty>
761-
<property>aprArmHome</property>
762-
<message>The folder of APR for aarch64 must be specified by hand. Please try -DaprArmHome=</message>
763-
</requireProperty>
764761
</rules>
765762
<ignoreCache>true</ignoreCache>
766763
</configuration>
@@ -1013,7 +1010,7 @@
10131010
<!-- <verbose>true</verbose> -->
10141011
<configureArgs>
10151012
<configureArg>--with-ssl=no</configureArg>
1016-
<configureArg>--with-apr=${aprArmHome}</configureArg>
1013+
<configureArg>--with-apr=${aprHome}</configureArg>
10171014
<configureArg>--with-static-libs</configureArg>
10181015
<configureArg>--libdir=${project.build.directory}/native-build/target/lib</configureArg>
10191016
<configureArg>CFLAGS=-O3 -Werror -fno-omit-frame-pointer -fvisibility=hidden -Wunused -Wno-unused-value</configureArg>
@@ -1207,7 +1204,7 @@
12071204

12081205
<properties>
12091206
<linkStatic>true</linkStatic>
1210-
<osxCrossCompile>true</osxCrossCompile>
1207+
<crossCompile>mac</crossCompile>
12111208
<target>arm64-apple-macos11</target>
12121209
<macOsxDeploymentTarget>OSX_DEPLOYMENT_TARGET=11.0</macOsxDeploymentTarget>
12131210
<cmakeOsxDeploymentTarget>-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0</cmakeOsxDeploymentTarget>
@@ -1455,7 +1452,7 @@
14551452

14561453
<properties>
14571454
<linkStatic>true</linkStatic>
1458-
<osxCrossCompile>true</osxCrossCompile>
1455+
<crossCompile>mac</crossCompile>
14591456
<target>x86_64-apple-macos10.12</target>
14601457
<macOsxDeploymentTarget>OSX_DEPLOYMENT_TARGET=10.12</macOsxDeploymentTarget>
14611458
<cmakeOsxDeploymentTarget>-DCMAKE_OSX_DEPLOYMENT_TARGET=10.12</cmakeOsxDeploymentTarget>

docker/Dockerfile.cross_compile_aarch64

-18
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,6 @@ RUN set -x && \
3636
mv gcc-arm-$GCC_VERSION-x86_64-aarch64-none-linux-gnu /
3737
ENV PATH="/gcc-arm-$GCC_VERSION-x86_64-aarch64-none-linux-gnu/bin:${PATH}"
3838

39-
# Copy over patch we need to apply to apr to not link against libcrypt
40-
COPY patches/apr_crypt.patch $SOURCE_DIR
41-
42-
# Cross compile Apache Apr for aarch64 - static
43-
RUN set -x && \
44-
wget --no-check-certificate https://downloads.apache.org//apr/apr-$APR_VERSION.tar.gz && \
45-
tar xvf apr-$APR_VERSION.tar.gz && \
46-
pushd apr-$APR_VERSION && \
47-
patch -p0 < $SOURCE_DIR/apr_crypt.patch && \
48-
./buildconf && \
49-
CC=aarch64-none-linux-gnu-gcc CFLAGS='-O3 -fno-omit-frame-pointer -fPIC ' ./configure --disable-shared --prefix=/opt/apr-$APR_VERSION-static --host=aarch64-none-linux-gnu ac_cv_have_decl_sys_siglist=no ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_tcp_nodelay_with_cork=yes ac_cv_sizeof_struct_iovec=8 && \
50-
make || true && \
51-
pushd tools && \
52-
gcc -Wall -O2 -DCROSS_COMPILE gen_test_char.c -s -o gen_test_char && \
53-
popd && \
54-
make && make install && \
55-
popd
56-
5739
# Cross compile Apache Apr for aarch64 - share
5840
RUN set -x && \
5941
wget --no-check-certificate https://downloads.apache.org//apr/apr-$APR_VERSION.tar.gz && \

docker/docker-compose.centos-7.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040

4141
cross-compile-aarch64-build:
4242
<<: *cross-compile-aarch64-common
43-
command: /bin/bash -cl "./mvnw clean package -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share -DskipTests && ./mvnw clean package -Plinux-aarch64 -am -pl boringssl-static -DaprArmHome=/opt/apr-$$APR_VERSION-static -DboringsslSourceDir=/root/workspace/boringssl-source -DboringsslHome=/root/workspace/boringssl -DskipTests"
43+
command: /bin/bash -cl "./mvnw clean package -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share -DskipTests && ./mvnw clean package -Plinux-aarch64 -am -pl boringssl-static -DskipTests"
4444

4545
cross-compile-aarch64-deploy:
4646
<<: *cross-compile-aarch64-common
@@ -50,7 +50,7 @@ services:
5050
- ~/.m2/repository:/root/.m2/repository
5151
- ~/.m2/settings.xml:/root/.m2/settings.xml
5252
- ..:/code
53-
command: /bin/bash -cl "./mvnw clean deploy -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share -DskipTests && ./mvnw clean deploy -Plinux-aarch64 -am -pl boringssl-static -DaprArmHome=/opt/apr-$$APR_VERSION-static -DboringsslSourceDir=/root/workspace/boringssl-source -DboringsslHome=/root/workspace/boringssl -DskipTests"
53+
command: /bin/bash -cl "./mvnw clean deploy -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share -DskipTests && ./mvnw clean deploy -Plinux-aarch64 -am -pl boringssl-static -DskipTests"
5454

5555
cross-compile-aarch64-stage-snapshot:
5656
<<: *cross-compile-aarch64-common
@@ -60,7 +60,7 @@ services:
6060
- ~/.m2/repository:/root/.m2/repository
6161
- ~/local-staging:/root/local-staging
6262
- ..:/code
63-
command: /bin/bash -cl "./mvnw -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share clean package org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true && ./mvnw -Plinux-aarch64 -am -pl boringssl-static -DaprArmHome=/opt/apr-$$APR_VERSION-static -DboringsslSourceDir=/root/workspace/boringssl-source -DboringsslHome=/root/workspace/boringssl clean package org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true"
63+
command: /bin/bash -cl "./mvnw -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share clean package org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true && ./mvnw -Plinux-aarch64 -am -pl boringssl-static clean package org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true"
6464

6565
cross-compile-aarch64-stage-release:
6666
<<: *cross-compile-aarch64-common
@@ -70,5 +70,5 @@ services:
7070
- ~/.m2/settings.xml:/root/.m2/settings.xml
7171
- ~/local-staging:/root/local-staging
7272
- ..:/code
73-
command: /bin/bash -cl "cat <(echo -e \"${GPG_PRIVATE_KEY}\") | gpg --batch --import && ./mvnw -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share clean javadoc:jar package gpg:sign org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DnexusUrl=https://oss.sonatype.org -DserverId=sonatype-nexus-staging -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true -Dgpg.passphrase=${GPG_PASSPHRASE} -Dgpg.keyname=${GPG_KEYNAME} && ./mvnw -Plinux-aarch64 -am -pl boringssl-static -DaprArmHome=/opt/apr-$$APR_VERSION-static -DboringsslSourceDir=/root/workspace/boringssl-source -DboringsslHome=/root/workspace/boringssl clean javadoc:jar package gpg:sign org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DnexusUrl=https://oss.sonatype.org -DserverId=sonatype-nexus-staging -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true -Dgpg.passphrase=${GPG_PASSPHRASE} -Dgpg.keyname=${GPG_KEYNAME}"
73+
command: /bin/bash -cl "cat <(echo -e \"${GPG_PRIVATE_KEY}\") | gpg --batch --import && ./mvnw -Plinux-aarch64 -am -pl openssl-dynamic -DaprArmHome=/opt/apr-$$APR_VERSION-share -DopensslArmHome=/opt/openssl-$$OPENSSL_VERSION-share clean javadoc:jar package gpg:sign org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DnexusUrl=https://oss.sonatype.org -DserverId=sonatype-nexus-staging -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true -Dgpg.passphrase=${GPG_PASSPHRASE} -Dgpg.keyname=${GPG_KEYNAME} && ./mvnw -Plinux-aarch64 -am -pl boringssl-static clean javadoc:jar package gpg:sign org.sonatype.plugins:nexus-staging-maven-plugin:deploy -DnexusUrl=https://oss.sonatype.org -DserverId=sonatype-nexus-staging -DaltStagingDirectory=/root/local-staging -DskipRemoteStaging=true -DskipTests=true -Dgpg.passphrase=${GPG_PASSPHRASE} -Dgpg.keyname=${GPG_KEYNAME}"
7474

pom.xml

+28-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<aprSourceDir>${project.build.directory}/apr-source</aprSourceDir>
104104
<archBits>64</archBits>
105105
<linkStatic>false</linkStatic>
106-
<osxCrossCompile>false</osxCrossCompile>
106+
<crossCompile>false</crossCompile>
107107
<sslHome>${project.build.directory}/ssl</sslHome>
108108
<msvcSslIncludeDirs>${sslHome}/include</msvcSslIncludeDirs>
109109
<msvcSslLibDirs>${sslHome}/lib</msvcSslLibDirs>
@@ -699,7 +699,7 @@
699699
<exec executable="buildconf" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true" />
700700

701701
<if>
702-
<equals arg1="${osxCrossCompile}" arg2="true" />
702+
<equals arg1="${crossCompile}" arg2="mac" />
703703
<then>
704704
<!--
705705
+ We need to set some extra variables as otherwise the configure of apr will fail when trying to cross-compile.
@@ -723,6 +723,32 @@
723723
<arg line="install" />
724724
</exec>
725725
</then>
726+
<elseif>
727+
<equals arg1="${crossCompile}" arg2="linux" />
728+
<then>
729+
<!--
730+
+ We need to set some extra variables as otherwise the configure of apr will fail when trying to cross-compile.
731+
+ See https://stackoverflow.com/a/1605497/1074097
732+
+ -->
733+
<exec executable="configure" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true">
734+
<arg line="--disable-shared --prefix=${aprHome} --host=aarch64-linux-gnu CC=aarch64-none-linux-gnu-gcc CFLAGS='-O3 -fno-omit-frame-pointer -fPIC' ac_cv_have_decl_sys_siglist=no ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_tcp_nodelay_with_cork=yes ac_cv_sizeof_struct_iovec=8" />
735+
</exec>
736+
<!--
737+
Make will fail when it tries to use the gen_test_char program.
738+
We work around this by compile gen_test_char separate, execute and than rerun make.
739+
See https://stackoverflow.com/a/56262330/1074097
740+
-->
741+
<exec executable="make" failonerror="false" dir="${aprSourceDir}" resolveexecutable="true" />
742+
<exec executable="gcc" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true">
743+
<arg line="-Wall -O2 -DCROSS_COMPILE tools/gen_test_char.c -o tools/gen_test_char" />
744+
</exec>
745+
<exec executable="tools/gen_test_char" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true" output="${aprSourceDir}/include/private/apr_escape_test_char.h" />
746+
<exec executable="make" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true" />
747+
<exec executable="make" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true">
748+
<arg line="install" />
749+
</exec>
750+
</then>
751+
</elseif>
726752
<else>
727753
<exec executable="configure" failonerror="true" dir="${aprSourceDir}" resolveexecutable="true">
728754
<!--

0 commit comments

Comments
 (0)