Add cross compiler script [skip ci]

This commit is contained in:
Ben Busby 2025-01-29 12:45:56 -07:00
parent 6682d5c59a
commit 4ec94a141d
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
2 changed files with 46 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
badger-db
farside
deploy.sh
out

45
cross_compile.sh Executable file
View File

@ -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