Expand description
Write the section format used by ver-stub, and inject it into binaries.
This crate can be used from
build.rsscripts- Standalone binary tools, such as
ver-stub-tool.
§Quickstart
Create a LinkSection, tell it what contents you want it to have, and then
do something with it – either write the bytes out to a file, or patch it
into a binary that is using ver-stub.
In your build.rs:
ⓘ
use ver_stub_build::LinkSection;
fn main() {
// Patch the `my-bin` executable, producing `my-bin.bin` in the target profile dir.
LinkSection::new()
.with_all_git()
.patch_into_bin_dep("my-dep", "my-bin")
.write_to_target_profile_dir()
.unwrap();
// 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()
.unwrap();
// Or at a custom destination
LinkSection::new()
.with_all_git()
.patch_into_bin_dep("my-dep", "my-bin")
.write_to("dist/my-bin")
.unwrap();
}NOTE: patch_into_bin_dep requires cargo’s unstable artifact dependencies feature.
You must use nightly cargo, and enable “bindeps” in .cargo/config.toml.
Then it finds file to be patched using CARGO_BIN_FILE_* env vars.
More generally, you can use it without artifact dependencies, to do things similar to what ver-stub-tool does.
ⓘ
use ver_stub_build::LinkSection;
fn main() {
// Patch a binary at a specific path
LinkSection::new()
.with_all_git()
.patch_into("/path/to/binary")
.write_to_target_profile_dir()
.unwrap();
// Or with a custom output name
LinkSection::new()
.with_all_git()
.patch_into("/path/to/binary")
.with_filename("my-custom-name")
.write_to_target_profile_dir()
.unwrap();
// Or just write the section data file (for use with cargo-objcopy)
LinkSection::new()
.with_all_git()
.write_to_out_dir()
.unwrap();
}Structs§
- Link
Section - Builder for configuring which git information to include in version sections.
- Llvm
Tools - Wrapper for LLVM tools (llvm-readobj, llvm-objcopy).
- Section
Info - Information about a section in a binary.
- Update
Section Command - Builder for updating sections in a binary.
Enums§
- Binary
Format - Binary format detected from llvm-readobj output.
- Error
- Error type for ver-stub-build operations.
Constants§
- SECTION_
NAME - The section name used for version data (platform-specific).
Functions§
- platform_
section_ name - The section name is platform specific, and needs to depend on the target platform. This function gets the correct name for each binary format. (ver_stub::SECTION_NAME is the name for the host platform and so is less useful)