File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,17 @@ gobuildmaybe() {
119119
120120 local workdir=" $( pwd) "
121121
122+ local ldFlagsAdditional=" "
123+ if [ " ${BUILDOPT_DEBUG:- } " = " " ]; then # not doing debug build?
124+ # https://www.codingexplorations.com/blog/reducing-binary-size-in-go-strip-unnecessary-data-with-ldflags-w-s
125+ # where:
126+ # -w: This flag omits the DWARF symbol table, effectively removing debugging information.
127+ # -s: This strips the symbol table and debug information from the binary.
128+ #
129+ # ldflags go to `$ go tool link`. you can see these flags by running that command to see help.
130+ ldFlagsAdditional=" -w -s"
131+ fi
132+
122133 # NOTE: setting the "dynversion.Version" doesn't work when code under vendor/, but seems
123134 # to work now fine with Go modules. https://github.com/golang/go/issues/19000
124135
@@ -129,7 +140,7 @@ gobuildmaybe() {
129140
130141 # compile statically so this works on Alpine Linux that doesn't have glibc
131142 (cd " $dir_in_which_to_compile " && GOARM=6 GOOS=" $os " GOARCH=" $architecture " CGO_ENABLED=0 go build \
132- -ldflags " -extldflags \" -static\" -X github.com/function61/gokit/app/dynversion.Version=$FRIENDLY_REV_ID " \
143+ -ldflags " $ldFlagsAdditional -extldflags \" -static\" -X github.com/function61/gokit/app/dynversion.Version=$FRIENDLY_REV_ID " \
133144 -o " $projectroot /rel/${BINARY_NAME}${binSuffix} " )
134145}
135146
You can’t perform that action at this time.
0 commit comments