Skip to content

Commit 3f92763

Browse files
committed
Enhance Makefile and version settings for build-time injection
1 parent 287b057 commit 3f92763

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

farcaster-go/Makefile

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ PLATFORMS=linux/arm64,linux/amd64
44
VER_MAJOR=$(shell echo ${VERSION} | awk -F'.' '{print $$1}')
55
VER_MINOR=$(shell echo ${VERSION} | awk -F'.' '{print $$2}')
66

7+
COMMIT=$(shell git rev-parse --short HEAD)
78
COMPAT_IMAGE=${NAME}-linux-compat
8-
LDFLAGS=-ldflags "-X main.Version=v${VERSION}"
9+
LDFLAGS=-ldflags "-X probely.com/farcaster/settings.Version=${VERSION} -X probely.com/farcaster/settings.Commit=${COMMIT}"
910
GOFILES := $(shell find . -name '*.go')
1011

1112
.DEFAULT_GOAL: $(NAME)
@@ -19,12 +20,6 @@ fmt:
1920
vet: fmt
2021
go vet ./...
2122

22-
version: check-env
23-
@echo '// This file was auto-generated by "make version". Do not change it directly!' > settings/version.go
24-
@echo >> settings/version.go
25-
@echo 'package settings' >> settings/version.go
26-
@echo 'const Version = "${VERSION}"' >> settings/version.go
27-
2823
linux-compat: linux-compat-build linux-compat-extract
2924

3025
linux-compat-build:
@@ -38,15 +33,15 @@ linux-compat-extract: linux-compat-build
3833
done
3934
docker rm ${NAME}-tmp-container
4035

41-
windows: version
36+
windows:
4237
GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o bin/${NAME}-windows-amd64.exe
4338
GOOS=windows GOARCH=arm64 go build ${LDFLAGS} -o bin/${NAME}-windows-arm64.exe
4439

45-
linux: version
40+
linux:
4641
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o bin/${NAME}-linux-amd64
4742
GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o bin/${NAME}-linux-arm64
4843

49-
darwin: version
44+
darwin:
5045
GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o bin/${NAME}-darwin-amd64
5146
GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o bin/${NAME}-darwin-arm64
5247

@@ -76,5 +71,5 @@ endif
7671
@# VERSION must be a valid semver
7772
@echo ${VERSION} | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$' || (echo "VERSION must be a valid semver" && exit 1)
7873

79-
.PHONY: version windows linux linux-compat linux-compat-build linux-compat-extract darwin lint
80-
.PHONY: docker docker-clean docker-prepare version
74+
.PHONY: windows linux linux-compat linux-compat-build linux-compat-extract darwin lint
75+
.PHONY: docker docker-clean docker-prepare

farcaster-go/settings/version.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// This file was auto-generated by "make version". Do not change it directly!
22

33
package settings
4-
const Version = "0.0.0"
4+
5+
// Version and Commit are injected at build time via linker flags.
6+
var (
7+
// Version holds the semantic version of the build (e.g. "1.2.3").
8+
Version string = "dev"
9+
10+
// Commit is the short git commit hash corresponding to this build.
11+
Commit string = "none"
12+
)

0 commit comments

Comments
 (0)