File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,14 +122,13 @@ Please refer to [RUNC.md](/docs/RUNC.md) for the currently supported version of
122122You can build static binaries by providing a few variables to ` make ` :
123123
124124``` sh
125- make EXTRA_FLAGS=" -buildmode pie" \
126- EXTRA_LDFLAGS=' -linkmode external -extldflags "-fno-PIC -static"' \
127- BUILDTAGS=" netgo osusergo static_build"
125+ make STATIC=1
128126```
129127
130128> * Note* :
131129> - static build is discouraged
132130> - static containerd binary does not support loading shared object plugins (` *.so ` )
131+ > - static build binaries are not position-independent
133132
134133# Via Docker container
135134
Original file line number Diff line number Diff line change 9090GO_BUILDTAGS ?=
9191GO_BUILDTAGS += urfave_cli_no_docs
9292GO_BUILDTAGS += ${DEBUG_TAGS}
93+ ifneq ($(STATIC ) ,)
94+ GO_BUILDTAGS += osusergo netgo static_build
95+ endif
9396GO_TAGS =$(if $(GO_BUILDTAGS ) ,-tags "$(strip $(GO_BUILDTAGS ) ) ",)
94- GO_LDFLAGS =-ldflags '-X $(PKG ) /version.Version=$(VERSION ) -X $(PKG ) /version.Revision=$(REVISION ) -X $(PKG ) /version.Package=$(PACKAGE ) $(EXTRA_LDFLAGS ) '
97+
98+ GO_LDFLAGS =-ldflags '-X $(PKG ) /version.Version=$(VERSION ) -X $(PKG ) /version.Revision=$(REVISION ) -X $(PKG ) /version.Package=$(PACKAGE ) $(EXTRA_LDFLAGS )
99+ ifneq ($(STATIC ) ,)
100+ GO_LDFLAGS += -extldflags "-static"
101+ endif
102+ GO_LDFLAGS+ ='
103+
95104SHIM_GO_LDFLAGS =-ldflags '-X $(PKG ) /version.Version=$(VERSION ) -X $(PKG ) /version.Revision=$(REVISION ) -X $(PKG ) /version.Package=$(PACKAGE ) -extldflags "-static" $(EXTRA_LDFLAGS ) '
96105
97106# Project packages.
Original file line number Diff line number Diff line change @@ -21,7 +21,9 @@ COMMANDS += containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2
2121# check GOOS for cross compile builds
2222ifeq ($(GOOS),linux)
2323 ifneq ($(GOARCH),$(filter $(GOARCH),mips mipsle mips64 mips64le ppc64))
24- GO_GCFLAGS += -buildmode=pie
24+ ifeq ($(STATIC),)
25+ GO_GCFLAGS += -buildmode=pie
26+ endif
2527 endif
2628endif
2729
You can’t perform that action at this time.
0 commit comments