Files
2026-07-03 10:14:48 +02:00

72 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euxo pipefail
THIS_SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
ROOT_DIR="$THIS_SCRIPT_DIR/.."
IROH_DIR="$THIS_SCRIPT_DIR/../iroh"
TARGETS="x86_64-musl,x86_64-unknown-linux-musl aarch64-musl,aarch64-unknown-linux-musl"
if ! command -v docker &> /dev/null; then
echo "▸ docker cli not found, please install it"
exit 1
fi
if ! command -v sha256sum &> /dev/null; then
echo "▸ sha256sum tool not found, please install it"
exit 1
fi
if ! command -v upx &> /dev/null; then
echo "▸ upx tool not found, please install it"
exit 1
fi
if [ ! -d $IROH_DIR ]; then
echo "▸ cloning iroh source code"
git clone https://github.com/n0-computer/iroh $IROH_DIR
echo "▸ checkout out version v1.0.1 of iroh"
git -C $IROH_DIR checkout v1.0.1
fi
for i in $TARGETS; do
IFS=","; set -- $i;
echo "▸ building for $1"
docker run --rm -it \
-v "${IROH_DIR}":/home/rust/src \
-e RUSTFLAGS="-C target-feature=+crt-static" \
"ghcr.io/rust-cross/rust-musl-cross:${1}" \
cargo build \
--profile optimized-release \
--features server \
--package iroh-relay
done
# NOTE(d1): if possible, avoid having to rework permissions?
echo "▸ resetting ownership permissions for $IROH_DIR"
sudo chown -R $(whoami):$(whoami) "$IROH_DIR/target"
for i in $TARGETS; do
IFS=","; set -- $i;
echo "▸ stripping with musl-strip"
docker run --rm -it \
-v "${IROH_DIR}":/home/rust/src \
-e RUSTFLAGS="-C target-feature=+crt-static" \
"ghcr.io/rust-cross/rust-musl-cross:${1}" \
musl-strip \
"/home/rust/src/target/${2}/optimized-release/iroh-relay"
echo "▸ compressing binary for ${2} with upx"
upx --best --lzma "${IROH_DIR}/target/${2}/optimized-release/iroh-relay"
echo "▸ moving binaries into place"
mkdir -p "${ROOT_DIR}/target/$2"
cp "${IROH_DIR}/target/$2/optimized-release/iroh-relay" "${ROOT_DIR}/target/$2/iroh-relay"
echo "▸ generating checksum for $2"
sha256sum "${ROOT_DIR}/target/$2/iroh-relay" > "${ROOT_DIR}/target/$2/checksum.txt"
done