From 0d682e24a1ba8e93e5e54a73d64f7d256f87492f Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 28 Nov 2017 17:49:39 -0800 Subject: [PATCH] plugins: don't compile for static build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can't really use `dlopen()` from a statically built binary, so let's disable this functionality if `static_build` tag is used (which is sort of a de-facto standard way of doing it). This eliminates the following warning: 🇩 bin/containerd # github.com/containerd/containerd/cmd/containerd /tmp/go-link-509179974/000004.o: In function `pluginOpen': /usr/local/go/src/plugin/plugin_dlopen.go:19: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking [v2: add static build instructions to BUILDING.md] Signed-off-by: Kir Kolyshkin --- BUILDING.md | 14 ++++++++++++++ plugin/plugin_go18.go | 2 +- plugin/plugin_other.go | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 9594fdfe4..327d0aaf8 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -43,6 +43,20 @@ You can move them in your global path with: sudo make install ``` +### Static binaries + +You can build static binaries by providing a few variables to `make`: + +```sudo +make EXTRA_FLAGS="-buildmode pie" \ + EXTRA_LDFLAGS='-extldflags "-fno-PIC -static"' \ + BUILDTAGS="static_build" +``` + +Note that + - static build is discouraged + - static containerd binary does not support plugins loading + ## Via Docker Container ### Build containerd diff --git a/plugin/plugin_go18.go b/plugin/plugin_go18.go index d9101246e..eee0e3fdb 100644 --- a/plugin/plugin_go18.go +++ b/plugin/plugin_go18.go @@ -1,4 +1,4 @@ -// +build go1.8,!windows,amd64 +// +build go1.8,!windows,amd64,!static_build package plugin diff --git a/plugin/plugin_other.go b/plugin/plugin_other.go index 21a457040..180917af8 100644 --- a/plugin/plugin_other.go +++ b/plugin/plugin_other.go @@ -1,4 +1,4 @@ -// +build !go1.8 windows !amd64 +// +build !go1.8 windows !amd64 static_build package plugin