Skip to main content

Crate ver_stub

Crate ver_stub 

Source
Expand description

Runtime access to version data injected via a link section.

This crate provides a way to access build-time information that has been injected into the binary via a link section (ver_stub on ELF/COFF, __TEXT,ver_stub on Mach-O).

Use its functions

fn git_sha() -> Option<&str>;
fn git_describe() -> Option<&str>;
fn build_timestamp() -> Option<&str>;
...

to read fields from the section if they are present.

Then use ver-stub-build or ver-stub-tool to write the link section into the binary at the end of your build.

§Details

The section format is:

  • First byte: number of members in the section (for forward compatibility)
  • Next num_members * 2 bytes: array of end offsets (u16, little-endian, relative to header)
  • Remaining bytes: concatenated string data

Header size = 1 + num_members * 2

For member N:

  • start = header_size + end[N-1] if N > 0, else header_size
  • end = header_size + end[N]
  • If start == end, the member is not present.
  • If N >= num_members (from first byte), the member is not present.

Using relative offsets means a zero-initialized buffer reads as “all members absent”. The num_members byte enables forward and backwards compatibility: old sections can be read by new code which has more members added in the future, and new sections can be read by old code as well, as long as we never change the index of any existing member.

Constants§

SECTION_NAME
The section name used for version data (platform-specific).

Functions§

build_date
Returns the build date, if present.
build_timestamp
Returns the build timestamp, if present.
custom
Returns the custom application-specific string, if present.
git_branch
Returns the git branch name, if present.
git_commit_date
Returns the git commit date, if present.
git_commit_msg
Returns the git commit message, if present.
git_commit_timestamp
Returns the git commit timestamp, if present.
git_describe
Returns the git describe output, if present.
git_sha
Returns the git SHA, if present.