Skip to content

feat: show commit hash, branch, commit count and build date in --version - #34

Merged
Kinflou merged 1 commit into
mainfrom
feat/version-build-info
Oct 3, 2026
Merged

Kinflou merged 1 commit into
mainfrom
feat/version-build-info

Conversation

@Kinflou

@Kinflou Kinflou commented Oct 3, 2026

Copy link
Copy Markdown
Member

Summary

comline -V stays the bare CARGO_PKG_VERSION. comline --version now also shows:

comline 0.2.0
commit-hash: d9ccd73b35ac
commit-branch: main
commit-count: 78
build-date: 2026-10-03T13:26:54Z

(-dirty appended to the hash when the working tree had uncommitted changes at build time.)

  • build.rs's new emit_version_info captures these via git/date at build time (cargo:rustc-env=...), degrading each field independently to "unknown" rather than failing the build — a source tarball with no .git, or a machine with no git/date on PATH, still produces a working binary.
  • The string itself is built at runtime in main.rs (via option_env!, never a hard env!), not through the #[command(long_version = ...)] derive attribute — build.rs itself compiles src/cli.rs via #[path] for man-page/completion generation, before it has emitted these env vars for the real binary, so a const baked in by that attribute would need env! there too and hard-fail that earlier compilation.

Test plan

  • cargo build / cargo test — clean, 46 tests passing
  • Manual: comline -V vs comline --version — confirmed the split above
  • Confirmed man-page/shell-completion generation (build.rs's original job) still works

comline -V stays the bare CARGO_PKG_VERSION. comline --version now also
shows:

  commit-hash: d9ccd73(-dirty)
  commit-branch: main
  commit-count: 78
  build-date: 2026-10-03T13:26:54Z

build.rs's new emit_version_info captures these via git/date at build
time (cargo:rustc-env=...), degrading each independently to "unknown"
rather than failing the build - a source tarball with no .git, or a
machine with no git/date on PATH, still produces a working binary.
"-dirty" is appended to the hash when `git status --porcelain` is
non-empty at build time.

The long_version string is built at runtime in main.rs (via
option_env!, never a hard env!) rather than through the
#[command(long_version = ...)] derive attribute on Cli - build.rs
itself compiles src/cli.rs via #[path] for man-page/completion
generation, before it has emitted these env vars for the real binary,
so a const baked in by that attribute would need env! there too and
hard-fail that earlier compilation.
@Kinflou
Kinflou merged commit 2e54fda into main Oct 3, 2026
1 of 2 checks passed
@Kinflou
Kinflou deleted the feat/version-build-info branch October 3, 2026 13:30
Kinflou pushed a commit that referenced this pull request Oct 3, 2026
Slipped through in the --version feature (#34) - this repo's CI runs
cargo fmt --check, caught here when it ran on this PR's otherwise-
unrelated branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant