Skip to content

Commit

Permalink
embed version with linker
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Sep 9, 2022
1 parent c375eab commit eb0dd63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions buildinfo/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package buildinfo

var Version = "?"

0 comments on commit eb0dd63

Please sign in to comment.