Add option to use with zigbuild

Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
2024-02-22 16:36:20 +01:00
parent f6fb48e08c
commit 7a96634b5a
4 changed files with 125 additions and 12 deletions

48
build.sh Executable file → Normal file
View File

@@ -2,14 +2,17 @@
print_usage()
{
echo "USAGE: $0 <slim|full> [rust version] [cross version]"
echo "USAGE: $0 <slim|full|zig> [rust version] [cross version] [zig version]"
echo
echo "Arguments:"
echo -e "\t<slim|full>\tSlim build (without targets) or Full build (with targets)"
echo
echo -e "\t[rust version]\tVersion of rust (https://github.com/rust-lang/rust)"
echo -e "\t[cross version]\tVersion of cross (https://github.com/cross-rs/cross)"
echo -e "\t[zig version]\tVersion of zig (https://ziglang.org/download)"
echo -e "\t\t\tUse 'master' for master version of zig"
echo
echo "Both versions default to the latest version."
echo "All versions default to the latest release."
}
get_latest_release() {
@@ -18,6 +21,18 @@ get_latest_release() {
sed -E 's/.*"v?([^"]+)".*/\1/' # Pluck JSON value
}
get_version() {
case $2 in
latest | "")
echo $(get_latest_release $1)
;;
*)
echo $2
;;
esac
}
if command -v podman &> /dev/null
then
@@ -42,7 +57,7 @@ if [ $# -lt 1 ]; then
fi
case ${1} in
full | slim)
full | slim | zig)
;;
*)
@@ -56,7 +71,7 @@ esac
set -e -o pipefail
if [ -z "$2" ]; then
RUST_VERSION=$(get_latest_release 'rust-lang/rust')
RUST_VERSION=$(get_version 'rust-lang/rust' $2)
else
RUST_VERSION=$2
fi
@@ -67,12 +82,25 @@ else
CROSS_VERSION=$3
fi
echo "Creating a ${1} build with Rust ${RUST_VERSION} and cross ${CROSS_VERSION}"
ZIG_VERSION=$(get_latest_release 'ziglang/zig')
export RUST_VERSION
export CROSS_VERSION
export ZIG_VERSION
IMAGE="img.kie.rs/jjkiers/rust-dind-cross:rust${RUST_VERSION}-cross${CROSS_VERSION}-${1}"
echo "Creating a ${1} build with the following versions:"
echo -e "\tRust:\t${RUST_VERSION}"
echo -e "\tcross:\t${CROSS_VERSION}"
echo -e "\tzig:\t${ZIG_VERSION}"
case $1 in
full | slim)
IMAGE="img.kie.rs/jjkiers/rust-crossbuild:rust${RUST_VERSION}-cross${CROSS_VERSION}-${1}"
;;
zig)
IMAGE="img.kie.rs/jjkiers/rust-crossbuild:rust${RUST_VERSION}-zig${ZIG_VERSION}-${1}"
;;
esac
envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
-t ${IMAGE} \
@@ -80,6 +108,12 @@ envsubst < Dockerfile-${1} | ${BUILDER} build -f - \
echo "Built image ${IMAGE}"
exit 0
${BUILDER} push ${IMAGE}
echo "Pushed image ${IMAGE}"
if [ $? -ne 0 ]; then
echo "Pushing failed: ${BUILDER} push ${IMAGE}"
else
echo "Pushed image ${IMAGE}"
fi