diff --git a/Makefile b/Makefile index f9045df615a..cd6efced4ce 100644 --- a/Makefile +++ b/Makefile @@ -21,9 +21,9 @@ ifeq ($(shell $(GO) env GOOS),linux) endif endif GO_BUILD := $(GO) build -trimpath $(GO_BUILDMODE) $(EXTRA_FLAGS) -tags "$(BUILDTAGS)" \ - -ldflags "-X main.gitCommit=$(COMMIT) -X main.version=$(VERSION) $(EXTRA_LDFLAGS)" + -ldflags "-X main.gitCommit=$(COMMIT) $(EXTRA_LDFLAGS)" GO_BUILD_STATIC := CGO_ENABLED=1 $(GO) build -trimpath $(EXTRA_FLAGS) -tags "$(BUILDTAGS) netgo osusergo" \ - -ldflags "-extldflags -static -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION) $(EXTRA_LDFLAGS)" + -ldflags "-extldflags -static -X main.gitCommit=$(COMMIT) $(EXTRA_LDFLAGS)" GPG_KEYID ?= asarai@suse.de diff --git a/main.go b/main.go index 56a6066f8c5..6c11ab790b8 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + _ "embed" "errors" "fmt" "io" @@ -17,9 +18,9 @@ import ( "github.com/urfave/cli" ) -// version must be set from the contents of VERSION file by go build's -// -X main.version= option in the Makefile. -var version = "unknown" +// version is automatically set from the contents of VERSION file on go1.16+. +//go:embed VERSION +var version string // gitCommit will be the hash that the binary was built from // and will be populated by the Makefile @@ -57,7 +58,7 @@ func main() { app.Name = "runc" app.Usage = usage - v := []string{version} + v := []string{strings.TrimSpace(version)} if gitCommit != "" { v = append(v, "commit: "+gitCommit)