From cdd72e3a3dc16f85a50fe7abe358deae4aacbaea Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 29 Mar 2022 09:16:47 +0200 Subject: [PATCH 1/3] use trimpath and buildmode=pie for binaries --- .bingo/Variables.mk | 7 --- .bingo/gox.mod | 5 -- .bingo/gox.sum | 6 --- .bingo/variables.env | 3 -- .make/release.mk | 111 ++++++++++++++++++++++++++++++++++++++----- 5 files changed, 99 insertions(+), 33 deletions(-) delete mode 100644 .bingo/gox.mod delete mode 100644 .bingo/gox.sum diff --git a/.bingo/Variables.mk b/.bingo/Variables.mk index 94c5d9bced2..f442f5340bc 100644 --- a/.bingo/Variables.mk +++ b/.bingo/Variables.mk @@ -47,12 +47,6 @@ $(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod @echo "(re)installing $(GOBIN)/golangci-lint-v1.43.0" @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.43.0 "github.com/golangci/golangci-lint/cmd/golangci-lint" -GOX := $(GOBIN)/gox-v1.0.1 -$(GOX): $(BINGO_DIR)/gox.mod - @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. - @echo "(re)installing $(GOBIN)/gox-v1.0.1" - @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=gox.mod -o=$(GOBIN)/gox-v1.0.1 "github.com/mitchellh/gox" - HUGO := $(GOBIN)/hugo-v0.91.0 $(HUGO): $(BINGO_DIR)/hugo.mod @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. @@ -106,4 +100,3 @@ $(REFLEX): $(BINGO_DIR)/reflex.mod @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. @echo "(re)installing $(GOBIN)/reflex-v0.3.1" @cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=reflex.mod -o=$(GOBIN)/reflex-v0.3.1 "github.com/cespare/reflex" - diff --git a/.bingo/gox.mod b/.bingo/gox.mod deleted file mode 100644 index c48c4a9fa34..00000000000 --- a/.bingo/gox.mod +++ /dev/null @@ -1,5 +0,0 @@ -module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT - -go 1.17 - -require github.com/mitchellh/gox v1.0.1 diff --git a/.bingo/gox.sum b/.bingo/gox.sum deleted file mode 100644 index 0b5dfc49612..00000000000 --- a/.bingo/gox.sum +++ /dev/null @@ -1,6 +0,0 @@ -github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= -github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -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= diff --git a/.bingo/variables.env b/.bingo/variables.env index b54bcc82b4b..1deb407f41e 100644 --- a/.bingo/variables.env +++ b/.bingo/variables.env @@ -18,8 +18,6 @@ CALENS="${GOBIN}/calens-v0.2.0" GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.43.0" -GOX="${GOBIN}/gox-v1.0.1" - HUGO="${GOBIN}/hugo-v0.91.0" MOCKERY="${GOBIN}/mockery-v2.9.4" @@ -37,4 +35,3 @@ PROTOC_GEN_MICROWEB="${GOBIN}/protoc-gen-microweb-v0.0.0-20211219183901-997c02ca PROTOC_GEN_OPENAPIV2="${GOBIN}/protoc-gen-openapiv2-v2.7.2" REFLEX="${GOBIN}/reflex-v0.3.1" - diff --git a/.make/release.mk b/.make/release.mk index 6f99abec746..612b375373e 100644 --- a/.make/release.mk +++ b/.make/release.mk @@ -11,26 +11,113 @@ release-dirs: # docker specific packaging flags DOCKER_LDFLAGS += -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseDataPathType=path" -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseDataPathValue=/var/lib/ocis" -release-linux-docker-amd64: $(GOX) release-dirs - @$(GOX) -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' -os 'linux' -arch 'amd64' -output '$(DIST)/binaries/$(EXECUTABLE)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME) -release-linux-docker-arm: $(GOX) release-dirs - @$(GOX) -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' -os 'linux' -arch 'arm' -output '$(DIST)/binaries/$(EXECUTABLE)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME) +release-linux-docker-amd64: release-dirs + GOOS=linux \ + GOARCH=amd64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-linux' \ + ./cmd/$(NAME) -release-linux-docker-arm64: $(GOX) release-dirs - @$(GOX) -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' -os 'linux' -arch 'arm64' -output '$(DIST)/binaries/$(EXECUTABLE)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME) +release-linux-docker-arm: release-dirs + GOOS=linux \ + GOARCH=arm \ + go build \ + -tags 'netgo $(TAGS)' \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-arm-linux' \ + ./cmd/$(NAME) + +release-linux-docker-arm64: release-dirs + GOOS=linux \ + GOARCH=arm64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-arm64-linux' \ + ./cmd/$(NAME) .PHONY: release-linux -release-linux: $(GOX) release-dirs - @$(GOX) -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -os 'linux' -arch 'amd64 386 arm64 arm' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME) +release-linux: release-dirs + GOOS=linux \ + GOARCH=amd64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-linux' \ + ./cmd/$(NAME) + + GOOS=linux \ + GOARCH=386 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-386-linux' \ + ./cmd/$(NAME) + + GOOS=linux \ + GOARCH=arm64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-arm64-linux' \ + ./cmd/$(NAME) + + GOOS=linux \ + GOARCH=arm \ + go build \ + -tags 'netgo $(TAGS)' \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-arm-linux' \ + ./cmd/$(NAME) .PHONY: release-windows -release-windows: $(GOX) release-dirs - @$(GOX) -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -os 'windows' -arch 'amd64' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME) +release-windows: release-dirs + GOOS=windows \ + GOARCH=amd64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '-extldflags "-static" $(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-windows' \ + ./cmd/$(NAME) .PHONY: release-darwin -release-darwin: $(GOX) release-dirs - @$(GOX) -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -os 'darwin' -arch 'amd64 arm64' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME) +release-darwin: release-dirs + GOOS=darwin \ + GOARCH=amd64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '$(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-darwin' \ + ./cmd/$(NAME) + + GOOS=darwin \ + GOARCH=arm64 \ + go build \ + -tags 'netgo $(TAGS)' \ + -buildmode=pie \ + -trimpath \ + -ldflags '$(LDFLAGS)' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-arm64-darwin' \ + ./cmd/$(NAME) .PHONY: release-copy release-copy: From f66ee2c855981d2992fb9abcb6dd0d27054c1568 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 29 Mar 2022 09:28:04 +0200 Subject: [PATCH 2/3] fix os-arch order --- .make/release.mk | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.make/release.mk b/.make/release.mk index 612b375373e..7bccfc7b345 100644 --- a/.make/release.mk +++ b/.make/release.mk @@ -20,7 +20,7 @@ release-linux-docker-amd64: release-dirs -buildmode=pie \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-amd64' \ ./cmd/$(NAME) release-linux-docker-arm: release-dirs @@ -30,7 +30,7 @@ release-linux-docker-arm: release-dirs -tags 'netgo $(TAGS)' \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-arm-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm' \ ./cmd/$(NAME) release-linux-docker-arm64: release-dirs @@ -41,7 +41,7 @@ release-linux-docker-arm64: release-dirs -buildmode=pie \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-arm64-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm64' \ ./cmd/$(NAME) .PHONY: release-linux @@ -53,17 +53,16 @@ release-linux: release-dirs -buildmode=pie \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-amd64' \ ./cmd/$(NAME) GOOS=linux \ GOARCH=386 \ go build \ -tags 'netgo $(TAGS)' \ - -buildmode=pie \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-386-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-386' \ ./cmd/$(NAME) GOOS=linux \ @@ -73,7 +72,7 @@ release-linux: release-dirs -buildmode=pie \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-arm64-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm64' \ ./cmd/$(NAME) GOOS=linux \ @@ -82,7 +81,7 @@ release-linux: release-dirs -tags 'netgo $(TAGS)' \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-arm-linux' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm' \ ./cmd/$(NAME) .PHONY: release-windows @@ -94,7 +93,7 @@ release-windows: release-dirs -buildmode=pie \ -trimpath \ -ldflags '-extldflags "-static" $(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-windows' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-windows-amd64' \ ./cmd/$(NAME) .PHONY: release-darwin @@ -106,7 +105,7 @@ release-darwin: release-dirs -buildmode=pie \ -trimpath \ -ldflags '$(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-amd64-darwin' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-darwin-amd64' \ ./cmd/$(NAME) GOOS=darwin \ @@ -116,7 +115,7 @@ release-darwin: release-dirs -buildmode=pie \ -trimpath \ -ldflags '$(LDFLAGS)' \ - -o '$(DIST)/binaries/$(EXECUTABLE)-arm64-darwin' \ + -o '$(DIST)/binaries/$(EXECUTABLE)-darwin-arm64' \ ./cmd/$(NAME) .PHONY: release-copy From 61cd1a3e132c89e2cc2f3594736e808709645efa Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 29 Mar 2022 09:40:58 +0200 Subject: [PATCH 3/3] add comment about buildmode=pie for arm --- .make/release.mk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.make/release.mk b/.make/release.mk index 7bccfc7b345..4c655230593 100644 --- a/.make/release.mk +++ b/.make/release.mk @@ -33,6 +33,9 @@ release-linux-docker-arm: release-dirs -o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm' \ ./cmd/$(NAME) + @# https://github.com/golang/go/issues/50405 + @# -buildmode=pie not easily doable for arm + release-linux-docker-arm64: release-dirs GOOS=linux \ GOARCH=arm64 \ @@ -84,6 +87,9 @@ release-linux: release-dirs -o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm' \ ./cmd/$(NAME) + @# https://github.com/golang/go/issues/50405 + @# -buildmode=pie not easily doable for arm + .PHONY: release-windows release-windows: release-dirs GOOS=windows \