+ if [[ -n "$target_arch" ]]; then
+ # A target architecture has been specified
+ package_go_binary_worker "$src_path" "$prog" "$package_format" "$description" "$native_arch" "$target_arch" "$license_file"
+ return $?
+ else
+ # No target architecture specified, default to native target. When on amd64 also crosscompile arm64
+ # but only when building deb packages (centos does not have support for crosscompiling userspace).
+ archs=($native_arch)
+ if [[ "$native_arch" == "amd64" ]] && [[ "$package_format" == "deb" ]]; then
+ archs=('amd64' 'arm64')
+ fi
+ for ta in $archs; do
+ package_go_binary_worker "$src_path" "$prog" "$package_format" "$description" "$native_arch" "$ta" "$license_file"
+ retval=$?
+ if [[ "$retval" != 0 ]]; then
+ return $retval
+ fi
+ done
+ fi
+}
+
+# Usage: package_go_binary services/foo arvados-foo deb "Compute foo to arbitrary precision" [amd64/arm64] [amd64/arm64] [apache-2.0.txt]
+package_go_binary_worker() {
+ local src_path="$1"; shift
+ local prog="$1"; shift
+ local package_format="$1"; shift
+ local description="$1"; shift
+ local native_arch="${1:-amd64}"; shift
+ local target_arch="${1:-amd64}"; shift
+ local license_file="${1:-agpl-3.0.txt}"; shift
+
+ if [[ "$native_arch" != "$target_arch" ]] && [[ "$package_format" == "rpm" ]]; then
+ echo "Error: no cross compilation support for Go on $native_arch ($package_format), can not build $prog for $target_arch"
+ return 1
+ fi
+
+ debug_echo "package_go_binary $src_path as $prog (native arch: $native_arch, target arch: $target_arch)"