Files
alda-mirror/client/bin/build

81 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/../"
mkdir -p target
# Keep the target folder from getting too big by deleting any builds older than
# 7 days.
if [ -d target/ ]; then
find \
target/ \
-maxdepth 1 \
-not -path target/ \
-type d \
-mtime +7 \
-exec rm -vrf {} \;
fi
# See comments about generated code in main.go.
go generate
build_sha="$(../bin/current-content-sha client)"
if [[ -d "target/$build_sha" ]]; then
echo "Existing build: $PWD/target/$build_sha"
exit 0
fi
# Refuse to build unless the tests are all passing.
go test $(go list ./...)
function build() {
os="$1"
arch="$2"
if [[ "$os" == "windows" ]]; then
ext=".exe"
else
ext=""
fi
output_filename="target/$build_sha/$os-$arch/alda$ext"
echo "Building $output_filename..."
# Install the standard packages locally to speed up subsequent builds.
GOOS="$os" GOARCH="$arch" go install
# Build.
#
# Notes:
# * The trimpath flags make it so that paths are stripped in the binary, which
# we need because otherwise, the full path to the executable (at build time!
# like, it contains "/home/circleci"!) ends up in the log output.
# Reference: https://github.com/rs/zerolog/issues/133#issuecomment-464404901
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \
go build \
-tags netgo \
-ldflags '-w -extldflags "-static"' \
-gcflags="all=-trimpath=$PWD" \
-asmflags="all=-trimpath=$PWD" \
-o "$output_filename" \
main.go
}
for os in windows darwin linux; do
for arch in 386 amd64; do
# Support for darwin/386 was apparently removed around Go 1.13.
if [[ "$os" == darwin ]] && [[ "$arch" == 386 ]]; then
continue
fi
build $os $arch
done
done
echo "Done."