No version surface in the binary: embed the commit hash and expose it #47

Open
opened 2026-08-10 15:51:59 +02:00 by clawbot · 1 comment
Collaborator

Deliberately excluded from #19, which added make build, so it is filed here rather than lost.

The org Go styleguide wants the git commit hash embedded at build time (-X main.Version) and surfaced at startup. This repo has no version surface at all, so it is more than a linker flag.

Definition of done

  • A main.Version variable set via -ldflags -X from make build.
  • A decision, recorded in the code, on where it surfaces. The candidates are a startup line, a -v flag, and the score screen — but this is a faithful port of Rogue 5.4.4, so anything that changes what the player sees during a normal game is a divergence from C and needs justifying as one. A -v flag that exits immediately is the least invasive and is the presumed answer unless someone argues otherwise.
  • A sane fallback when the tree is dirty or there is no VCS (a plain go build with no ldflags must still produce a runnable binary, not an empty version string that reads as a bug).
  • make check green; TODO.md Completed Steps entry in the same commit; commit title ends (closes #N).

Priority

Low. No defect behind it, and it must not alter in-game display without a deliberate decision.

Deliberately excluded from https://git.eeqj.de/sneak/rgoue/issues/19, which added `make build`, so it is filed here rather than lost. The org Go styleguide wants the git commit hash embedded at build time (`-X main.Version`) and surfaced at startup. This repo has no version surface at all, so it is more than a linker flag. ## Definition of done - A `main.Version` variable set via `-ldflags -X` from `make build`. - A decision, recorded in the code, on where it surfaces. The candidates are a startup line, a `-v` flag, and the score screen — but this is a faithful port of Rogue 5.4.4, so anything that changes what the player sees during a normal game is a divergence from C and needs justifying as one. A `-v` flag that exits immediately is the least invasive and is the presumed answer unless someone argues otherwise. - A sane fallback when the tree is dirty or there is no VCS (a plain `go build` with no ldflags must still produce a runnable binary, not an empty version string that reads as a bug). - `make check` green; `TODO.md` Completed Steps entry in the same commit; commit title ends ` (closes #N)`. ## Priority Low. No defect behind it, and it must not alter in-game display without a deliberate decision.
Author
Collaborator

Plan. Ruling on where the version shows: a -v flag that prints it to stdout and exits 0, before the terminal is touched. Nothing changes in what the player sees during a game, so there is no departure from C.

  • make build sets main.Version with -ldflags "-X main.Version=..." from git rev-parse --short HEAD, with -dirty appended when the tree has uncommitted changes.
  • Fallback when main.Version was not set at link time (a plain build without the flag): use vcs.revision (and vcs.modified) from runtime/debug.ReadBuildInfo, and failing that a fixed word such as unknown. Never an empty string.
  • A test covers the fallback order. README.md documents -v next to -s and -d.
  • Runs after #25 (same file, cmd/rogue/main.go) and #42 (same Makefile) land.

Model: opus-5-5

Plan. Ruling on where the version shows: a `-v` flag that prints it to stdout and exits 0, before the terminal is touched. Nothing changes in what the player sees during a game, so there is no departure from C. - `make build` sets `main.Version` with `-ldflags "-X main.Version=..."` from `git rev-parse --short HEAD`, with `-dirty` appended when the tree has uncommitted changes. - Fallback when `main.Version` was not set at link time (a plain build without the flag): use `vcs.revision` (and `vcs.modified`) from `runtime/debug.ReadBuildInfo`, and failing that a fixed word such as `unknown`. Never an empty string. - A test covers the fallback order. `README.md` documents `-v` next to `-s` and `-d`. - Runs after https://git.eeqj.de/sneak/rgoue/issues/25 (same file, `cmd/rogue/main.go`) and https://git.eeqj.de/sneak/rgoue/issues/42 (same `Makefile`) land. Model: opus-5-5
Sign in to join this conversation.