|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Fail script on any error (do not change) |
| 4 | +set -e |
| 5 | + |
| 6 | +PROJECT_ROOT="$(dirname "$(dirname "$(realpath "$0")")")" |
| 7 | +cd "${PROJECT_ROOT}" |
| 8 | + |
| 9 | +# Make sure no one is sourcing the script, as we export variables |
| 10 | +if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then |
| 11 | + echo "Execute ${BASH_SOURCE[0]} instead of souring it" |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +version="HEAD" # use "latest" for most recent tagged release |
| 16 | +install_targets=( |
| 17 | + "github.com/athanorlabs/atomic-swap/cmd/swapd@${version}" |
| 18 | + "github.com/athanorlabs/atomic-swap/cmd/swapcli@${version}" |
| 19 | + "github.com/athanorlabs/atomic-swap/cmd/bootnode@${version}" |
| 20 | +) |
| 21 | + |
| 22 | +# turn on echo |
| 23 | +set -x |
| 24 | + |
| 25 | +dest_dir=release-bin |
| 26 | +rm -rf "${dest_dir}" |
| 27 | +mkdir "${dest_dir}" |
| 28 | + |
| 29 | +# Note: We don't bother with static builds (larger binaries) as swapd depends on |
| 30 | +# a local monero-wallet-rpc binary and all releases of monero-wallet-rpc depend |
| 31 | +# on glibc. |
| 32 | +unset CGO_ENABLED |
| 33 | + |
| 34 | +# Unfortunately, GOBIN can't be set when doing cross platform builds and |
| 35 | +# go install doesn't take an -o flag: |
| 36 | +# https://github.com/golang/go/issues/57485 |
| 37 | +# We are inside a go module project right now and we'll confuse tooling |
| 38 | +# if we put the GOPATH inside of the project. We are using "go install", |
| 39 | +# so nothing will go wrong even if a go.mod exists at the top of /tmp. |
| 40 | +build_dir="$(mktemp -d /tmp/release-build-XXXXXXXXXX)" |
| 41 | + |
| 42 | +for os in linux darwin; do |
| 43 | + for arch in amd64 arm64; do |
| 44 | + GOPATH="${build_dir}" GOOS="${os}" GOARCH="${arch}" \ |
| 45 | + go install -tags=prod "${install_targets[@]}" |
| 46 | + from_dir="${build_dir}/bin/${os}_${arch}" |
| 47 | + to_dir="${dest_dir}/${os/darwin/macos}-${arch/amd64/x64}" |
| 48 | + if [[ -d "${from_dir}" ]]; then |
| 49 | + # non-native binaries |
| 50 | + mv "${from_dir}" "${to_dir}" |
| 51 | + else |
| 52 | + # native binaries |
| 53 | + mkdir "${to_dir}" |
| 54 | + mv "${build_dir}/bin/"* "${to_dir}" |
| 55 | + fi |
| 56 | + done |
| 57 | +done |
| 58 | + |
| 59 | +chmod -R u+w "${build_dir}" |
| 60 | +rm -rf "${build_dir}" |
0 commit comments