From 1d8b4a4bfbbf44ba10f7f5b6b7b3d51c6af338f6 Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:44:22 +0100 Subject: [PATCH] feat: cross compile bolt-cli tarballs for usage by boltup --- boltup/boltup.sh | 3 +-- justfile | 4 +++ scripts/bolt-cli-tarballs.sh | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100755 scripts/bolt-cli-tarballs.sh diff --git a/boltup/boltup.sh b/boltup/boltup.sh index 39ac403f..783eb7ed 100755 --- a/boltup/boltup.sh +++ b/boltup/boltup.sh @@ -95,8 +95,7 @@ main() { BIN_FILENAME="bolt-cli-${ARCHITECTURE}-${PLATFORM}.$EXT" BIN_ARCHIVE_URL="${RELEASE_URL}${BIN_FILENAME}" - # Download and extract the binaries archive - say "downloading latest binary" + # Download and extract the tarball. if [ "$PLATFORM" = "win32" ]; then tmp="$(mktemp -d 2>/dev/null || echo ".")/bolt.zip" ensure download "$BIN_ARCHIVE_URL" "$tmp" diff --git a/justfile b/justfile index 0c06cc95..cf9b1214 100644 --- a/justfile +++ b/justfile @@ -184,3 +184,7 @@ build-and-push-image package tag: build-and-push-all-images tag='latest': @just build-and-push-image bolt-sidecar {{tag}} @just build-and-push-image bolt-boost {{tag}} + +# Create tarballs for the bolt-cli binaries for all the supported platforms +create-bolt-cli-tarballs: + chmod +x ./scripts/bolt-cli-tarballs.sh && ./scripts/bolt-cli-tarballs.sh diff --git a/scripts/bolt-cli-tarballs.sh b/scripts/bolt-cli-tarballs.sh new file mode 100755 index 00000000..8ca19414 --- /dev/null +++ b/scripts/bolt-cli-tarballs.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -eo pipefail + +# Use this script to create tarballs for bolt-cli to be uploaded to each Github release. +# This is intended to be run locally, and assuming you have cross installed. +# +# Note: this will only work when run on MacOS as `cross` does not distribute SDKs for +# MacOS due to licensing issues. + +# Target tuples for cross compilation. +# each tuple is in the format of "target-triple", "short-name". +TARGETS=( + "aarch64-apple-darwin" "arm64-darwin" # ARM apple chips (M1) + "x86_64-apple-darwin" "amd64_64-darwin" # Intel apple chips + "aarch64-unknown-linux-gnu" "arm64-linux" # ARM linux chips + "x86_64-unknown-linux-gnu" "amd64-linux" # x86 linux chips +) + +PROFILE="release" + +# Check if cross is installed +if ! command -v cross &> /dev/null; then + echo "cross is not installed. Install it by running 'cargo install cross'" + exit 1 +fi + +( + cd bolt-cli || exit 1 + mkdir -p dist + + # Iterate over TARGETS in pairs + for ((i=0; i<${#TARGETS[@]}; i+=2)); do + target="${TARGETS[i]}" + short_name="${TARGETS[i+1]}" + + echo "Building for $target ($short_name)" + + mkdir -p "dist/$short_name" + cross build --$PROFILE --target "$target" + cp "target/$target/$PROFILE/bolt" "dist/$short_name/bolt" + tar -czf "dist/bolt-cli-$short_name.tar.gz" -C "dist/$short_name" bolt + + echo "Done building for $target ($short_name)" + done + + echo "Done building all targets." + echo "You can find the tarballs in bolt-cli/dist/" +) + +exit 0