Add -w -s to ldflags when compiling for release
By default, when compiling cloudflared via make, we can strip the symbol table and DWARF debugging information from the binary. This results in an approximately 10Mb reduction in file size, with no impact on execution. If you need to run cloudflared through a debugger and need the DWARF/symbol table information, you can run `make cloudflared DEBUG=true` to use the previous behaviour.
This commit is contained in:
parent
6dad2bf9c4
commit
0615741643
14
Makefile
14
Makefile
|
@ -1,6 +1,6 @@
|
||||||
VERSION := $(shell git describe --tags --always --dirty="-dev" --match "[0-9][0-9][0-9][0-9].*.*")
|
VERSION := $(shell git describe --tags --always --dirty="-dev" --match "[0-9][0-9][0-9][0-9].*.*")
|
||||||
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
|
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
|
||||||
VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
|
LD_FLAGS := -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"
|
||||||
MSI_VERSION := $(shell git tag -l --sort=v:refname | grep "w" | tail -1 | cut -c2-)
|
MSI_VERSION := $(shell git tag -l --sort=v:refname | grep "w" | tail -1 | cut -c2-)
|
||||||
#MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
|
#MSI_VERSION expects the format of the tag to be: (wX.X.X). Starts with the w character to not break cfsetup.
|
||||||
#e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
|
#e.g. w3.0.1 or w4.2.10. It trims off the w character when creating the MSI.
|
||||||
|
@ -62,6 +62,10 @@ else
|
||||||
TARGET_PUBLIC_REPO ?= $(FLAVOR)
|
TARGET_PUBLIC_REPO ?= $(FLAVOR)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(DEBUG), true)
|
||||||
|
LD_FLAGS += -w -s
|
||||||
|
endif
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: cloudflared test
|
all: cloudflared test
|
||||||
|
|
||||||
|
@ -71,7 +75,7 @@ clean:
|
||||||
|
|
||||||
.PHONY: cloudflared
|
.PHONY: cloudflared
|
||||||
cloudflared: tunnel-deps
|
cloudflared: tunnel-deps
|
||||||
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -v -mod=vendor $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared
|
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -v -mod=vendor -ldflags='$(LD_FLAGS)' $(IMPORT_PATH)/cmd/cloudflared
|
||||||
|
|
||||||
.PHONY: container
|
.PHONY: container
|
||||||
container:
|
container:
|
||||||
|
@ -79,7 +83,7 @@ container:
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: vet
|
test: vet
|
||||||
go test -v -mod=vendor -race $(VERSION_FLAGS) ./...
|
go test -v -mod=vendor -race -ldflags='$(LD_FLAGS)' ./...
|
||||||
|
|
||||||
.PHONY: test-ssh-server
|
.PHONY: test-ssh-server
|
||||||
test-ssh-server:
|
test-ssh-server:
|
||||||
|
@ -190,7 +194,7 @@ homebrew-release: homebrew-upload
|
||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release: bin/equinox
|
release: bin/equinox
|
||||||
bin/equinox release $(EQUINOX_FLAGS) -- $(VERSION_FLAGS) $(IMPORT_PATH)/cmd/cloudflared
|
bin/equinox release $(EQUINOX_FLAGS) -- -ldflags='$(LD_FLAGS)' $(IMPORT_PATH)/cmd/cloudflared
|
||||||
|
|
||||||
.PHONY: github-release
|
.PHONY: github-release
|
||||||
github-release: cloudflared
|
github-release: cloudflared
|
||||||
|
@ -225,4 +229,4 @@ vet:
|
||||||
|
|
||||||
.PHONY: msi
|
.PHONY: msi
|
||||||
msi: cloudflared
|
msi: cloudflared
|
||||||
go-msi make --msi cloudflared.msi --version $(MSI_VERSION)
|
go-msi make --msi cloudflared.msi --version $(MSI_VERSION)
|
||||||
|
|
Loading…
Reference in New Issue