From 9930f98f8e3624dcdde2805a40c613b1570c2bec Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 22 Jun 2019 22:07:58 +0000 Subject: [PATCH] Compress binaries after building them (#81) --- .drone1.yml | 24 ++++++++++++++++++++---- Makefile | 9 +++++++++ docs/content/doc/development/make.md | 14 ++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.drone1.yml b/.drone1.yml index 7b87d86e..9ee35789 100644 --- a/.drone1.yml +++ b/.drone1.yml @@ -186,13 +186,21 @@ steps: - make release-darwin depends_on: [ before-static-build ] - - name: after-build-static - image: techknowlogick/xgo:latest + - name: after-build-compress + image: kolaente/upx pull: true depends_on: - static-build-windows - static-build-linux - static-build-darwin + commands: + - make release-compress + + - name: after-build-static + image: techknowlogick/xgo:latest + pull: true + depends_on: + - after-build-compress commands: - make release-copy - make release-check @@ -383,13 +391,21 @@ steps: - make release-darwin depends_on: [ before-static-build ] - - name: after-build-static - image: techknowlogick/xgo:latest + - name: after-build-compress + image: kolaente/upx pull: true depends_on: - static-build-windows - static-build-linux - static-build-darwin + commands: + - make release-compress + + - name: after-build-static + image: techknowlogick/xgo:latest + pull: true + depends_on: + - after-build-compress commands: - make release-copy - make release-check diff --git a/Makefile b/Makefile index d4f3a6ef..7276bd55 100644 --- a/Makefile +++ b/Makefile @@ -98,6 +98,10 @@ build: $(EXECUTABLE) $(EXECUTABLE): $(SOURCES) go build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@ +.PHONY: compress-build +compress-build: + upx -9 $(EXECUTABLE) + .PHONY: release release: release-dirs release-windows release-linux release-darwin release-copy release-check release-os-package release-zip @@ -135,6 +139,11 @@ ifneq ($(DRONE_WORKSPACE),'') mv /build/* $(DIST)/binaries endif +# Compresses all releases made by make release-* but not mips* releases since upx can't handle these. +.PHONY: release-compress +release-compress: + $(foreach file,$(filter-out $(wildcard $(wildcard $(DIST)/binaries/$(EXECUTABLE)-*mips*)),$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*)), upx -9 $(file);) + .PHONY: release-copy release-copy: $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));) diff --git a/docs/content/doc/development/make.md b/docs/content/doc/development/make.md index d0a750b8..b875035b 100644 --- a/docs/content/doc/development/make.md +++ b/docs/content/doc/development/make.md @@ -64,10 +64,19 @@ make build Builds a `vikunja`-binary in the root directory of the repo for the platform it is run on. +### Compress the built binary + +{{< highlight bash >}} +make compress-build +{{< /highlight >}} + +Go binaries are very big. +To make the vikunja binary smaller, we can compress it using [upx](https://upx.github.io/). + ### Build Releases {{< highlight bash >}} -make build +make release {{< /highlight >}} Builds binaries for all platforms and zips them with a copy of the `templates/` folder. @@ -75,7 +84,7 @@ All built zip files are stored into `dist/zips/`. Binaries are stored in `dist/b binaries bundled with `templates` are stored in `dist/releases/`. All cross-platform binaries built using this series of commands are built with the help of -[xgo](https://github.com/karalabe/xgo). The make command will automatically install the +[xgo](https://github.com/techknowlogick/xgo). The make command will automatically install the binary to be able to use it. `make release` is actually just a shortcut to execute `make release-dirs release-windows release-linux release-darwin release-copy release-check release-os-package release-zip`. @@ -85,6 +94,7 @@ binary to be able to use it. * `release-copy` bundles binaries with a copy of `templates/` to then be zipped * `release-check` creates sha256 checksums for each binary which will be included in the zip file * `release-os-package` bundles a binary with a copy of the `templates/` folder, the `sha256` checksum file, a sample `config.yml` and a copy of the license in a folder for each architecture +* `release-compress` compresses all build binaries, see `compress-build` * `release-zip` makes a zip file for the files created by `release-os-package` ### Build debian packages