17417: add arm64 support for our golang packages, functional for Debian
authorWard Vandewege <ward@curii.com>
Wed, 22 Dec 2021 18:34:07 +0000 (13:34 -0500)
committerWard Vandewege <ward@curii.com>
Wed, 22 Dec 2021 18:43:25 +0000 (13:43 -0500)
       11 as of this commit.

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

build/package-build-dockerfiles/debian11/Dockerfile
build/run-build-packages-one-target.sh
build/run-build-packages.sh
build/run-library.sh

index 06380ef896b2b79669fc758b02616315e5de8525..924c916845c4131d56a9a43e1d2dd8fb58e75eab 100644 (file)
@@ -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/
index 7a91cb4de15eec13dbd524342b2bb20679666b0e..d52de98a933b895e53214afacc3f2fa10e72f5b5 100755 (executable)
@@ -21,6 +21,8 @@ Syntax:
     Build only a specific package
 --only-test <package>
     Test only a specific package
+--only-arch <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
index 26ed168aa6c60365109e63c8bfef83d8831dfe68..5fe176a182965ac0f7133e596393fd9f6008b9da 100755 (executable)
@@ -22,6 +22,8 @@ Options:
     Distribution to build packages for (default: debian10)
 --only-build <package>
     Build only a specific package (or $ONLY_BUILD from environment)
+--only-arch <architecture>
+    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
             ;;
index ebc1f9e59fc1d4122627cc6bcd700cd16573de2c..686c2b678290b1ab95f659dfd684482e3d9ca36d 100755 (executable)
@@ -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