From eb0dd6344ff81e7508ec3fea9d2e0be11702d2b6 Mon Sep 17 00:00:00 2001 From: hub Date: Sat, 10 Sep 2022 00:23:14 +0200 Subject: [PATCH] embed version with linker --- Makefile | 13 +++++++------ buildinfo/version.go | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 buildinfo/version.go diff --git a/Makefile b/Makefile index 37f14a8..262ea8d 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,18 @@ MOD_NAME = $(shell go list -m) BIN_NAME = $(shell basename $(MOD_NAME)) +LDFLAGS = "-X '$(MOD_NAME)/buildinfo.Version=$(shell git describe --tags 2> /dev/null || echo "devel")'" out/$(BIN_NAME)-dev: clean lint test mkdir -p out - go build -race -o $@ + go build -ldflags=$(LDFLAGS) -race -o $@ release: clean mkdir -p out - GOOS=linux GOARCH=amd64 go build -o out/$(BIN_NAME)-linux - GOOS=linux GOARCH=arm64 go build -o out/$(BIN_NAME)-linux-arm64 - GOOS=darwin GOARCH=amd64 go build -o out/$(BIN_NAME)-darwin - GOOS=darwin GOARCH=arm64 go build -o out/$(BIN_NAME)-darwin-arm64 - GOOS=windows GOARCH=amd64 go build -o out/$(BIN_NAME)-windows.exe + GOOS=linux GOARCH=amd64 go build -ldflags=$(LDFLAGS) -o out/$(BIN_NAME)-linux + GOOS=linux GOARCH=arm64 go build -ldflags=$(LDFLAGS) -o out/$(BIN_NAME)-linux-arm64 + GOOS=darwin GOARCH=amd64 go build -ldflags=$(LDFLAGS) -o out/$(BIN_NAME)-darwin + GOOS=darwin GOARCH=arm64 go build -ldflags=$(LDFLAGS) -o out/$(BIN_NAME)-darwin-arm64 + GOOS=windows GOARCH=amd64 go build -ldflags=$(LDFLAGS) -o out/$(BIN_NAME)-windows.exe README.md: out/$(BIN_NAME)-dev @echo "# $(BIN_NAME)" > README.md diff --git a/buildinfo/version.go b/buildinfo/version.go new file mode 100644 index 0000000..cf352ee --- /dev/null +++ b/buildinfo/version.go @@ -0,0 +1,3 @@ +package buildinfo + +var Version = "?"