Skip to content

Commit f4f70d3

Browse files
authored
Merge pull request #117 from setlog/feature-reduce-binary-size
Feature reduce binary size
2 parents 3fc41cf + 68d6a81 commit f4f70d3

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
run: |
2525
sudo apt-get update -y
2626
sudo apt-get install -y libgtk-3-dev
27+
- name: Install UPX (Linux)
28+
if: matrix.platform == 'ubuntu-18.04'
29+
run: sudo apt-get update && sudo apt-get install upx-ucl
30+
- name: Install UPX (Windows)
31+
if: matrix.platform == 'windows-2019'
32+
run: choco install upx -y
2733
- name: Install goversioninfo
2834
shell: bash
2935
run: |

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## TBD (TBD)
44
### Changes
5+
* DWARF symbols are now stripped from the trivrost binary to reduce file size. This can save a few bytes on some platforms.
6+
* The binary is now compressed with UPX when using `make compress`. Reduces the final filesystem to under 50%.
57
* Shorter log-output for proxy detection. Reduces average size of the log output by 5–15%.
68
* Shorter log-output for HTTP errors, reduces size of log output by a few percent.
79
* Update dependencies to recent versions: gopsutils, testify, gojsonschema, logrus, prometheus/client_golang, go_ieproxy, fatih/color, golang/x/sys, golang/x/net

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GITDESC := $(shell git describe --tags 2> /dev/null || echo unav
2323
LAUNCHER_VERSION := $(shell git describe --tags --abbrev=0 --match "v[0-9]*.[0-9]*.[0-9]*" 2> /dev/null || echo unavailable)
2424
GITBRANCH := $(shell git symbolic-ref -q --short HEAD || echo unknown)
2525
GITHASH := $(shell git rev-parse --short=8 --verify HEAD || echo unknown)
26-
LDFLAGS := -s -X main.gitDescription=${GITDESC} -X main.gitBranch=${GITBRANCH} -X main.gitHash=${GITHASH} -X "github.com/setlog/trivrost/cmd/launcher/launcher.buildTime=$(shell date -u "+%Y-%m-%d %H:%M:%S UTC")"
26+
LDFLAGS := -s -w -X main.gitDescription=${GITDESC} -X main.gitBranch=${GITBRANCH} -X main.gitHash=${GITHASH} -X "github.com/setlog/trivrost/cmd/launcher/launcher.buildTime=$(shell date -u "+%Y-%m-%d %H:%M:%S UTC")"
2727

2828
# Assume version is part of the tag. If not, default to v0.0.0
2929
VERSIONOK := $(shell echo -n "${LAUNCHER_VERSION}" | grep -E ^v[0-9]+\.[0-9]+\.[0-9]+$$ && echo ok)
@@ -68,13 +68,21 @@ export LAUNCHER_PROGRAM_EXT
6868
.PHONY: build bundle bundle-msi test copy-test-files generate clean sign dist help
6969

7070
# Default target
71-
build: generate ## Build (default)
71+
build: compile package
72+
73+
compile: generate ## Compile with go build. Run after make generate.
7274
ifeq (${OS},windows)
7375
# Removing unneeded PNG from Windows binary
7476
rm cmd/launcher/resources/icon.png.gen.go
7577
endif
7678
# See https://github.com/golang/go/issues/18400#issuecomment-270414574 for why -installsuffix is needed.
7779
go build -o "${UPDATE_FILES_DIR}/${OS}/${LAUNCHER_PROGRAM_NAME}${LAUNCHER_PROGRAM_EXT}" -v -installsuffix _separate -ldflags '${LDFLAGS}' ${MODULE_PATH_LAUNCHER}
80+
$(info # compile finished)
81+
82+
compress: ## Compress compiled binary with UPX. Needs to run after make compile, but before make sign.
83+
upx "${UPDATE_FILES_DIR}/${OS}/${LAUNCHER_PROGRAM_NAME}${LAUNCHER_PROGRAM_EXT}"
84+
85+
package:
7886
ifeq (${OS},darwin)
7987
# Mac bundle is special
8088
mkdir -p "${UPDATE_FILES_DIR}/${OS}/${LAUNCHER_PROGRAM_NAME}.app/Contents/MacOS"
@@ -83,7 +91,6 @@ ifeq (${OS},darwin)
8391
mkdir -p "${UPDATE_FILES_DIR}/${OS}/${LAUNCHER_PROGRAM_NAME}.app/Contents/Resources"
8492
if [ -f cmd/launcher/resources/icon.icns ]; then cp cmd/launcher/resources/icon.icns "${UPDATE_FILES_DIR}/${OS}/${LAUNCHER_PROGRAM_NAME}.app/Contents/Resources/icon.icns"; fi
8593
endif
86-
$(info # make build finished)
8794

8895
bundle: ## Bundle OS-specific files. Call after signing
8996
mkdir -p "${RELEASE_FILES_DIR}/${OS}"

docs/building.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ In this document, we will focus on how to get the project to build, i.e. success
1111
- [`go`](https://golang.org/) >= v1.13
1212
- [`goversioninfo`](https://github.com/josephspurrier/goversioninfo) (Make sure to add `$GOPATH/bin` to your `$PATH`)
1313
- [`make`](https://superuser.com/questions/352000/whats-a-good-way-to-install-build-essentials-all-common-useful-commands-on)
14+
- [`upx`](https://upx.github.io/)
1415
- `libgtk-3-dev`
1516

1617
## Building
@@ -26,6 +27,7 @@ In this document, we will focus on how to get the project to build, i.e. success
2627
- [`git`](https://git-scm.com/)
2728
- [`go`](https://golang.org/) >= v1.13
2829
- [`goversioninfo`](https://github.com/josephspurrier/goversioninfo) (Make sure to add `%GOPATH%\bin` to your `%PATH%`)
30+
- [`upx`](https://upx.github.io/)
2931

3032
## Further instructions
3133
1. Install [mingw-w64](https://mingw-w64.org) (specifically the [Mingw-builds](https://mingw-w64.org/doku.php/download/mingw-builds) package) as a recent GCC-compatible compiler.

0 commit comments

Comments
 (0)