Skip to main content

Module build_info

Module build_info 

Source
Expand description

编译期注入的构建元信息。

根目录 build.rs 在编译期采集 git / rustc / 编译时刻信息,通过 cargo:rustc-env=KEY=VALUE 注入为编译期环境变量,本模块用 env! 宏读取 (编译期内联为 &'static str,零运行时开销)。

整个模块 gated 在 server feature 下:log_build_info 用了 tracing::info!, 而 tracing 是 optional 依赖(仅 server 启用)。常量定义本身两端都能编译, 但当前没有任何前端代码引用它们,gating 掉更稳妥。

字段拆分取舍:

  • git_describe:一句话承载“版本 + 提交数 + hash + 脏标记“,人眼定位构建最快, 已内含短 hash,故不再单独存 short_hash。
  • git_hash / commit_date 单独拆出,因为脏树时 describe 带 -dirty 但 commit_date 仍是上一个提交的,两者分离才能各自准确。
  • build_time:编译时刻(造出这个二进制的时间),与 commit_date 不同—— CI / 本地可能停在同一个 commit 但时间不同。

Structs§

BuildInfo
构建元信息(编译期常量集合)。

Statics§

BUILD_INFO
全局唯一的构建信息实例。

Functions§

log_build_info
打印构建信息。在 main() tracing 初始化之后调用。