Replace gox with a bash build script (#571)

This commit is contained in:
Dan Sosedoff
2022-07-26 20:17:40 -05:00
committed by GitHub
parent 2d6ec5dde7
commit 9a75243732
2 changed files with 28 additions and 25 deletions

View File

@@ -1,4 +1,3 @@
TARGETS = darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64
GIT_COMMIT = $(shell git rev-parse HEAD)
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
GO_VERSION = $(shell go version | awk {'print $$3'})
@@ -11,10 +10,8 @@ usage:
@echo ""
@echo "Task : Description"
@echo "----------------- : -------------------"
@echo "make setup : Install all necessary dependencies"
@echo "make dev : Generate development build"
@echo "make build : Generate production build for current OS"
@echo "make bootstrap : Install cross-compilation toolchain"
@echo "make release : Generate binaries for all supported OSes"
@echo "make test : Execute test suite"
@echo "make test-all : Execute test suite on multiple PG versions"
@@ -42,31 +39,13 @@ build:
release: LDFLAGS += -X $(PKG)/pkg/command.GitCommit=$(GIT_COMMIT)
release: LDFLAGS += -X $(PKG)/pkg/command.BuildTime=$(BUILD_TIME)
release: LDFLAGS += -X $(PKG)/pkg/command.GoVersion=$(GO_VERSION)
release:
release: clean
@echo "Building binaries..."
@gox \
-osarch "$(TARGETS)" \
-ldflags "$(LDFLAGS)" \
-output "./bin/pgweb_{{.OS}}_{{.Arch}}"
@echo "Building ARM binaries..."
GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "$(LDFLAGS)" -o "./bin/pgweb_linux_arm_v5"
@echo "Building ARM64 binaries..."
GOOS=linux GOARCH=arm64 GOARM=7 go build -ldflags "$(LDFLAGS)" -o "./bin/pgweb_linux_arm64_v7"
@echo "\nPackaging binaries...\n"
@./script/package.sh
bootstrap:
gox -build-toolchain
setup:
go install github.com/mitchellh/gox@v1.0.1
@LDFLAGS='${LDFLAGS}' ./script/build_all.sh
clean:
@rm -f ./pgweb
@rm -rf ./bin/*
@echo "Removing all artifacts"
@rm -rf ./pgweb ./bin/*
docker:
docker build --no-cache -t pgweb .

24
script/build_all.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
TARGETS="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64"
ARM_TARGETS="arm/v5 arm64/v7"
for target in $TARGETS; do
echo "-> target: $target"
parts=(${target//\// })
os=${parts[0]}
arch=${parts[1]}
GOOS=$os GOARCH=$arch go build -ldflags "$LDFLAGS" -o "./bin/pgweb_${os}_${arch}"
done
for target in $ARM_TARGETS; do
echo "-> target: $target"
parts=(${target//\// })
arch=${parts[0]}
arm=$(echo ${parts[1]} | sed s/v//g)
GOOS=linux GOARCH=$arch GOARM=$arm go build -ldflags "$LDFLAGS" -o "./bin/pgweb_linux_${arch}_v${arm}"
done