Skip to content

Commit

Permalink
Use UPX to reduce size of distributed binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusweig committed Jun 7, 2020
1 parent 1e1a18d commit dcf1fed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
- name: Verify build
run: make dev

- name: Install UPX
# if: contains(github.ref, 'tags')
run: |
apt update
apt install -y upx
- name: Make binaries
if: contains(github.ref, 'tags')
run: |
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 ketall main.go

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

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

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

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

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

0 comments on commit dcf1fed

Please sign in to comment.