Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/embed-cli-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"kit": patch
---

`shellcade-kit version` now reports the real release version instead of
`(devel)`/`(unknown)`. GoReleaser builds the binary with plain `go build`, so
`debug.ReadBuildInfo().Main.Version` was empty for the released artifact;
GoReleaser now stamps the tag into `main.version` via `-ldflags`, making the
"binary embeds the same kit version it ships under" claim true. In-tree
`go build`/`go run` is unchanged (still falls back to build info). No behavior
change for game authors.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ builds:
env: [CGO_ENABLED=0]
goos: [darwin, linux, windows]
goarch: [amd64, arm64]
ldflags: ["-s -w"]
ldflags: ["-s -w -X main.version={{.Version}}"]

archives:
- formats: [tar.gz]
Expand Down
16 changes: 16 additions & 0 deletions cmd/shellcade-kit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ import (
"github.com/shellcade/kit/v2/host/sdk"
)

// version is the binary's own version. GoReleaser overrides it via
// -ldflags "-X main.version={{.Version}}" so release binaries report the kit
// tag they ship under; in-tree `go build`/`go run` leaves it "dev" and
// printVersion falls back to the module version from build info.
var version = "dev"

func main() {
if len(os.Args) >= 2 && os.Args[1] == "version" {
printVersion()
Expand Down Expand Up @@ -117,6 +123,16 @@ func printVersion() {
}
}
}
// A real -ldflags value (the GoReleaser release path) wins over the empty
// bi.Main.Version that in-tree `go build` produces. Under lockstep the tag
// IS the kit module release, so the binary ships under that kit version too
// — adopt it for the kit line when build info couldn't supply one.
if version != "" && version != "dev" {
own = version
if kitv == "(unknown)" {
kitv = version
}
}
fmt.Printf("shellcade-kit %s\nkit %s (github.com/shellcade/kit/v2)\nabi v%d\n", own, kitv, gameabi.Version)
}

Expand Down
Loading