Skip to content

feat: implement vergen crate for git-based versioning#21

Merged
nerdCopter merged 1 commit into
masterfrom
20251204_vergen
Dec 4, 2025
Merged

feat: implement vergen crate for git-based versioning#21
nerdCopter merged 1 commit into
masterfrom
20251204_vergen

Conversation

@nerdCopter
Copy link
Copy Markdown
Owner

@nerdCopter nerdCopter commented Dec 4, 2025

Overview

Implement dynamic versioning using the vergen crate to embed git commit information at build time.

Changes

  • Versioning: Replace hardcoded semantic version (0.9.0) with dynamic git-based version

    • Format: bbl_parser <short-sha> (<date>)
    • Example: bbl_parser 14be1ee (2025-12-04)
  • Build Integration: Add vergen crate as build dependency

    • Emits VERGEN_GIT_SHA (short form) and VERGEN_GIT_COMMIT_DATE
    • Uses gitcl backend for minimal external dependencies
  • CLI Output: Update both help and version displays

    • -V flag shows: version string with short SHA and date
    • Help text includes same version info for consistency
    • Package name derived from CARGO_PKG_NAME macro
  • Documentation: Remove hardcoded version references

    • README.md: Remove work-in-progress marker
    • OVERVIEW.md: Remove version 0.9.0 references
  • Git Configuration: Add build.rs to gitignore whitelist

Benefits

  • Accurate versioning: Version always reflects actual git commit
  • No manual updates: Version automatically updates on rebuild
  • Consistent identity: Uses TOML package name for reliability
  • Minimal overhead: Build script runs only when needed

Testing

✅ All 38 tests pass
✅ Formatting complies (cargo fmt)
✅ Clippy checks pass (no warnings)
✅ Release build successful

Files Changed

  • build.rs (new) - Vergen build script configuration
  • Cargo.toml - Added vergen dependencies
  • src/main.rs - Updated version string generation
  • .gitignore - Whitelisted build.rs
  • README.md, OVERVIEW.md - Removed version references

Summary by CodeRabbit

  • Documentation

    • README title updated; removed work-in-progress status indicator
    • Project overview documentation heading simplified
    • Removed version-specific content and status notes from documentation
  • Improvements

    • Application version display now includes Git commit SHA and date details
    • Build-time metadata generation implemented for enhanced build traceability
    • Version information automatically generated during compilation

✏️ Tip: You can customize this high-level summary in your review settings.

- Add vergen build dependency with git and gitcl features
- Create build.rs to emit VERGEN_GIT_SHA and VERGEN_GIT_COMMIT_DATE
- Update version output to use short SHA and date (e.g., bbl_parser 14be1ee (2025-12-04))
- Use CARGO_PKG_NAME macro for package name consistency
- Remove hardcoded semantic version references from documentation
- Update .gitignore to whitelist build.rs
- Version now reflects actual git commit info at build time
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 4, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a build-time Git metadata system using the vergen crate. Changes include adding a build script (build.rs) to emit Git SHA and commit date during compilation, updating Cargo.toml with build dependencies, and modifying src/main.rs to incorporate this metadata into the CLI version display. Documentation is updated to remove version-specific references.

Changes

Cohort / File(s) Summary
Build System Configuration
.gitignore, Cargo.toml
Added build.rs to .gitignore whitelist; introduced [build-dependencies] section with anyhow = "1.0" and vergen = { version = "8", features = ["git", "gitcl"] }
Build Script Implementation
build.rs
New Rust build script using anyhow::Result and vergen::EmitBuilder to generate compile-time Git metadata (SHA and commit date) with error handling
CLI Metadata Integration
src/main.rs
Added vergen-generated constants (GIT_SHA, GIT_COMMIT_DATE, VERSION_STR); reworked CLI command to use env!("CARGO_PKG_NAME"), computed version string, and formatted about text with Git information
Documentation Updates
OVERVIEW.md, README.md
Removed version-specific references and work-in-progress status; updated titles from "v0.9.0" and "(Work-in-Progress)" to neutral forms

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • build.rs: Verify vergen::EmitBuilder configuration correctly emits git SHA and commit date; confirm error handling flow and that emit() properly propagates metadata
  • Cargo.toml: Confirm vergen version 8 and feature flags (["git", "gitcl"]) are appropriate; validate anyhow dependency is correctly specified
  • src/main.rs: Review how environment variables injected by build.rs are consumed (e.g., env!() calls); ensure VERSION_STR computation is correct and about_text formatting includes all intended metadata
  • Build integration: Verify the build script is triggered automatically and metadata is consistently available during compilation

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing git-based versioning via the vergen crate, which is the central focus of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 20251204_vergen

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14be1ee and ae20354.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • Cargo.toml (1 hunks)
  • OVERVIEW.md (1 hunks)
  • README.md (1 hunks)
  • build.rs (1 hunks)
  • src/main.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
README.md

📄 CodeRabbit inference engine (AGENTS.md)

Maintain a proper README.md

Files:

  • README.md
{src/**/*.rs,Cargo.*,README.md,OVERVIEW.md,.gitignore,.github/**}

📄 CodeRabbit inference engine (AGENTS.md)

Only commit changes to src/**/*.rs, Cargo.*, README.md, OVERVIEW.md, .gitignore, and .github/**; never use git add . or git add -A

Files:

  • README.md
  • OVERVIEW.md
  • Cargo.toml
  • .gitignore
  • src/main.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Do not remove or modify comments unless the related code is changed
Only add comments that explain code functionality; do not add AI instructional comments
Never embed or call external binaries from Rust code

Files:

  • build.rs
  • src/main.rs
OVERVIEW.md

📄 CodeRabbit inference engine (AGENTS.md)

Maintain a proper OVERVIEW.md

Files:

  • OVERVIEW.md
src/main.rs

📄 CodeRabbit inference engine (AGENTS.md)

Maintain the application entry point at src/main.rs

Files:

  • src/main.rs
🧠 Learnings (12)
📓 Common learnings
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: README.md:0-0
Timestamp: 2025-08-29T19:55:43.912Z
Learning: nerdCopter updated the bbl_parser project license from GPL-3.0-or-later to AGPL-3.0-or-later across all repository files (Cargo.toml, LICENSE, README.md) for consistency with the dual-licensing approach that includes a commercial license option.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: LICENSE_COMMERCIAL:1-4
Timestamp: 2025-08-29T19:52:05.099Z
Learning: nerdCopter prefers to avoid publishing personal information in license files for privacy and security reasons, as they are an individual maintainer rather than a company.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: README.md:520-521
Timestamp: 2025-08-29T19:53:41.354Z
Learning: nerdCopter uses AGPL-3.0-or-later licensing for the bbl_parser project with a dual-licensing approach that includes a separate commercial license option.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: CONTRIBUTING.md:9-14
Timestamp: 2025-08-21T20:25:45.741Z
Learning: nerdCopter prefers to keep CLA language general using "project maintainer" rather than specifying a legal entity name, as they are an individual maintainer without an associated company.
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: LICENSE_COMMERCIAL:0-0
Timestamp: 2025-08-29T20:15:04.624Z
Learning: nerdCopter prefers clear positive indicators (✅) when describing fixes rather than using ❌ symbols which can be confusing when describing what was corrected in a positive context.
📚 Learning: 2025-08-29T19:55:43.912Z
Learnt from: nerdCopter
Repo: nerdCopter/bbl_parser PR: 2
File: README.md:0-0
Timestamp: 2025-08-29T19:55:43.912Z
Learning: nerdCopter updated the bbl_parser project license from GPL-3.0-or-later to AGPL-3.0-or-later across all repository files (Cargo.toml, LICENSE, README.md) for consistency with the dual-licensing approach that includes a commercial license option.

Applied to files:

  • README.md
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Applies to **/*.rs : Never embed or call external binaries from Rust code

Applied to files:

  • build.rs
  • Cargo.toml
  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Before any code changes, run `cargo fmt --all -- --check`

Applied to files:

  • Cargo.toml
  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Before any code changes, run `cargo clippy --all-targets --all-features -- -D warnings`

Applied to files:

  • Cargo.toml
  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Code must pass `cargo fmt --all -- --check` with no formatting issues

Applied to files:

  • Cargo.toml
  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Only commit if all of the following pass: clippy (with -D warnings), fmt (check), tests (verbose), tests with `--features=cli`, and `cargo build --release`

Applied to files:

  • Cargo.toml
  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Applies to {src/**/*.rs,Cargo.*,README.md,OVERVIEW.md,.gitignore,.github/**} : Only commit changes to `src/**/*.rs`, `Cargo.*`, `README.md`, `OVERVIEW.md`, `.gitignore`, and `.github/**`; never use `git add .` or `git add -A`

Applied to files:

  • .gitignore
  • src/main.rs
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Follow `.gitignore` when committing files

Applied to files:

  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Applies to src/main.rs : Maintain the application entry point at `src/main.rs`

Applied to files:

  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: Applies to OVERVIEW.md : Maintain a proper `OVERVIEW.md`

Applied to files:

  • .gitignore
📚 Learning: 2025-10-08T18:00:17.944Z
Learnt from: CR
Repo: nerdCopter/bbl_parser PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-08T18:00:17.944Z
Learning: After formatting, verify with `cargo fmt --all -- --check` before proceeding

Applied to files:

  • .gitignore
🧬 Code graph analysis (1)
build.rs (1)
src/main.rs (1)
  • main (394-547)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test (macos-latest)
  • GitHub Check: Test (windows-latest)
🔇 Additional comments (7)
README.md (1)

1-1: LGTM!

The title simplification removes the work-in-progress status, aligning with the project's evolution.

.gitignore (1)

9-9: LGTM!

Whitelisting build.rs is correct since it's a standard Rust build script that should be tracked in version control.

OVERVIEW.md (1)

1-1: LGTM!

Removing the hardcoded version from the title aligns well with the shift to dynamic git-based versioning.

build.rs (1)

1-10: LGTM!

The build script is correctly structured using vergen's EmitBuilder to generate Git metadata at compile time. The configuration with git_sha(true) and git_commit_date() aligns with the PR objectives, and error handling appropriately propagates failures. The fallback values ("unknown") in src/main.rs provide graceful degradation when Git is unavailable.

src/main.rs (2)

30-40: LGTM!

The Git metadata constants are well-structured with appropriate fallbacks. Using env! with "unknown" defaults provides graceful degradation when vergen doesn't generate metadata (e.g., non-git environments), and compile-time concat! ensures zero runtime overhead.


341-348: LGTM!

The CLI construction correctly integrates git-based versioning. Using env!("CARGO_PKG_NAME") for the command name and VERSION_STR for the version provides consistency with the build-time metadata, and the formatted about text clearly displays package identity alongside Git information.

Cargo.toml (1)

12-14: Build dependencies are correctly configured with valid versions and no known security advisories.

Vergen version 8.3.2 is valid and currently in use (confirmed in Cargo.lock). The gitcl backend is appropriately configured for minimal external dependencies, pulling in only time alongside standard build tooling. No RustSec advisories exist for vergen itself or its direct dependencies. Both anyhow 1.0 and vergen 8 with features ["git", "gitcl"] are production-ready.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nerdCopter nerdCopter merged commit d82343a into master Dec 4, 2025
9 checks passed
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