Skip to content

Commit ecc10ab

Browse files
authored
chore(envd): minimize binary size with build-flag tweaks (#2664)
Adds `-trimpath`, `-buildvcs=false`, `-buildid=` and `-s -w` to the prod `envd` build. Effect: drops debug paths, VCS metadata, and the linker build ID from the binary. No runtime cost (Go's pclntab is untouched, so panics/pprof/stack traces still resolve names + lines), smaller mmap'd footprint, and reproducible builds across machines. `build-debug` is intentionally unaffected.
1 parent 9481380 commit ecc10ab

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

packages/envd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ENV := $(shell cat ../../.last_used_env || echo "not-set")
33

44
BUILD := $(shell git rev-parse --short HEAD)
55
LDFLAGS=-ldflags "-X=main.commitSHA=$(BUILD)"
6+
PROD_LDFLAGS=-ldflags "-X=main.commitSHA=$(BUILD) -s -w -buildid="
67

78
AWS_BUCKET_PREFIX ?= $(PREFIX)$(AWS_ACCOUNT_ID)-
89
GCP_BUCKET_PREFIX ?= $(GCP_PROJECT_ID)-
@@ -27,7 +28,7 @@ else
2728
endif
2829

2930
build:
30-
CGO_ENABLED=0 GOOS=linux GOARCH=$(BUILD_ARCH) go build -a -o bin/envd ${LDFLAGS}
31+
CGO_ENABLED=0 GOOS=linux GOARCH=$(BUILD_ARCH) go build -trimpath -buildvcs=false -a -o bin/envd ${PROD_LDFLAGS}
3132

3233
build-debug:
3334
CGO_ENABLED=1 go build -race -gcflags=all="-N -l" -o bin/debug/envd ${LDFLAGS}

0 commit comments

Comments
 (0)