Skip to content

Commit 7f87972

Browse files
Use UPX to reduce size of distributed binaries (#57)
1 parent 6a94c5e commit 7f87972

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ jobs:
5252
if: contains(github.ref, 'tags')
5353
run: |
5454
set -euo pipefail
55+
sudo apt update
56+
sudo apt install -y upx
5557
hack/install-gox.sh
5658
make deploy
5759

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ else
5151
COMPRESS:=gzip --best -k -c
5252
endif
5353

54+
define doUPX
55+
strip $@ && upx -9q $@
56+
endef
57+
5458
GO_FILES := $(shell find . -type f -name '*.go')
5559

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

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

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

9499
.PHONY: lint
95100
lint:
@@ -131,9 +136,15 @@ clean:
131136
$(RM) -r $(BUILDDIR) rakkess
132137

133138
$(BUILDDIR)/rakkess-amd64-linux: build-rakkess
139+
$(doUPX)
134140
$(BUILDDIR)/rakkess-amd64-darwin: build-rakkess
141+
$(doUPX)
135142
$(BUILDDIR)/rakkess-amd64-windows.exe: build-rakkess
143+
$(doUPX)
136144

137145
$(BUILDDIR)/access-matrix-amd64-linux: build-access-matrix
146+
$(doUPX)
138147
$(BUILDDIR)/access-matrix-amd64-darwin: build-access-matrix
148+
$(doUPX)
139149
$(BUILDDIR)/access-matrix-amd64-windows.exe: build-access-matrix
150+
$(doUPX)

0 commit comments

Comments
 (0)