Skip to content

fix: improve version detection fallback in build.rs #2028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ralphmodales
Copy link
Contributor

Fix version detection in build.rs for cargo-binstall installations

This PR implements improvements suggested in issue #2025.

The main change is fixing the version detection logic in build.rs to properly handle cases where Git operations fail or return empty results. Previously, when using cargo-binstall, the gix --version command would output nothing because the build script was not properly falling back to CARGO_PKG_VERSION.

Changes

  • Improved Git command validation: Added explicit check for output.status.success() to ensure Git command actually succeeded
  • Fixed empty string handling: Modified parse_describe() to return None for empty strings instead of Some(""), allowing proper fallback to CARGO_PKG_VERSION
  • Enhanced error handling: Build script now properly detects when Git describe fails and falls back to package version

Issue

When installing via cargo-binstall, the pre-built binaries were compiled in environments where:

  • Git commands may have failed silently
  • Repository tags were not available
  • The fallback mechanism was not triggering due to empty strings being treated as valid results

The original parse_describe function would return Some("") for empty Git output, preventing the unwrap_or_else fallback from executing.

Testing

  • Verified that gix --version now properly displays version information when installed via cargo-binstall
  • Confirmed that source builds continue to work as expected
  • Version detection now works correctly in both scenarios

Fixes #2025

Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank so much!

@Byron Byron enabled auto-merge May 27, 2025 12:50
@Byron Byron merged commit 5546baa into GitoxideLabs:main May 27, 2025
22 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.

--version should output version
2 participants