summaryrefslogtreecommitdiff
path: root/cross_compile.sh
diff options
context:
space:
mode:
authorBen Busby <contact@benbusby.com>2025-01-29 12:45:56 -0700
committerBen Busby <contact@benbusby.com>2025-01-29 12:45:56 -0700
commit4ec94a141d99da43df250d331d6651b8c870e5c9 (patch)
treed2c50db47c6c4ac6f977db809f4bd079a9902048 /cross_compile.sh
parent6682d5c59a99f1c34d4905e859a9a77fa7c25f77 (diff)
downloadfarside-4ec94a141d99da43df250d331d6651b8c870e5c9.tar.gz
Add cross compiler script [skip ci]
Diffstat (limited to 'cross_compile.sh')
-rwxr-xr-xcross_compile.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/cross_compile.sh b/cross_compile.sh
new file mode 100755
index 0000000..50deecc
--- /dev/null
+++ b/cross_compile.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
+
+mkdir -p $dir/out/
+rm -f $dir/out/*
+
+platforms=(
+ "linux/arm"
+ "linux/amd64"
+ "linux/arm64"
+ "linux/386"
+ "darwin/amd64"
+ "darwin/arm64"
+ "windows/386"
+ "windows/amd64"
+ "windows/arm64")
+
+for platform in "${platforms[@]}"
+do
+ platform_split=(${platform//\// })
+ GOOS=${platform_split[0]}
+ GOARCH=${platform_split[1]}
+ output_name="farside"
+
+ tar_name="farside_${GOOS}_${GOARCH}.tar.gz"
+ if [ $GOOS = "darwin" ]; then
+ tar_name="farside_macOS_${GOARCH}.tar.gz"
+ fi
+
+ if [ $GOOS = "windows" ]; then
+ output_name+=".exe"
+ fi
+
+ compile_cmd="GOOS=$GOOS GOARCH=$GOARCH go build -ldflags='-s -w' -o $output_name ."
+ echo "└ $compile_cmd"
+ eval $compile_cmd
+ if [ $? -ne 0 ]; then
+ echo "An error has occurred! Aborting the script execution..."
+ exit 1
+ fi
+
+ tar -czvf out/$tar_name $output_name
+ rm -f $output_name
+done