Skip to content

Commit

Permalink
Merge pull request #3415 from owncloud/pie
Browse files Browse the repository at this point in the history
use trimpath and buildmode=pie for binaries
  • Loading branch information
wkloucek authored Mar 29, 2022
2 parents dbaefed + 61cd1a3 commit 5dd03dd
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 33 deletions.
7 changes: 0 additions & 7 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"

5 changes: 0 additions & 5 deletions .bingo/gox.mod

This file was deleted.

6 changes: 0 additions & 6 deletions .bingo/gox.sum

This file was deleted.

3 changes: 0 additions & 3 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

116 changes: 104 additions & 12 deletions .make/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,118 @@ 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)-linux-amd64' \
./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)-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 \
go build \
-tags 'netgo $(TAGS)' \
-buildmode=pie \
-trimpath \
-ldflags '-extldflags "-static" $(LDFLAGS) $(DOCKER_LDFLAGS)' \
-o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm64' \
./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)-linux-amd64' \
./cmd/$(NAME)

GOOS=linux \
GOARCH=386 \
go build \
-tags 'netgo $(TAGS)' \
-trimpath \
-ldflags '-extldflags "-static" $(LDFLAGS)' \
-o '$(DIST)/binaries/$(EXECUTABLE)-linux-386' \
./cmd/$(NAME)

GOOS=linux \
GOARCH=arm64 \
go build \
-tags 'netgo $(TAGS)' \
-buildmode=pie \
-trimpath \
-ldflags '-extldflags "-static" $(LDFLAGS)' \
-o '$(DIST)/binaries/$(EXECUTABLE)-linux-arm64' \
./cmd/$(NAME)

GOOS=linux \
GOARCH=arm \
go build \
-tags 'netgo $(TAGS)' \
-trimpath \
-ldflags '-extldflags "-static" $(LDFLAGS)' \
-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: $(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)-windows-amd64' \
./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)-darwin-amd64' \
./cmd/$(NAME)

GOOS=darwin \
GOARCH=arm64 \
go build \
-tags 'netgo $(TAGS)' \
-buildmode=pie \
-trimpath \
-ldflags '$(LDFLAGS)' \
-o '$(DIST)/binaries/$(EXECUTABLE)-darwin-arm64' \
./cmd/$(NAME)

.PHONY: release-copy
release-copy:
Expand Down

0 comments on commit 5dd03dd

Please sign in to comment.