Skip to content

Commit

Permalink
Fix Makefile build cmd to create static binaries
Browse files Browse the repository at this point in the history
The previous build command produces dynamic executables
instead of the intended (but not well noted in the Makefile)
static executables. This commit includes changes noted in
upstream `golang/go` issues which appear to work as intended
for others.

I also include doc comments and reference links describing
the use of the updated build options list and some problems
that I encountered during testing of `linkmode=external`.

- refs GH-92

- refs atc0005/check-mail#94
- refs atc0005/check-mail#95
- refs atc0005/check-mail#101

- refs golang/go 38789
- refs golang/go 26492
  • Loading branch information
atc0005 committed Oct 7, 2020
1 parent 51aa796 commit 5199302
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Makefile
Expand Up @@ -40,7 +40,41 @@ VERSION = $(shell git describe --always --long --dirty)

# The default `go build` process embeds debugging information. Building
# without that debugging information reduces the binary size by around 28%.
BUILDCMD = go build -mod=vendor -trimpath -a -ldflags="-s -w -X $(VERSION_VAR_PKG).version=$(VERSION)"
#
# We also include additional flags in an effort to generate static binaries
# that do not have external dependencies. As of Go 1.15 this still appears to
# be a mixed bag, so YMMV.
#
# See https://github.com/golang/go/issues/26492 for more information.
#
# -s
# Omit the symbol table and debug information.
#
# -w
# Omit the DWARF symbol table.
#
# -tags 'osusergo,netgo'
# Use pure Go implementation of user and group id/name resolution.
# Use pure Go implementation of DNS resolver.
#
# -extldflags '-static'
# Pass 'static' flag to external linker.
#
# -linkmode=external
# https://golang.org/src/cmd/cgo/doc.go
#
# NOTE: Using external linker requires installation of `gcc-multilib`
# package when building 32-bit binaries on a Debian/Ubuntu system. It also
# seems to result in an unstable build that crashes on startup. This *might*
# be specific to the WSL environment used for builds, but since this is a
# new issue and and I do not yet know much about this option, I am leaving
# it out.
#
# CGO_ENABLED=0
# https://golang.org/cmd/cgo/
# explicitly disable use of cgo
# removes potential need for linkage against local c library (e.g., glibc)
BUILDCMD = CGO_ENABLED=0 go build -mod=vendor -trimpath -a -ldflags "-s -w -X $(VERSION_VAR_PKG).version=$(VERSION)"
GOCLEANCMD = go clean -mod=vendor ./...
GITCLEANCMD = git clean -xfd
CHECKSUMCMD = sha256sum -b
Expand Down

0 comments on commit 5199302

Please sign in to comment.