From e5d50698d212d50da367410f938ae59f34abfcda Mon Sep 17 00:00:00 2001 From: Christian Visintin Date: Mon, 7 Oct 2024 17:49:52 +0200 Subject: [PATCH] fix: vergen (#296) --- Cargo.lock | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + build.rs | 19 ++++- src/main.rs | 17 +++- 4 files changed, 257 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a56b5d0a..03900eee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + [[package]] name = "arbitrary" version = "1.3.2" @@ -288,6 +294,38 @@ dependencies = [ "bytes", ] +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cassowary" version = "0.3.0" @@ -309,6 +347,8 @@ version = "1.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -570,6 +610,41 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.79", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.79", +] + [[package]] name = "data-encoding" version = "2.6.0" @@ -637,6 +712,37 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "derive_builder" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "derive_builder_macro" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" +dependencies = [ + "derive_builder_core", + "syn 2.0.79", +] + [[package]] name = "des" version = "0.7.0" @@ -1010,6 +1116,19 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +[[package]] +name = "git2" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724" +dependencies = [ + "bitflags 2.6.0", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "h2" version = "0.3.26" @@ -1329,6 +1448,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.5.0" @@ -1440,6 +1565,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.70" @@ -1619,6 +1753,18 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libgit2-sys" +version = "0.17.0+1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libredox" version = "0.1.3" @@ -1847,6 +1993,15 @@ dependencies = [ "tauri-winrt-notification", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nucleo" version = "0.5.0" @@ -3105,6 +3260,9 @@ name = "semver" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -3392,6 +3550,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.26.3" @@ -3471,6 +3635,20 @@ dependencies = [ "futures-core", ] +[[package]] +name = "sysinfo" +version = "0.31.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows 0.56.0", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -3583,6 +3761,7 @@ dependencies = [ "tuirealm", "unicode-width 0.2.0", "uzers", + "vergen-git2", "version-compare", "whoami", "wildmatch", @@ -4078,6 +4257,49 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vergen" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349ed9e45296a581f455bc18039878f409992999bc1d5da12a6800eb18c8752f" +dependencies = [ + "anyhow", + "cargo_metadata", + "derive_builder", + "regex", + "rustc_version", + "rustversion", + "sysinfo", + "time", + "vergen-lib", +] + +[[package]] +name = "vergen-git2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e771aff771c0d7c2f42e434e2766d304d917e29b40f0424e8faaaa936bbc3f29" +dependencies = [ + "anyhow", + "derive_builder", + "git2", + "rustversion", + "time", + "vergen", + "vergen-lib", +] + +[[package]] +name = "vergen-lib" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229eaddb0050920816cf051e619affaf18caa3dd512de8de5839ccbc8e53abb0" +dependencies = [ + "anyhow", + "derive_builder", + "rustversion", +] + [[package]] name = "version-compare" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index b1a4832b..6fb248b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,6 +90,8 @@ serial_test = "^3" [build-dependencies] cfg_aliases = "0.2" +vergen-git2 = { version = "1", features = ["build", "cargo", "rustc", "si"] } + [features] default = ["smb", "with-keyring"] diff --git a/build.rs b/build.rs index 543d2da8..ca33ce62 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,7 @@ use cfg_aliases::cfg_aliases; +use vergen_git2::{BuildBuilder, CargoBuilder, Emitter, Git2Builder, RustcBuilder, SysinfoBuilder}; -fn main() { +fn main() -> Result<(), Box> { // Setup cfg aliases cfg_aliases! { // Platforms @@ -13,4 +14,20 @@ fn main() { smb_unix: { all(unix, feature = "smb", not(macos)) }, smb_windows: { all(windows, feature = "smb") } } + + let build = BuildBuilder::all_build()?; + let cargo = CargoBuilder::all_cargo()?; + let git2 = Git2Builder::all_git()?; + let rustc = RustcBuilder::all_rustc()?; + let si = SysinfoBuilder::all_sysinfo()?; + + Emitter::default() + .add_instructions(&build)? + .add_instructions(&cargo)? + .add_instructions(&git2)? + .add_instructions(&rustc)? + .add_instructions(&si)? + .emit()?; + + Ok(()) } diff --git a/src/main.rs b/src/main.rs index c6e0f850..922c455f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,11 +29,20 @@ use self::activity_manager::{ActivityManager, NextActivity}; use self::cli::{Args, ArgsSubcommands, RemoteArgs, RunOpts, Task}; use self::system::logging::{self, LogLevel}; +const APP_NAME: &str = env!("CARGO_PKG_NAME"); +const APP_BUILD_DATE: &str = env!("VERGEN_BUILD_TIMESTAMP"); +const APP_GIT_BRANCH: &str = env!("VERGEN_GIT_BRANCH"); +const APP_GIT_HASH: &str = env!("VERGEN_GIT_SHA"); const EXIT_CODE_SUCCESS: i32 = 0; const EXIT_CODE_ERROR: i32 = 1; const TERMSCP_VERSION: &str = env!("CARGO_PKG_VERSION"); const TERMSCP_AUTHORS: &str = env!("CARGO_PKG_AUTHORS"); +#[inline] +fn git_hash() -> &'static str { + APP_GIT_HASH[0..8].as_ref() +} + fn main() { let args: Args = argh::from_env(); // Parse args @@ -48,7 +57,10 @@ fn main() { if let Err(err) = logging::init(run_opts.log_level) { eprintln!("Failed to initialize logging: {err}"); } - info!("termscp {} started!", TERMSCP_VERSION); + info!( + "{APP_NAME} v{TERMSCP_VERSION} ({APP_GIT_BRANCH}, {git_hash}, {APP_BUILD_DATE}) - Developed by {TERMSCP_AUTHORS}", + git_hash = git_hash() + ); // Run info!("Starting activity manager..."); let rc = run(run_opts); @@ -70,7 +82,8 @@ fn parse_args(args: Args) -> Result { // Version if args.version { return Err(format!( - "termscp - {TERMSCP_VERSION} - Developed by {TERMSCP_AUTHORS}", + "{APP_NAME} v{TERMSCP_VERSION} ({APP_GIT_BRANCH}, {git_hash}, {APP_BUILD_DATE}) - Developed by {TERMSCP_AUTHORS}", + git_hash = git_hash() )); } // Logging