From d1168f35f34aa049c55b4eb3a40b2b7f7c5325bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Wed, 19 Feb 2025 03:47:01 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E5=9C=A8=20version=20=E4=B8=AD?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E8=AF=A6=E7=BB=86=E7=9A=84=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20(#265)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * build: 在 version 中展示详细的构建信息 * chore: 修改 --- Cargo.lock | 59 +++++++++++++++++++++++++++++ Cargo.toml | 3 +- crates/bili_sync/Cargo.toml | 4 ++ crates/bili_sync/build.rs | 3 ++ crates/bili_sync/src/config/clap.rs | 27 ++++++++++++- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 crates/bili_sync/build.rs diff --git a/Cargo.lock b/Cargo.lock index 31b7e15..fe339be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,6 +463,7 @@ dependencies = [ "axum", "bili_sync_entity", "bili_sync_migration", + "built", "chrono", "clap", "cookie", @@ -593,6 +594,16 @@ dependencies = [ "syn_derive", ] +[[package]] +name = "built" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ed6191a7e78c36abdb16ab65341eefd73d64d303fffccdbb00d51e4205967b" +dependencies = [ + "chrono", + "git2", +] + [[package]] name = "bumpalo" version = "3.17.0" @@ -639,6 +650,8 @@ version = "1.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -1287,6 +1300,19 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "git2" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fda788993cc341f69012feba8bf45c0ba4f3291fcc08e214b4d5a7332d88aff" +dependencies = [ + "bitflags 2.5.0", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "glob" version = "0.3.1" @@ -1622,6 +1648,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.69" @@ -1666,6 +1701,18 @@ version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +[[package]] +name = "libgit2-sys" +version = "0.18.0+1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1a117465e7e1597e8febea8bb0c410f1c7fb93b1e1cddf34363f8390367ffec" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libm" version = "0.2.8" @@ -1693,6 +1740,18 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libz-sys" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9b68e50e6e0b26f672573834882eb57759f6db9b3be2ea3c35c91188bb4eaa" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.4.13" diff --git a/Cargo.toml b/Cargo.toml index 581dab6..0038018 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,9 @@ async-std = { version = "1.13.0", features = ["attributes", "tokio1"] } async-stream = "0.3.6" async-trait = "0.1.85" axum = { version = "0.8.1", features = ["macros"] } +built = { version = "0.7.7", features = ["git2", "chrono"] } chrono = { version = "0.4.39", features = ["serde"] } -clap = { version = "4.5.26", features = ["env"] } +clap = { version = "4.5.26", features = ["env", "string"] } cookie = "0.18.1" cow-utils = "0.1.3" dirs = "6.0.0" diff --git a/crates/bili_sync/Cargo.toml b/crates/bili_sync/Cargo.toml index 71adf1e..9c6a8d7 100644 --- a/crates/bili_sync/Cargo.toml +++ b/crates/bili_sync/Cargo.toml @@ -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 diff --git a/crates/bili_sync/build.rs b/crates/bili_sync/build.rs new file mode 100644 index 0000000..d8f91cb --- /dev/null +++ b/crates/bili_sync/build.rs @@ -0,0 +1,3 @@ +fn main() { + built::write_built_file().expect("Failed to acquire build-time information"); +} diff --git a/crates/bili_sync/src/config/clap.rs b/crates/bili_sync/src/config/clap.rs index 342e50f..7f42011 100644 --- a/crates/bili_sync/src/config/clap.rs +++ b/crates/bili_sync/src/config/clap.rs @@ -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, + ) +}