build: 在 version 中展示详细的构建信息 (#265)

* build: 在 version 中展示详细的构建信息

* chore: 修改
This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-02-19 03:47:01 +08:00
committed by GitHub
parent bc27778366
commit d1168f35f3
5 changed files with 94 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ license = { workspace = true }
description = { workspace = true }
publish = { workspace = true }
readme = "../../README.md"
build = "build.rs"
[dependencies]
anyhow = { workspace = true }
@@ -55,6 +56,9 @@ utoipa-swagger-ui = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
[build-dependencies]
built = { workspace = true }
[package.metadata.release]
release = true

View File

@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}

View File

@@ -1,7 +1,7 @@
use clap::Parser;
#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(name = "Bili-Sync", version = version(), about, long_about = None)]
pub struct Args {
#[arg(short, long, env = "SCAN_ONLY")]
pub scan_only: bool,
@@ -9,3 +9,28 @@ pub struct Args {
#[arg(short, long, default_value = "None,bili_sync=info", env = "RUST_LOG")]
pub log_level: String,
}
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
fn version() -> String {
let version = if let (Some(git_version), Some(git_dirty)) = (built_info::GIT_VERSION, built_info::GIT_DIRTY) {
format!("{}{}", git_version, if git_dirty { "-dirty" } else { "" })
} else {
built_info::PKG_VERSION.to_owned()
};
format!(
"{}
Architecture: {}-{}
Author: {}
Built Time: {}
Rustc Version: {}",
version,
built_info::CFG_OS,
built_info::CFG_TARGET_ARCH,
built_info::PKG_AUTHORS,
built_info::BUILT_TIME_UTC,
built_info::RUSTC_VERSION,
)
}