feat: embed build version info in binaries

This commit is contained in:
2026-03-02 19:16:53 +08:00
parent 489c2d191c
commit 676a6e659a
4 changed files with 36 additions and 4 deletions

24
Makefile Normal file
View File

@@ -0,0 +1,24 @@
APP=inps
VERSION ?= 0.1.0
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GO_VERSION := $(shell go env GOVERSION 2>/dev/null || echo unknown)
LDFLAGS := -s -w \
-X 'github.com/openp2p-cn/inp2p/pkg/config.Version=$(VERSION)' \
-X 'github.com/openp2p-cn/inp2p/pkg/config.GitCommit=$(GIT_COMMIT)' \
-X 'github.com/openp2p-cn/inp2p/pkg/config.BuildTime=$(BUILD_TIME)' \
-X 'github.com/openp2p-cn/inp2p/pkg/config.GoVersion=$(GO_VERSION)'
.PHONY: build build-client build-server
build: build-client build-server
build-client:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" -o bin/inp2pc ./cmd/inp2pc
build-server:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -ldflags "$(LDFLAGS)" -o bin/inp2ps ./cmd/inp2ps