This is a proposal to add -static flag to go build.
Producing a static build with go already requires a non-trivial amount of flags passed to go build, which on Linux currently amounts to something like:
-ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build' [1]
...and this magic string keeps growing.
It would be awesome to encapsulate this sacred knowledge internally, exposing it via a new -static flag for go build and friends.
In addition to the above benefit of hiding the complexity, -static can also bring us more niceties, such as:
- automatic
static build tag third-party software can rely upon. Currently using static_build tag seems like a de-facto standard, used a lot, but it has to be explicitly defined like in [1] above.
- providing
--static flag to pkg-config invocations (those initiated by // #cgo pkg-config: lib lines in the source code). It will solve another issue (linking against a proper set of libraries for both static and dynamic link cases) for which a somewhat verbose workaround is currently required (for example, see ploop_link_static.go and ploop_link_dynamic.go).
See also
This is a proposal to add
-staticflag togo build.Producing a static build with go already requires a non-trivial amount of flags passed to
go build, which on Linux currently amounts to something like:-ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build'[1]...and this magic string keeps growing.
It would be awesome to encapsulate this sacred knowledge internally, exposing it via a new
-staticflag forgo buildand friends.In addition to the above benefit of hiding the complexity,
-staticcan also bring us more niceties, such as:staticbuild tag third-party software can rely upon. Currently usingstatic_buildtag seems like a de-facto standard, used a lot, but it has to be explicitly defined like in [1] above.--staticflag topkg-configinvocations (those initiated by// #cgo pkg-config: liblines in the source code). It will solve another issue (linking against a proper set of libraries for both static and dynamic link cases) for which a somewhat verbose workaround is currently required (for example, see ploop_link_static.go and ploop_link_dynamic.go).See also
--statictopkg-config)