Expand description
Build script helper for injecting version data into binaries.
This crate provides utilities for use in build.rs scripts to inject
git version information into artifact dependency binaries:
- Git SHA (
git rev-parse HEAD) - Git describe (
git describe --always --dirty) - Git branch (
git rev-parse --abbrev-ref HEAD)
§Requirements
This crate requires Cargo’s unstable artifact dependencies feature (bindeps).
You must use nightly Cargo and enable it in .cargo/config.toml:
[unstable]
bindeps = true§Example
In your build.rs:
ⓘ
use ver_shim_build::LinkSection;
fn main() {
// Patch an artifact dependency binary (uses CARGO_BIN_FILE_* env vars)
LinkSection::new()
.with_all_git()
.patch_into_bin_dep("my-dep", "my-bin")
.write_to_target_profile_dir();
// Or patch a binary at a specific path
LinkSection::new()
.with_all_git()
.patch_into("/path/to/binary")
.write_to_target_profile_dir();
// Or with a custom output name
LinkSection::new()
.with_all_git()
.patch_into_bin_dep("my-dep", "my-bin")
.with_filename("my-custom-name")
.write_to_target_profile_dir();
// Or just write the section data file (for use with cargo-objcopy)
LinkSection::new()
.with_all_git()
.write_to_out_dir();
}Structs§
- Link
Section - Builder for configuring which git information to include in version sections.
- Llvm
Tools - Wrapper for LLVM tools (llvm-readobj, llvm-objcopy).
- Update
Section Command - Builder for updating sections in a binary.