Skip to content

Commit 99cbdd5

Browse files
haubenrejona86
andauthored
Add support for cross-compiling for s390x platform (#9455)
* Added s390x platform support * Adapt to existing platform naming scheme * Updated s390_64 library whitelist * Use g++ compiler version 8.x for s390x * Introduced dedicated Docker container for building s390x artifacts Minor fix --------- Signed-off-by: Dirk Haubenreisser <[email protected]> Co-authored-by: Eric Anderson <[email protected]>
1 parent 39c9ebf commit 99cbdd5

File tree

10 files changed

+57
-5
lines changed

10 files changed

+57
-5
lines changed

buildscripts/build_docker.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
set -eu -o pipefail
33

44
readonly buildscripts_dir="$(dirname "$(readlink -f "$0")")"
5-
docker build -t grpc-java-artifacts "$buildscripts_dir"/grpc-java-artifacts
5+
docker build -t grpc-java-artifacts-x86 "$buildscripts_dir"/grpc-java-artifacts
6+
docker build -t grpc-java-artifacts-multiarch -f "$buildscripts_dir"/grpc-java-artifacts/Dockerfile.multiarch.base "$buildscripts_dir"/grpc-java-artifacts
7+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -exu -o pipefail
3+
4+
# first we need to install the prerequisites required for s390x cross compilation
5+
apt-get update && apt-get install -y g++-s390x-linux-gnu
6+
7+
# now kick off the build for the mvn artifacts for s390x
8+
# mvn artifacts are stored in grpc-java/mvn-artifacts/
9+
SKIP_TESTS=true ARCH=s390_64 "$(dirname $0)"/kokoro/unix.sh
10+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:22.04
2+
3+
# make sure apt-get works in unattended mode
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# install the OS-level prerequisites for building protobuf and running the gradle build
7+
RUN apt-get update && \
8+
apt-get upgrade -y && \
9+
apt-get install -y --no-install-recommends ca-certificates build-essential wget curl openjdk-8-jdk && \
10+
apt-get autoclean -y && \
11+
apt-get autoremove -y && \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
15+

buildscripts/kokoro/linux_artifacts.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)"
1111
trap spongify_logs EXIT
1212

1313
"$GRPC_JAVA_DIR"/buildscripts/build_docker.sh
14-
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh /grpc-java/buildscripts/build_artifacts_in_docker.sh
14+
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-x86 /grpc-java/buildscripts/build_artifacts_in_docker.sh
1515

1616
# grpc-android, grpc-cronet and grpc-binder require the Android SDK, so build outside of Docker and
1717
# use --include-build for its grpc-core dependency
@@ -59,3 +59,9 @@ SKIP_TESTS=true ARCH=aarch_64 "$GRPC_JAVA_DIR"/buildscripts/kokoro/unix.sh
5959
# for ppc64le platform
6060
sudo apt-get install -y g++-powerpc64le-linux-gnu
6161
SKIP_TESTS=true ARCH=ppcle_64 "$GRPC_JAVA_DIR"/buildscripts/kokoro/unix.sh
62+
63+
# for s390x platform
64+
# building these artifacts inside a Docker container as we have specific requirements
65+
# for GCC (version 11.x needed) which in turn requires Ubuntu 22.04 LTS
66+
"$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-multiarch /grpc-java/buildscripts/build_s390x_artifacts_in_docker.sh
67+

buildscripts/kokoro/unix.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# ARCH=aarch_64 ./buildscripts/kokoro/unix.sh
1212
# For ppc64le arch:
1313
# ARCH=ppcle_64 ./buildscripts/kokoro/unix.sh
14+
# For s390x arch:
15+
# ARCH=s390_64 ./buildscripts/kokoro/unix.sh
1416

1517
# This script assumes `set -e`. Removing it may lead to undefined behavior.
1618
set -exu -o pipefail
@@ -80,7 +82,7 @@ fi
8082
LOCAL_MVN_TEMP=$(mktemp -d)
8183
# Note that this disables parallel=true from GRADLE_FLAGS
8284
if [[ -z "${ALL_ARTIFACTS:-}" ]]; then
83-
if [[ "$ARCH" = "aarch_64" || "$ARCH" = "ppcle_64" ]]; then
85+
if [[ "$ARCH" = "aarch_64" || "$ARCH" = "ppcle_64" || "$ARCH" = "s390_64" ]]; then
8486
GRADLE_FLAGS+=" -x grpc-compiler:generateTestProto -x grpc-compiler:generateTestLiteProto"
8587
GRADLE_FLAGS+=" -x grpc-compiler:testGolden -x grpc-compiler:testLiteGolden"
8688
GRADLE_FLAGS+=" -x grpc-compiler:testDeprecatedGolden -x grpc-compiler:testDeprecatedLiteGolden"

buildscripts/kokoro/upload_artifacts.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ LOCAL_OTHER_ARTIFACTS="$KOKORO_GFILE_DIR"/github/grpc-java/artifacts/
3737
# for linux ppc64le platform
3838
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-ppcle_64.exe' | wc -l)" != '0' ]]
3939

40+
# for linux s390x platform
41+
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-linux-s390_64.exe' | wc -l)" != '0' ]]
42+
4043
# from macos job:
4144
[[ "$(find "$LOCAL_MVN_ARTIFACTS" -type f -iname 'protoc-gen-grpc-java-*-osx-x86_64.exe' | wc -l)" != '0' ]]
4245
# copy all x86 artifacts to aarch until native artifacts are built

buildscripts/make_dependencies.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ else
3838
./configure --disable-shared --host=aarch64-linux-gnu --prefix="$INSTALL_DIR"
3939
elif [[ "$ARCH" == ppc* ]]; then
4040
./configure --disable-shared --host=powerpc64le-linux-gnu --prefix="$INSTALL_DIR"
41+
elif [[ "$ARCH" == s390* ]]; then
42+
./configure --disable-shared --host=s390x-linux-gnu --prefix="$INSTALL_DIR"
4143
elif [[ "$ARCH" == loongarch* ]]; then
4244
./configure --disable-shared --host=loongarch64-unknown-linux-gnu --prefix="$INSTALL_DIR"
4345
fi

buildscripts/run_in_docker.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ quote() {
1010
done
1111
}
1212

13+
readonly docker_image=$1; shift
14+
1315
readonly grpc_java_dir="$(dirname "$(readlink -f "$0")")/.."
1416
if [[ -t 0 ]]; then
1517
DOCKER_ARGS="-it"
@@ -21,5 +23,5 @@ fi
2123
# the original exit code. $DOCKER_ARGS can not be quoted, otherwise it becomes a '' which confuses
2224
# docker.
2325
exec docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \
24-
grpc-java-artifacts \
26+
$docker_image \
2527
bash -c "function fixFiles() { chown -R $(id -u):$(id -g) /grpc-java; }; trap fixFiles EXIT; $(quote "$@")"

compiler/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ model {
5858
cppCompiler.executable = 'aarch64-linux-gnu-g++'
5959
linker.executable = 'aarch64-linux-gnu-g++'
6060
}
61-
target("s390_64")
61+
target("s390_64") {
62+
cppCompiler.executable = 's390x-linux-gnu-g++'
63+
linker.executable = 's390x-linux-gnu-g++'
64+
}
6265
target("loongarch_64")
6366
}
6467
clang(Clang) {

compiler/check-artifact.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ checkArch ()
6868
format="$(powerpc64le-linux-gnu-objdump -f "$1" | grep -o "file format .*$" | grep -o "[^ ]*$")"
6969
echo Format=$format
7070
assertEq "$format" "elf64-powerpcle" $LINENO
71+
elif [[ "$ARCH" == s390_64 ]]; then
72+
format="$(s390x-linux-gnu-objdump -f "$1" | grep -o "file format .*$" | grep -o "[^ ]*$")"
73+
echo Format=$format
74+
assertEq "$format" "elf64-s390" $LINENO
7175
else
7276
fail "Unsupported arch: $ARCH"
7377
fi
@@ -121,6 +125,9 @@ checkDependencies ()
121125
elif [[ "$ARCH" == ppcle_64 ]]; then
122126
dump_cmd='powerpc64le-linux-gnu-objdump -x '"$1"' |grep "NEEDED"'
123127
white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld64\.so\.2"
128+
elif [[ "$ARCH" == s390_64 ]]; then
129+
dump_cmd='s390x-linux-gnu-objdump -x '"$1"' |grep "NEEDED"'
130+
white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld64\.so\.1"
124131
fi
125132
elif [[ "$OS" == osx ]]; then
126133
dump_cmd='otool -L '"$1"' | fgrep dylib'

0 commit comments

Comments
 (0)