You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4 KiB

# Make sure `cross` is installed.
# You'll also need `sed`, a relatively recent version of `tar`, and `7z`.
shopt -s extglob
# Trap errors and interrupts
set -Eeuo pipefail
function handle_sigint() {
echo "SIGINT, exiting..."
exit 1
trap handle_sigint SIGINT
function handle_err() {
echo "Error in!" 1>&2
echo "$(caller): ${BASH_COMMAND}" 1>&2
echo "Exiting..."
exit 2
trap handle_err ERR
# Go to the root of the project
SCRIPT=$(realpath "${0}")
SCRIPTPATH=$(dirname "${SCRIPT}")
cd "${SCRIPTPATH}" || exit 12
declare -A TARGETS=(
# Get the version number
VERSION=$(sed -nr 's/^version *= *"([0-9.]+)"/\1/p' Cargo.toml | head --lines=1)
# Make the builds
for target in "${!TARGETS[@]}"; do
echo Building "${target}"
# Keeping the cached builds seem to be breaking things when going between targets
# This wouldn't be a problem if these were running in a matrix on the CI...
rm -rf target/release/
cross build -j $(($(nproc) / 2)) --release --target "${target}"
if [[ "${target}" =~ .*"windows".* ]]; then
zip -j "gandi-live-dns.${VERSION}.${TARGETS[${target}]}.zip" target/"${target}"/release/gandi-live-dns.exe 1>/dev/null
tar -acf "gandi-live-dns.${VERSION}.${TARGETS[${target}]}.tar.xz" -C "target/${target}/release/" "gandi-live-dns"
if [[ "$#" -ge 2 && "$1" = "--no-docker" ]]; then
echo "Exiting without releasing to docker"
exit 0
# Copy files into place so Docker can get them easily
cd Docker
echo Building Docker images
mkdir -p binaries
for target in "${!DOCKER_TARGETS[@]}"; do
mkdir -p "binaries/${DOCKER_TARGETS[${target}]}"
cp ../target/"${target}"/release/gandi-live-dns?(|.exe) "binaries/${DOCKER_TARGETS[${target}]}/gandi-live-dns"
${DOCKER} buildx build . \
--platform=linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 \
--file "Dockerfile" \
--tag "seriousbug/gandi-live-dns-rust:latest" \
--tag "seriousbug/gandi-live-dns-rust:${VERSION}" \