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

Use UPX to reduce size of distributed binaries #57

Merged
merged 1 commit into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
if: contains(github.ref, 'tags')
run: |
set -euo pipefail
sudo apt update
sudo apt install -y upx
hack/install-gox.sh
make deploy

Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ else
COMPRESS:=gzip --best -k -c
endif

define doUPX
strip $@ && upx -9q $@
endef

GO_FILES := $(shell find . -type f -name '*.go')

.PHONY: test
Expand Down Expand Up @@ -85,11 +89,12 @@ dev: GO_LDFLAGS := $(subst -s -w,,$(GO_LDFLAGS))
dev:
go build -race -ldflags $(GO_LDFLAGS) -o rakkess main.go

# TODO(corneliusweig): gox does not support the -trimpath flag, see https://github.com/mitchellh/gox/pull/138
build-rakkess: $(GO_FILES) $(BUILDDIR)
gox -osarch="$(PLATFORMS)" -ldflags $(GO_LDFLAGS) -output="out/rakkess-{{.Arch}}-{{.OS}}"
GOFLAGS="-trimpath" gox -osarch="$(PLATFORMS)" -tags netgo -ldflags $(GO_LDFLAGS) -output="out/rakkess-{{.Arch}}-{{.OS}}"

build-access-matrix: $(GO_FILES) $(BUILDDIR)
gox -osarch="$(PLATFORMS)" -tags accessmatrix -ldflags $(GO_LDFLAGS) -output="out/access-matrix-{{.Arch}}-{{.OS}}"
GOFLAGS="-trimpath" gox -osarch="$(PLATFORMS)" -tags accessmatrix,netgo -ldflags $(GO_LDFLAGS) -output="out/access-matrix-{{.Arch}}-{{.OS}}"

.PHONY: lint
lint:
Expand Down Expand Up @@ -131,9 +136,15 @@ clean:
$(RM) -r $(BUILDDIR) rakkess

$(BUILDDIR)/rakkess-amd64-linux: build-rakkess
$(doUPX)
$(BUILDDIR)/rakkess-amd64-darwin: build-rakkess
$(doUPX)
$(BUILDDIR)/rakkess-amd64-windows.exe: build-rakkess
$(doUPX)

$(BUILDDIR)/access-matrix-amd64-linux: build-access-matrix
$(doUPX)
$(BUILDDIR)/access-matrix-amd64-darwin: build-access-matrix
$(doUPX)
$(BUILDDIR)/access-matrix-amd64-windows.exe: build-access-matrix
$(doUPX)