Distribute static binaries
xbt573 opened this issue · 2 comments
gonic version: v0.16.4
docker tag: latest
Actually this is irrelevant to issue, but nevermind.
-
Building go-sqlite3 statically is very easy, just pass
-ldflags '-linkmode external -extldflags "-static"'
togo build
-
taglib requires static rebuild and some code changes, but nothing very hard
Firstly we need to build taglib as static library: pass-DBUILD_SHARED_LIBS=OFF
tocmake
(this is confusing, but disabling shared libraries enables static :/)
Static zlib is also needed, which is not always bundled with system package (on alpine usezlib-static
)
Needed code change is at https://github.com/sentriz/audiotags/blob/master/audiotags.go#L25: addzlib
to pkg-config
--- a/audiotags.go
+++ b/audiotags.go
@@ -22,7 +22,7 @@
package audiotags
/*
-#cgo pkg-config: taglib
+#cgo pkg-config: taglib zlib
#cgo LDFLAGS: -lstdc++
#include "audiotags.h"
#include <stdlib.h>
Final build command is:
go build -ldflags '-linkmode external -extldflags "-static"' -o gonic cmd/gonic/gonic.go
ldd
shows:
/lib/ld-musl-x86_64.so.1: gonic: Not a valid dynamic program
(whole process was made in alpine
docker image)
I didn't send PR because this is mostly untested (at least i could build it statically)
thanks! ill try this