Skip to content

Commit

Permalink
feat: better version print
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Jul 18, 2024
1 parent 0f01c69 commit e4366a2
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 7 deletions.
125 changes: 125 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ repository = "https://github.com/LibNyanpasu/clash-nyanpasu-service.git"

[workspace.dependencies]
nyanpasu-utils = { git = "https://github.com/LibNyanpasu/nyanpasu-utils.git", default-features = false }
warp = "0.3"
axum = "0.7.4"
anyhow = "1.0"
thiserror = "1"
log = "0.4.20"
log4rs = "1.2.0"
serde_json = "1.0"
parking_lot = "0.12.1"
simd-json = "0.13"
tokio = { version = "1", features = ["full"] }
Expand All @@ -39,10 +35,9 @@ opentelemetry_sdk = "0.23"
opentelemetry-stdout = { version = "0.4", features = ["trace"] }
tracing-opentelemetry = "0.24"
console-subscriber = "0.3.0"
rfd = "0.14.0"
futures = "0.3.30"
futures-util = "0.3"
runas = "1.2"
chrono = { version = "0.4", features = ["serde"] }

[profile.release]
panic = "unwind"
Expand Down
8 changes: 8 additions & 0 deletions nyanpasu_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
default-run = "nyanpasu-service"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
Expand Down Expand Up @@ -43,6 +44,13 @@ ctrlc = { version = "3", features = ["termination"] }
kill_tree = { version = "0.2.4", features = ["tokio"] }
semver = "1"
bounded-vec-deque = "0.1.1"
chrono = { workspace = true }
colored = "2.1.0"
timeago = "0.4"

[build-dependencies]
chrono = { workspace = true }
rustc_version = "0.4"

[target.'cfg(windows)'.dependencies]
check_elevation = "0.2.4"
Expand Down
61 changes: 61 additions & 0 deletions nyanpasu_service/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use chrono::prelude::*;
use rustc_version::version_meta;
use std::{env, process::Command};

fn main() {
// Git Information
let output = Command::new("git")
.args([
"show",
"--pretty=format:'%H,%cn,%cI'",
"--no-patch",
"--no-notes",
])
.output()
.unwrap();
let command_args: Vec<String> = String::from_utf8(output.stdout)
.unwrap()
.replace('\'', "")
.split(',')
.map(String::from)
.collect();
println!("cargo:rustc-env=COMMIT_HASH={}", command_args[0]);
println!("cargo:rustc-env=COMMIT_AUTHOR={}", command_args[1]);
let commit_date = DateTime::parse_from_rfc3339(command_args[2].as_str())
.unwrap()
.with_timezone(&Utc)
.to_rfc3339_opts(SecondsFormat::Millis, true);
println!("cargo:rustc-env=COMMIT_DATE={}", commit_date);

// Build Date
let build_date = Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true);
println!("cargo:rustc-env=BUILD_DATE={}", build_date);

// Build Profile
println!(
"cargo:rustc-env=BUILD_PROFILE={}",
match env::var("PROFILE").unwrap().as_str() {
"release" => "Release",
"debug" => "Debug",
_ => "Unknown",
}
);
// Build Platform
println!(
"cargo:rustc-env=BUILD_PLATFORM={}",
env::var("TARGET").unwrap()
);
// Rustc Version & LLVM Version
let rustc_version = version_meta().unwrap();
println!(
"cargo:rustc-env=RUSTC_VERSION={}",
rustc_version.short_version_string
);
println!(
"cargo:rustc-env=LLVM_VERSION={}",
match rustc_version.llvm_version {
Some(v) => v.to_string(),
None => "Unknown".to_string(),
}
)
}
Loading

0 comments on commit e4366a2

Please sign in to comment.