From a498b0016598ed34b2c957bf11830a52f6ab3931 Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Wed, 22 Dec 2021 13:34:07 -0500 Subject: [PATCH] 17417: add arm64 support for our golang packages, functional for Debian 11 as of this commit. Arvados-DCO-1.1-Signed-off-by: Ward Vandewege --- .../debian11/Dockerfile | 6 +++++ build/run-build-packages-one-target.sh | 9 +++++++- build/run-build-packages.sh | 7 +++++- build/run-library.sh | 22 ++++++++++++------- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/build/package-build-dockerfiles/debian11/Dockerfile b/build/package-build-dockerfiles/debian11/Dockerfile index 06380ef896..924c916845 100644 --- a/build/package-build-dockerfiles/debian11/Dockerfile +++ b/build/package-build-dockerfiles/debian11/Dockerfile @@ -30,6 +30,12 @@ RUN gpg --import --no-tty /tmp/mpapis.asc && \ ADD generated/go1.17.1.linux-amd64.tar.gz /usr/local/ RUN ln -s /usr/local/go/bin/go /usr/local/bin/ +# Add gcc-aarch64-linux-gnu to compile go binaries for arm64 +RUN /usr/bin/apt-get install -q -y gcc-aarch64-linux-gnu +# We also need libpam compiled for arm64 +RUN /usr/bin/dpkg --add-architecture arm64 +RUN /usr/bin/apt-get update && /usr/bin/apt-get install -o APT::Immediate-Configure=0 -q -y libpam0g-dev:arm64 + # Install nodejs and npm ADD generated/node-v10.23.1-linux-x64.tar.xz /usr/local/ RUN ln -s /usr/local/node-v10.23.1-linux-x64/bin/* /usr/local/bin/ diff --git a/build/run-build-packages-one-target.sh b/build/run-build-packages-one-target.sh index 7a91cb4de1..d52de98a93 100755 --- a/build/run-build-packages-one-target.sh +++ b/build/run-build-packages-one-target.sh @@ -21,6 +21,8 @@ Syntax: Build only a specific package --only-test Test only a specific package +--only-arch + Build only a specific architecture (amd64 or arm64) --force-build Build even if the package exists upstream or if it has already been built locally @@ -54,13 +56,14 @@ if ! [[ -d "$WORKSPACE" ]]; then fi PARSEDOPTS=$(getopt --name "$0" --longoptions \ - help,debug,test-packages,target:,command:,only-test:,force-test,only-build:,force-build,build-version: \ + help,debug,test-packages,target:,command:,only-test:,force-test,only-build:,force-build,only-arch:,build-version: \ -- "" "$@") if [ $? -ne 0 ]; then exit 1 fi TARGET=debian10 +ONLY_ARCH= FORCE_BUILD=0 COMMAND= DEBUG= @@ -90,6 +93,9 @@ while [ $# -gt 0 ]; do --only-build) ONLY_BUILD="$2"; shift ;; + --only-arch) + ONLY_ARCH="$2"; shift + ;; --debug) DEBUG=" --debug" ARVADOS_DEBUG="1" @@ -311,6 +317,7 @@ else --env ARVADOS_DEBUG=$ARVADOS_DEBUG \ --env "ONLY_BUILD=$ONLY_BUILD" \ --env "FORCE_BUILD=$FORCE_BUILD" \ + --env "ONLY_ARCH=$ONLY_ARCH" \ "$IMAGE" $COMMAND then echo diff --git a/build/run-build-packages.sh b/build/run-build-packages.sh index 26ed168aa6..5fe176a182 100755 --- a/build/run-build-packages.sh +++ b/build/run-build-packages.sh @@ -22,6 +22,8 @@ Options: Distribution to build packages for (default: debian10) --only-build Build only a specific package (or $ONLY_BUILD from environment) +--only-arch + Build only a specific architecture (or $ONLY_ARCH from environment) --force-build Build even if the package exists upstream or if it has already been built locally @@ -50,7 +52,7 @@ TARGET=debian10 COMMAND= PARSEDOPTS=$(getopt --name "$0" --longoptions \ - help,build-bundle-packages,debug,target:,only-build:,force-build \ + help,build-bundle-packages,debug,target:,only-build:,only-arch:,force-build \ -- "" "$@") if [ $? -ne 0 ]; then exit 1 @@ -73,6 +75,9 @@ while [ $# -gt 0 ]; do --force-build) FORCE_BUILD=1 ;; + --only-arch) + ONLY_ARCH="$2"; shift + ;; --debug) DEBUG=1 ;; diff --git a/build/run-library.sh b/build/run-library.sh index ebc1f9e59f..686c2b6782 100755 --- a/build/run-library.sh +++ b/build/run-library.sh @@ -137,9 +137,13 @@ package_go_binary() { local description="$1"; shift local license_file="${1:-agpl-3.0.txt}"; shift - for arch in 'amd64' 'arm64'; do - package_go_binary_worker "$src_path" "$prog" "$description" "$arch" "$license_file" - done + if [[ -n "$ONLY_ARCH" ]]; then + package_go_binary_worker "$src_path" "$prog" "$description" "$ONLY_ARCH" "$license_file" + else + for arch in 'amd64' 'arm64'; do + package_go_binary_worker "$src_path" "$prog" "$description" "$arch" "$license_file" + done + fi } # Usage: package_go_binary services/foo arvados-foo "Compute foo to arbitrary precision" [amd64/arm64] [apache-2.0.txt] @@ -159,19 +163,21 @@ package_go_binary_worker() { fi debug_echo "package_go_binary $src_path as $prog" - local basename="${src_path##*/}" calculate_go_package_version go_package_version $src_path cd $WORKSPACE/packages/$TARGET - test_package_presence $prog $go_package_version go - + test_package_presence "$prog" "$go_package_version" "go" "" "$arch" if [[ "$?" != "0" ]]; then return 1 fi echo "BUILDING ${arch}" - GOARCH=${arch} go get -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path" + if [[ "$arch" == "arm64" ]]; then + CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOARCH=${arch} go get -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path" + else + GOARCH=${arch} go get -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path" + fi local -a switches=() @@ -346,7 +352,7 @@ test_package_presence() { fi local full_pkgname - get_complete_package_name full_pkgname $pkgname $version $pkgtype $iteration $arch + get_complete_package_name full_pkgname "$pkgname" "$version" "$pkgtype" "$iteration" "$arch" # See if we can skip building the package, only if it already exists in the # processed/ directory. If so, move it back to the packages directory to make -- 2.30.2