Crate ver_stub_build

Crate ver_stub_build 

Source
Expand description

Write the section format used by ver-stub, and inject it into binaries.

This crate can be used from

  • build.rs scripts
  • 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§

LinkSection
Builder for configuring which git information to include in version sections.
LlvmTools
Wrapper for LLVM tools (llvm-readobj, llvm-objcopy).
SectionInfo
Information about a section in a binary.
UpdateSectionCommand
Builder for updating sections in a binary.

Enums§

BinaryFormat
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)