Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: Fix the cross-build script #460

Merged
merged 8 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ install:
build:
go build -o build/defradb cli/defradb/main.go

.PHONY: multi-build
multi-build:
echo "Compiling for multiple OS and Platforms"
GOOS=linux GOARCH=arm go build -o build/defradb-linux-arm cli/defradb/main.go
GOOS=linux GOARCH=arm64 go build -o build/defradb-linux-arm64 cli/defradb/main.go
GOOS=freebsd GOARCH=386 go build -o build/defradb-freebsd-386 cli/defradb/main.go
# Usage: make cross-build platforms="{platforms}"
# platforms is specified as a comma-separated list with no whitespace, e.g. "linux/amd64,linux/arm,linux/arm64"
# If none is specified, build for all platforms.
.PHONY: cross-build
cross-build:
bash tools/scripts/cross-build.sh $(platforms)

.PHONY: start
start: build
Expand Down
28 changes: 0 additions & 28 deletions build/go-cross-build.sh

This file was deleted.

39 changes: 39 additions & 0 deletions tools/scripts/cross-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

DEFRADB_MAIN="cli/defradb/main.go"
BUILD_DIR="build/"

platforms=$1
if [[ -z "${platforms}" ]]; then
echo "Building for all platforms"
# A subset of the comprehensive list found at https://go.dev/doc/install/source#environment
platforms=(
"windows/amd64"
"windows/arm64"
"windows/arm"
"linux/amd64"
"linux/arm64"
"linux/arm"
"darwin/amd64"
"darwin/arm64"
# "js/wasm"
)
else
platforms=(${platforms//,/ })
fi

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS="${platform_split[0]}"
GOARCH="${platform_split[1]}"
output_name=$BUILD_DIR'defradb-'$GOOS'-'$GOARCH
if [ "$GOOS" = "windows" ]; then
output_name+='.exe'
fi
if ! env GOOS="$GOOS" GOARCH="$GOARCH" go build -o $output_name $DEFRADB_MAIN; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
echo "Completed: ${output_name}"
done