-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathbuild-jni-lib.sh
executable file
·51 lines (41 loc) · 2.33 KB
/
build-jni-lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
set -euo pipefail
SRC_DIR=$(dirname "$0")
DST_DIR=${1}
MULTI_ARCH=${2}
CURL_VERSION=7.83.0
# Not using associative arrays to maintain bash 3 compatibility with building on MacOS
# MacOS ships with bash 3 and associative arrays require bash 4+
# Declaring a map as an array with the column character as a separator :
declare -a ARCHITECTURES_TO_PLATFORM=(
"x86_64:linux/amd64"
"aarch64:linux/arm64/v8"
)
declare -a TARGETS=("glibc" "musl")
for pair in "${ARCHITECTURES_TO_PLATFORM[@]}"; do
arch=${pair%%:*}
platform=${pair#*:}
if [[ "${MULTI_ARCH}" != "true" ]] && [[ "$(arch)" != "${arch}" ]]; then
echo "multi arch build not requested and host arch is $(arch), so skipping ${arch}:${platform} ..."
continue
fi
mkdir -p "${DST_DIR}/classes/${arch}"
for target in "${TARGETS[@]}"; do
echo "Compiling the native library for target ${target} on architecture ${arch} using Docker platform ${platform}"
artifact="${DST_DIR}/classes/${arch}/aws-lambda-runtime-interface-client.${target}.so"
if [[ "${MULTI_ARCH}" == "true" ]]; then
docker build --platform="${platform}" -f "${SRC_DIR}/Dockerfile.${target}" --build-arg CURL_VERSION=${CURL_VERSION} "${SRC_DIR}" -o - | tar -xOf - src/aws-lambda-runtime-interface-client.so > "${artifact}"
else
echo "multi-arch not requestsed, assuming this is a workaround to goofyness when docker buildx is enabled on Linux CI environments."
echo "enabling docker buildx often updates the docker api version, so assuming that docker cli is also too old to use --output type=tar, so doing alternative build-tag-run approach"
docker build --platform="${platform}" -t "lambda-java-jni-lib-${target}-${arch}" -f "${SRC_DIR}/Dockerfile.${target}" --build-arg CURL_VERSION=${CURL_VERSION} "${SRC_DIR}"
docker run --rm --entrypoint /bin/cat "lambda-java-jni-lib-${target}-${arch}" /src/aws-lambda-runtime-interface-client.so > "${artifact}"
fi
[ -f "${artifact}" ]
if ! file -b "${artifact}" | tr '-' '_' | tee /dev/stderr | grep -q "${arch}"; then
echo "${artifact} did not appear to be the correct architecture, check that Docker buildx is enabled"
exit 1
fi
done
done