Skip to content

Commit

Permalink
Merge pull request #2697 from reubenmiller/ci-build-script-outside-op…
Browse files Browse the repository at this point in the history
…tions

build: support build/packaging using other tooling
  • Loading branch information
reubenmiller authored Feb 12, 2024
2 parents 5ce44d6 + 08053cf commit 892716f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 42 deletions.
102 changes: 60 additions & 42 deletions ci/build_scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ ARCH=
TARGET=()
BUILD_OPTIONS=()
BUILD=1
INCLUDE_TEST_PACKAGES=1
INCLUDE_DEPRECATED_PACKAGES=1

REST_ARGS=()
while [ $# -gt 0 ]
Expand All @@ -89,6 +91,14 @@ do
BUILD=0
;;

--skip-test-packages)
INCLUDE_TEST_PACKAGES=0
;;

--skip-deprecated-packages)
INCLUDE_DEPRECATED_PACKAGES=0
;;

-h|--help)
help
exit 0
Expand Down Expand Up @@ -116,19 +126,6 @@ fi
# shellcheck disable=SC1091
. ./ci/build_scripts/version.sh

# Use zig to build as it is provides better cross compiling support
cargo +stable install cargo-zigbuild --version ">=0.17.3"

# Allow users to install zig by other package managers
if ! zig --help &>/dev/null; then
if ! python3 -m ziglang --help &>/dev/null; then
PIP_ROOT_USER_ACTION=ignore pip3 install ziglang --break-system-packages 2>/dev/null || PIP_ROOT_USER_ACTION=ignore pip3 install ziglang
fi
fi

# Display zig version to help with debugging
echo "zig version: $(zig version 2>/dev/null || python3 -m ziglang version 2>/dev/null ||:)"

if [ -z "$ARCH" ]; then
# If no target has been given, choose the target triple based on the
# host's architecture, however use the musl builds by default!
Expand All @@ -152,24 +149,6 @@ if [ -z "$ARCH" ]; then
esac
fi

if [ -n "$ARCH" ]; then
echo "Using target: $ARCH"
TARGET+=("--target=$ARCH")
rustup target add "$ARCH"
else
# Note: This will build the artifacts under target/release and not target/<triple>/release !
HOST_TARGET=$(rustc --version --verbose | grep host: | cut -d' ' -f2)
echo "Using host target: $HOST_TARGET"
fi

# Custom options for different targets
case "$ARCH" in
*)
BUILD_OPTIONS+=(
--release
)
;;
esac

# Load the release package list as $RELEASE_PACKAGES, $DEPRECATED_PACKAGES and $TEST_PACKAGES
# shellcheck disable=SC1091
Expand All @@ -178,6 +157,38 @@ source ./ci/package_list.sh
# build release for target
# GIT_SEMVER should be referenced in the build.rs scripts
if [ "$BUILD" = 1 ]; then
# Use zig to build as it is provides better cross compiling support
cargo +stable install cargo-zigbuild --version ">=0.17.3"

# Allow users to install zig by other package managers
if ! zig --help &>/dev/null; then
if ! python3 -m ziglang --help &>/dev/null; then
PIP_ROOT_USER_ACTION=ignore pip3 install ziglang --break-system-packages 2>/dev/null || PIP_ROOT_USER_ACTION=ignore pip3 install ziglang
fi
fi

# Display zig version to help with debugging
echo "zig version: $(zig version 2>/dev/null || python3 -m ziglang version 2>/dev/null ||:)"

if [ -n "$ARCH" ]; then
echo "Using target: $ARCH"
TARGET+=("--target=$ARCH")
rustup target add "$ARCH"
else
# Note: This will build the artifacts under target/release and not target/<triple>/release !
HOST_TARGET=$(rustc --version --verbose | grep host: | cut -d' ' -f2)
echo "Using host target: $HOST_TARGET"
fi

# Custom options for different targets
case "$ARCH" in
*)
BUILD_OPTIONS+=(
--release
)
;;
esac

cargo zigbuild "${TARGET[@]}" "${BUILD_OPTIONS[@]}"
fi

Expand All @@ -190,17 +201,24 @@ if [ -d "target/$ARCH/debian" ]; then
rm -rf "target/$ARCH/debian"
fi

# build/package both the release and deprecated packages
PACKAGES=( "${RELEASE_PACKAGES[@]}" "${DEPRECATED_PACKAGES[@]}" )
PACKAGES=( "${RELEASE_PACKAGES[@]}" )
if [ "$INCLUDE_DEPRECATED_PACKAGES" = "1" ]; then
PACKAGES+=(
"${DEPRECATED_PACKAGES[@]}"
)
fi

./ci/build_scripts/package.sh build "$ARCH" "${PACKAGES[@]}" --version "$GIT_SEMVER" --output "$OUTPUT_DIR"

if [ "$BUILD" = 1 ]; then
# Strip and build for test artifacts
for PACKAGE in "${TEST_PACKAGES[@]}"
do
cargo zigbuild --release -p "$PACKAGE" "${TARGET[@]}"
done
fi
if [ "$INCLUDE_TEST_PACKAGES" = 1 ]; then
if [ "$BUILD" = 1 ]; then
# Strip and build for test artifacts
for PACKAGE in "${TEST_PACKAGES[@]}"
do
cargo zigbuild --release -p "$PACKAGE" "${TARGET[@]}"
done
fi

# Package test binaries (deb only)
./ci/build_scripts/package.sh build "$ARCH" "${TEST_PACKAGES[@]}" --version "$GIT_SEMVER" --types deb --output "$OUTPUT_DIR" --no-clean
# Package test binaries (deb only)
./ci/build_scripts/package.sh build "$ARCH" "${TEST_PACKAGES[@]}" --version "$GIT_SEMVER" --types deb --output "$OUTPUT_DIR" --no-clean
fi
10 changes: 10 additions & 0 deletions ci/build_scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,21 @@ build_virtual_package() {
}

get_package_arch() {
# Return package architecture as per the
# nfpm architectures defined here: https://nfpm.goreleaser.com/goarch-to-pkg/
# which uses the GOARCH to abstract across the different
# arch names used in different linux packages (e.g. deb != rpm != apk)
case "$1" in
x86_64-unknown-linux-*) pkg_arch=amd64 ;;
i686-unknown-linux-*) pkg_arch=386 ;;
aarch64-unknown-linux-*) pkg_arch=arm64 ;;
armv7-unknown-linux-*eabihf) pkg_arch=arm7 ;;
arm-unknown-linux-*eabihf) pkg_arch=arm6 ;;
arm-unknown-linux-*eabi) pkg_arch=arm5 ;;
armv5te-unknown-linux-*eabi) pkg_arch=arm5 ;;
riscv64gc-unknown-linux-*) pkg_arch=riscv64 ;;
mips64el-unknown-linux-*abi64) pkg_arch=mips64le ;;
mipsel-unknown-linux-*) pkg_arch=mipsle ;;
*)
echo "Unknown package architecture. value=$1"
exit 1
Expand Down

1 comment on commit 892716f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
391 0 3 391 100 1h1m6.627999999s

Please sign in to comment.