Skip to content

Commit 0ba5ae1

Browse files
liushengejona86
authored andcommitted
Add support for cross-compiling for aarch64 platform
This change modified the building scripts to support cross compile grpc-java for aarch64 platform For #6364
1 parent 2d59264 commit 0ba5ae1

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

buildscripts/build_artifacts_in_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ set -exu -o pipefail
33

44
# Runs all the tests and builds mvn artifacts.
55
# mvn artifacts are stored in grpc-java/mvn-artifacts/
6-
ALL_ARTIFACTS=true ARCH=64 "$(dirname $0)"/kokoro/unix.sh
6+
ALL_ARTIFACTS=true ARCH=x86_64 "$(dirname $0)"/kokoro/unix.sh
77
# Already ran tests the first time, so skip tests this time
8-
SKIP_TESTS=true ARCH=32 "$(dirname $0)"/kokoro/unix.sh
8+
SKIP_TESTS=true ARCH=x86_32 "$(dirname $0)"/kokoro/unix.sh

buildscripts/kokoro/linux_artifacts.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ popd
3333
readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}"
3434
mkdir -p "$MVN_ARTIFACT_DIR"
3535
cp -r "$LOCAL_MVN_TEMP"/* "$MVN_ARTIFACT_DIR"/
36+
37+
# for aarch64 platform
38+
sudo apt-get install -y g++-aarch64-linux-gnu
39+
SKIP_TESTS=true ARCH=aarch_64 "$GRPC_JAVA_DIR"/buildscripts/kokoro/unix.sh

buildscripts/kokoro/unix.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
# the correct environment for releases.
66
# To run locally:
77
# ./buildscripts/kokoro/unix.sh
8-
# For 32 bit:
9-
# ARCH=32 ./buildscripts/kokoro/unix.sh
8+
# For x86 32 arch:
9+
# ARCH=x86_32 ./buildscripts/kokoro/unix.sh
10+
# For aarch64 arch:
11+
# ARCH=aarch_64 ./buildscripts/kokoro/unix.sh
1012

1113
# This script assumes `set -e`. Removing it may lead to undefined behavior.
1214
set -exu -o pipefail
@@ -23,14 +25,14 @@ cd $(dirname $0)/../..
2325

2426
# TODO(zpencer): always make sure we are using Oracle jdk8
2527

26-
# ARCH is 64 bit unless otherwise specified.
27-
ARCH="${ARCH:-64}"
28+
# ARCH is x86_64 unless otherwise specified.
29+
ARCH="${ARCH:-x86_64}"
2830

2931
ARCH="$ARCH" buildscripts/make_dependencies.sh
3032

3133
# Set properties via flags, do not pollute gradle.properties
3234
GRADLE_FLAGS="${GRADLE_FLAGS:-}"
33-
GRADLE_FLAGS+=" -PtargetArch=x86_$ARCH"
35+
GRADLE_FLAGS+=" -PtargetArch=$ARCH"
3436
GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false"
3537
GRADLE_FLAGS+=" -PfailOnWarnings=true"
3638
GRADLE_FLAGS+=" -PerrorProne=true"
@@ -70,6 +72,11 @@ fi
7072
LOCAL_MVN_TEMP=$(mktemp -d)
7173
# Note that this disables parallel=true from GRADLE_FLAGS
7274
if [[ -z "${ALL_ARTIFACTS:-}" ]]; then
75+
if [[ $ARCH == "aarch_64" ]]; then
76+
GRADLE_FLAGS+=" -x grpc-compiler:generateTestProto -x grpc-compiler:generateTestLiteProto"
77+
GRADLE_FLAGS+=" -x grpc-compiler:testGolden -x grpc-compiler:testLiteGolden"
78+
GRADLE_FLAGS+=" -x grpc-compiler:testDeprecatedGolden -x grpc-compiler:testDeprecatedLiteGolden"
79+
fi
7380
./gradlew grpc-compiler:build grpc-compiler:publish $GRADLE_FLAGS \
7481
-Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP
7582
else

buildscripts/kokoro/upload_artifacts.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ LOCAL_MVN_ARTIFACTS="$KOKORO_GFILE_DIR"/github/grpc-java/mvn-artifacts/
2727
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-x86_64.exe' | wc -l)" != '0' ]]
2828
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-x86_32.exe' | wc -l)" != '0' ]]
2929

30+
# for linux aarch64 platform
31+
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-aarch_64.exe' | wc -l)" != '0' ]]
32+
3033
# from macos job:
3134
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-osx-x86_64.exe' | wc -l)" != '0' ]]
3235

buildscripts/make_dependencies.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ set -evux -o pipefail
55

66
PROTOBUF_VERSION=3.11.0
77

8-
# ARCH is 64 bit unless otherwise specified.
9-
ARCH="${ARCH:-64}"
8+
# ARCH is x86_64 bit unless otherwise specified.
9+
ARCH="${ARCH:-x86_64}"
1010
DOWNLOAD_DIR=/tmp/source
11-
INSTALL_DIR="/tmp/protobuf-cache/$PROTOBUF_VERSION/$(uname -s)-$(uname -p)-x86_$ARCH"
11+
INSTALL_DIR="/tmp/protobuf-cache/$PROTOBUF_VERSION/$(uname -s)-$ARCH"
1212
mkdir -p $DOWNLOAD_DIR
1313

1414
# Start with a sane default
@@ -31,8 +31,12 @@ else
3131
fi
3232
pushd $DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}
3333
# install here so we don't need sudo
34-
./configure CFLAGS=-m"$ARCH" CXXFLAGS=-m"$ARCH" --disable-shared \
35-
--prefix="$INSTALL_DIR"
34+
if [[ "$ARCH" == x86* ]]; then
35+
./configure CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} --disable-shared \
36+
--prefix="$INSTALL_DIR"
37+
elif [[ "$ARCH" == aarch* ]]; then
38+
./configure --disable-shared --host=aarch64-linux-gnu --prefix="$INSTALL_DIR"
39+
fi
3640
# the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
3741
make clean
3842
make V=0 -j$NUM_CPU

compiler/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ model {
5151
}
5252
gcc(Gcc) {
5353
target("ppcle_64")
54-
target("aarch_64")
54+
target("aarch_64") {
55+
cppCompiler.executable = 'aarch64-linux-gnu-g++'
56+
linker.executable = 'aarch64-linux-gnu-g++'
57+
}
5558
target("s390_64")
5659
}
5760
clang(Clang) {

compiler/check-artifact.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ checkArch ()
5959
assertEq "$format" "elf32-i386" $LINENO
6060
elif [[ "$ARCH" == x86_64 ]]; then
6161
assertEq "$format" "elf64-x86-64" $LINENO
62+
elif [[ "$ARCH" == aarch_64 ]]; then
63+
assertEq "$format" "elf64-little" $LINENO
6264
else
6365
fail "Unsupported arch: $ARCH"
6466
fi
@@ -103,6 +105,9 @@ checkDependencies ()
103105
white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2"
104106
elif [[ "$ARCH" == x86_64 ]]; then
105107
white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2"
108+
elif [[ "$ARCH" == aarch_64 ]]; then
109+
dump_cmd='aarch64-linux-gnu-objdump -x '"$1"' |grep "NEEDED"'
110+
white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-aarch64\.so\.1"
106111
fi
107112
elif [[ "$OS" == osx ]]; then
108113
dump_cmd='otool -L '"$1"' | fgrep dylib'

0 commit comments

Comments
 (0)