Include git commit hash as string into Rust program

后端 未结 6 2043
小蘑菇
小蘑菇 2021-02-12 23:33

I host a Rust project in git repository and I want to make it print the version on some command. How can I include the version into the program? I thought that the build script

6条回答
  •  深忆病人
    2021-02-13 00:05

    shadow-rs:: build-time information stored in your rust project.(binary,lib,cdylib,dylib)

    https://github.com/baoyachi/shadow-rs

    shadow-rs allows you to recall properties of the build process and environment at runtime, including:

    • Cargo.toml project version
    • Dependency information
    • The Git commit that produced the build artifact (binary)
    • What version of the rust toolchain was used in compilation
    • The build variant, e.g. debug or release
    • (And more)

    You can use this tool to check in production exactly where a binary came from and how it was built.

    Full Examples

    • Check out the shadow_example for a simple demonstration of how shadow-rs might be used to provide build-time information at run-time.
    • built in method:examples.

提交回复
热议问题