From c5d07daa770e19548ca5382ea128de9a587b6f56 Mon Sep 17 00:00:00 2001 From: qiumiaomiao <2268428576@qq.com> Date: Thu, 21 Nov 2024 22:18:47 +0800 Subject: [PATCH 1/2] implmentation of https://github.com/binbat/live777/issues/235 use shadow-rs to get PKG_VERSION and COMMIT_HASH `core::concat` can only accept literals, so use `const_str::concat` --- Cargo.lock | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +++ build.rs | 3 ++ src/main.rs | 6 ++- 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 build.rs diff --git a/Cargo.lock b/Cargo.lock index c246e3a..aae4596 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,6 +592,11 @@ name = "cc" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" +dependencies = [ + "jobserver", + "libc", + "once_cell", +] [[package]] name = "ccm" @@ -717,6 +722,38 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-str" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3618cccc083bb987a415d85c02ca6c9994ea5b44731ec28b9ecf09658655fba9" + +[[package]] +name = "const_fn" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373e9fafaa20882876db20562275ff58d50e0caa2590077fe7ce7bef90211d0d" + +[[package]] +name = "const_format" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "cookie-factory" version = "0.3.3" @@ -1186,6 +1223,19 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[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 = "group" version = "0.13.0" @@ -1569,6 +1619,12 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is_debug" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d198e9919d9822d5f7083ba8530e04de87841eaf21ead9af8f2304efd57c89" + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -1581,6 +1637,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" @@ -1639,6 +1704,18 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[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 = "libwish" version = "0.0.0" @@ -1651,6 +1728,18 @@ dependencies = [ "webrtc", ] +[[package]] +name = "libz-sys" +version = "1.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -1670,6 +1759,7 @@ dependencies = [ "api", "clap", "cli", + "const-str", "http 1.1.0", "liveion", "liveman", @@ -1678,6 +1768,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "shadow-rs", "signal", "tempfile", "tokio", @@ -2075,6 +2166,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.36.0" @@ -3216,6 +3316,19 @@ dependencies = [ "digest", ] +[[package]] +name = "shadow-rs" +version = "0.35.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1b2328fb3ec0d5302f95915e7e77cfc2ff943714d9970bc4b66e9eacf318687" +dependencies = [ + "const_format", + "git2", + "is_debug", + "time", + "tzdb", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -3526,7 +3639,9 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "libc", "num-conv", + "num_threads", "powerfmt", "serde", "time-core", @@ -3894,6 +4009,35 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "tz-rs" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33851b15c848fad2cf4b105c6bb66eb9512b6f6c44a4b13f57c53c73c707e2b4" +dependencies = [ + "const_fn", +] + +[[package]] +name = "tzdb" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b580f6b365fa89f5767cdb619a55d534d04a4e14c2d7e5b9a31e94598687fb1" +dependencies = [ + "iana-time-zone", + "tz-rs", + "tzdb_data", +] + +[[package]] +name = "tzdb_data" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "654c1ec546942ce0594e8d220e6b8e3899e0a0a8fe70ddd54d32a376dfefe3f8" +dependencies = [ + "tz-rs", +] + [[package]] name = "ucd-trie" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 47eb191..3cdde84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,10 @@ repository.workspace = true default-run = "live777" +build = "build.rs" +[build-dependencies] +shadow-rs = "0.35.1" + [[bin]] name = "live777" path = "src/main.rs" @@ -87,9 +91,11 @@ net4mqtt = { path = "libs/net4mqtt" } signal = { path = "libs/signal" } clap = { workspace = true, features = ["derive"] } +const-str = "0.5.7" tokio = { workspace = true, features = ["full"] } tracing = { workspace = true } serde = { workspace = true } +shadow-rs = "0.35.1" toml = "0.8.19" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..a2a37f1 --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() -> shadow_rs::SdResult<()> { + shadow_rs::new() +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 1f8a75a..3287739 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,15 @@ use clap::Parser; +use const_str::concat; use tracing::{debug, info, warn}; +use shadow_rs::shadow; + +shadow!(build); mod log; mod utils; #[derive(Parser)] -#[command(version)] +#[command(version = concat!("v",build::PKG_VERSION,"-",build::SHORT_COMMIT))] struct Args { /// Set config file path #[arg(short, long)] From 8f9427ccf68780783f6f9a908b5e1d1a57e3025f Mon Sep 17 00:00:00 2001 From: qiumiaomiao <2268428576@qq.com> Date: Fri, 22 Nov 2024 11:10:14 +0800 Subject: [PATCH 2/2] format code --- build.rs | 2 +- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index a2a37f1..4a0dfc4 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,3 @@ fn main() -> shadow_rs::SdResult<()> { shadow_rs::new() -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 3287739..9ef38e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use clap::Parser; use const_str::concat; -use tracing::{debug, info, warn}; use shadow_rs::shadow; +use tracing::{debug, info, warn}; shadow!(build);