From cd05a14e64eb103ec114145cdcdc170062af0d9d Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Sun, 10 Oct 2021 23:29:51 +0300 Subject: [PATCH] build: cross-platform build with gox --- Makefile | 25 +++---------------------- go.mod | 1 + go.sum | 6 ++++++ 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 2117672f..c87850f3 100644 --- a/Makefile +++ b/Makefile @@ -4,28 +4,9 @@ EXECUTABLE=aws-mfa-assume-credential-process BIN_FOLDER="bin" -WINDOWS=$(BIN_FOLDER)/$(EXECUTABLE)-windows-amd64.exe -LINUX=$(BIN_FOLDER)/$(EXECUTABLE)-linux-amd64 -DARWIN=$(BIN_FOLDER)/$(EXECUTABLE)-darwin-amd64 -VERSION=$(shell git describe --tags --always --long --dirty) -windows: $(WINDOWS) ## Build for Windows - -linux: $(LINUX) ## Build for Linux - -darwin: $(DARWIN) ## Build for Darwin (macOS) - -$(WINDOWS): - env GOOS=windows GOARCH=amd64 go build -i -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/main.go - -$(LINUX): - env GOOS=linux GOARCH=amd64 go build -i -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/main.go - -$(DARWIN): - env GOOS=darwin GOARCH=amd64 go build -i -v -o $(DARWIN) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/main.go - -build: windows linux darwin ## Build binaries - @echo version: $(VERSION) +build: clean ## Build binaries + @(cd cmd && gox -output="../$(BIN_FOLDER)/$(EXECUTABLE)_{{.OS}}_{{.Arch}}" -osarch="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64") all: test build ## Build and run tests @@ -34,7 +15,7 @@ test: clean ## Run unit tests clean: ## Remove previous build @(go clean) - rm -f $(WINDOWS) $(LINUX) $(DARWIN) + @(rm -rf $(BIN_FOLDER)) help: ## Display available commands @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/go.mod b/go.mod index 6d49062e..ca046f8a 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/gookit/color v1.4.2 github.com/mattn/go-colorable v0.1.11 github.com/mattn/go-tty v0.0.3 + github.com/mitchellh/gox v1.0.1 // indirect github.com/urfave/cli/v2 v2.3.0 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 gopkg.in/ini.v1 v1.63.2 diff --git a/go.sum b/go.sum index 47d71c45..94aba755 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4 github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= +github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= +github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= @@ -23,6 +25,10 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI= github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= +github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= +github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= +github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=