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 2 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
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ 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
.PHONY: multi-cross-build
multi-cross-build:
sh tools/scripts/multi-cross-build.sh

.PHONY: start
start: build
Expand Down
17 changes: 5 additions & 12 deletions build/go-cross-build.sh → tools/scripts/multi-cross-build.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#!/usr/bin/env bash

package=$1
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name>"
exit 1
fi
package_split=(${package//\// })
package_name=${package_split[-1]}

platforms=("windows/amd64" "windows/386" "linux/amd64" "darwin/amd64")
defradb_main="cli/defradb/main.go"
build_dir="build/"
platforms=("windows/amd64" "windows/386" "linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
output_name=$build_dir'defradb-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi

env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $package
env GOOS=$GOOS GOARCH=$GOARCH go build -o $output_name $defradb_main
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
orpheuslummis marked this conversation as resolved.
Show resolved Hide resolved
Expand Down