diff --git a/Cargo.lock b/Cargo.lock index 1f7669f5bd..96c44ed4bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1614,6 +1614,26 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "enum-iterator" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eeac5c5edb79e4e39fe8439ef35207780a11f69c52cbe424ce3dfad4cb78de6" +dependencies = [ + "enum-iterator-derive", +] + +[[package]] +name = "enum-iterator-derive" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "enum_kind" version = "0.2.1" @@ -2285,6 +2305,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "git2" +version = "0.13.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "url", +] + [[package]] name = "glib" version = "0.14.5" @@ -3057,6 +3090,18 @@ version = "0.2.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +[[package]] +name = "libgit2-sys" +version = "0.12.26+1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libm" version = "0.2.1" @@ -3074,6 +3119,18 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libz-sys" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "lioness" version = "0.1.2" @@ -3541,6 +3598,7 @@ dependencies = [ "topology", "url", "validator-client", + "vergen", "version-checker", "websocket-requests", ] @@ -3607,6 +3665,7 @@ dependencies = [ "tokio-util", "url", "validator-client", + "vergen", "version-checker", "web3", ] @@ -3642,6 +3701,7 @@ dependencies = [ "topology", "url", "validator-client", + "vergen", "version-checker", ] @@ -3697,6 +3757,7 @@ dependencies = [ "topology", "url", "validator-client", + "vergen", "version-checker", ] @@ -3737,6 +3798,7 @@ dependencies = [ "topology", "url", "validator-client", + "vergen", "version-checker", ] @@ -7160,6 +7222,23 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "vergen" +version = "5.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cf88d94e969e7956d924ba70741316796177fa0c79a2c9f4ab04998d96e966e" +dependencies = [ + "anyhow", + "cfg-if 1.0.0", + "chrono", + "enum-iterator", + "getset", + "git2", + "rustc_version 0.4.0", + "rustversion", + "thiserror", +] + [[package]] name = "version-checker" version = "0.1.0" diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index b730576ddc..69e8ecdcd4 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -51,3 +51,6 @@ coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gate [dev-dependencies] serde_json = "1.0" # for the "textsend" example + +[build-dependencies] +vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] } \ No newline at end of file diff --git a/clients/native/build.rs b/clients/native/build.rs new file mode 100644 index 0000000000..01b3a20dc6 --- /dev/null +++ b/clients/native/build.rs @@ -0,0 +1,8 @@ +// Copyright 2021 - Nym Technologies SA +// SPDX-License-Identifier: Apache-2.0 + +use vergen::{vergen, Config}; + +fn main() { + vergen(Config::default()).expect("failed to extract build metadata") +} diff --git a/clients/native/src/main.rs b/clients/native/src/main.rs index 8527347c6e..3c8ae30ff9 100644 --- a/clients/native/src/main.rs +++ b/clients/native/src/main.rs @@ -1,7 +1,7 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use clap::{App, ArgMatches}; +use clap::{crate_version, App, ArgMatches}; pub mod client; pub mod commands; @@ -13,7 +13,8 @@ fn main() { println!("{}", banner()); let arg_matches = App::new("Nym Client") - .version(env!("CARGO_PKG_VERSION")) + .version(crate_version!()) + .long_version(&*long_version()) .author("Nymtech") .about("Implementation of the Nym Client") .subcommand(commands::init::command_args()) @@ -50,7 +51,38 @@ fn banner() -> String { (client - version {:}) "#, - env!("CARGO_PKG_VERSION") + crate_version!() + ) +} + +fn long_version() -> String { + format!( + r#" +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +"#, + "Build Timestamp:", + env!("VERGEN_BUILD_TIMESTAMP"), + "Build Version:", + env!("VERGEN_BUILD_SEMVER"), + "Commit SHA:", + env!("VERGEN_GIT_SHA"), + "Commit Date:", + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + "Commit Branch:", + env!("VERGEN_GIT_BRANCH"), + "rustc Version:", + env!("VERGEN_RUSTC_SEMVER"), + "rustc Channel:", + env!("VERGEN_RUSTC_CHANNEL"), + "cargo Profile:", + env!("VERGEN_CARGO_PROFILE"), ) } diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index 39ef15d38f..3a7c1c4dda 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -43,3 +43,6 @@ network-defaults = { path = "../../common/network-defaults" } [features] coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut"] + +[build-dependencies] +vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] } \ No newline at end of file diff --git a/clients/socks5/build.rs b/clients/socks5/build.rs new file mode 100644 index 0000000000..01b3a20dc6 --- /dev/null +++ b/clients/socks5/build.rs @@ -0,0 +1,8 @@ +// Copyright 2021 - Nym Technologies SA +// SPDX-License-Identifier: Apache-2.0 + +use vergen::{vergen, Config}; + +fn main() { + vergen(Config::default()).expect("failed to extract build metadata") +} diff --git a/clients/socks5/src/main.rs b/clients/socks5/src/main.rs index 44b23b85a0..7fcd2dc687 100644 --- a/clients/socks5/src/main.rs +++ b/clients/socks5/src/main.rs @@ -1,7 +1,7 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use clap::{App, ArgMatches}; +use clap::{crate_version, App, ArgMatches}; pub mod client; mod commands; @@ -15,6 +15,7 @@ fn main() { let arg_matches = App::new("Nym Socks5 Proxy") .version(env!("CARGO_PKG_VERSION")) .author("Nymtech") + .long_version(&*long_version()) .about("A Socks5 localhost proxy that converts incoming messages to Sphinx and sends them to a Nym address") .subcommand(commands::init::command_args()) .subcommand(commands::run::command_args()) @@ -50,7 +51,38 @@ fn banner() -> String { (socks5 proxy - version {:}) "#, - env!("CARGO_PKG_VERSION") + crate_version!() + ) +} + +fn long_version() -> String { + format!( + r#" +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +"#, + "Build Timestamp:", + env!("VERGEN_BUILD_TIMESTAMP"), + "Build Version:", + env!("VERGEN_BUILD_SEMVER"), + "Commit SHA:", + env!("VERGEN_GIT_SHA"), + "Commit Date:", + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + "Commit Branch:", + env!("VERGEN_GIT_BRANCH"), + "rustc Version:", + env!("VERGEN_RUSTC_SEMVER"), + "rustc Channel:", + env!("VERGEN_RUSTC_CHANNEL"), + "cargo Profile:", + env!("VERGEN_CARGO_PROFILE"), ) } diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 47770e76cb..834a5943cd 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -56,3 +56,4 @@ coconut = ["coconut-interface", "gateway-requests/coconut", "gateway-client/coco [build-dependencies] tokio = { version = "1.4", features = ["rt-multi-thread", "macros"] } sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] } +vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] } \ No newline at end of file diff --git a/gateway/build.rs b/gateway/build.rs index 8cb1bfd15e..3d75c39198 100644 --- a/gateway/build.rs +++ b/gateway/build.rs @@ -1,5 +1,6 @@ use sqlx::{Connection, SqliteConnection}; use std::env; +use vergen::{vergen, Config}; #[tokio::main] async fn main() { @@ -22,4 +23,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + vergen(Config::default()).expect("failed to extract build metadata") } diff --git a/gateway/src/main.rs b/gateway/src/main.rs index 91ff77066a..09c7d2bed3 100644 --- a/gateway/src/main.rs +++ b/gateway/src/main.rs @@ -1,7 +1,7 @@ // Copyright 2020 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use clap::{App, ArgMatches}; +use clap::{crate_version, App, ArgMatches}; mod commands; mod config; @@ -14,7 +14,8 @@ async fn main() { println!("{}", banner()); let arg_matches = App::new("Nym Mixnet Gateway") - .version(env!("CARGO_PKG_VERSION")) + .version(crate_version!()) + .long_version(&*long_version()) .author("Nymtech") .about("Implementation of the Nym Mixnet Gateway") .subcommand(commands::init::command_args()) @@ -53,7 +54,38 @@ fn banner() -> String { (gateway - version {:}) "#, - env!("CARGO_PKG_VERSION") + crate_version!() + ) +} + +fn long_version() -> String { + format!( + r#" +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +"#, + "Build Timestamp:", + env!("VERGEN_BUILD_TIMESTAMP"), + "Build Version:", + env!("VERGEN_BUILD_SEMVER"), + "Commit SHA:", + env!("VERGEN_GIT_SHA"), + "Commit Date:", + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + "Commit Branch:", + env!("VERGEN_GIT_BRANCH"), + "rustc Version:", + env!("VERGEN_RUSTC_SEMVER"), + "rustc Channel:", + env!("VERGEN_RUSTC_CHANNEL"), + "cargo Profile:", + env!("VERGEN_CARGO_PROFILE"), ) } diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index be8a63de46..6bd8cf6edb 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -47,3 +47,6 @@ version-checker = { path="../common/version-checker" } [dev-dependencies] serial_test = "0.5" + +[build-dependencies] +vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] } \ No newline at end of file diff --git a/mixnode/build.rs b/mixnode/build.rs new file mode 100644 index 0000000000..01b3a20dc6 --- /dev/null +++ b/mixnode/build.rs @@ -0,0 +1,8 @@ +// Copyright 2021 - Nym Technologies SA +// SPDX-License-Identifier: Apache-2.0 + +use vergen::{vergen, Config}; + +fn main() { + vergen(Config::default()).expect("failed to extract build metadata") +} diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index a0ad7774ec..931cc92b21 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -4,7 +4,7 @@ extern crate rocket; // Copyright 2020 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use clap::{App, ArgMatches}; +use clap::{crate_version, App, ArgMatches}; mod commands; mod config; @@ -16,7 +16,8 @@ fn main() { println!("{}", banner()); let arg_matches = App::new("Nym Mixnode") - .version(env!("CARGO_PKG_VERSION")) + .version(crate_version!()) + .long_version(&*long_version()) .author("Nymtech") .about("Implementation of a Loopix-based Mixnode") .subcommand(commands::describe::command_args()) @@ -57,7 +58,38 @@ fn banner() -> String { (mixnode - version {:}) "#, - env!("CARGO_PKG_VERSION") + crate_version!() + ) +} + +fn long_version() -> String { + format!( + r#" +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +"#, + "Build Timestamp:", + env!("VERGEN_BUILD_TIMESTAMP"), + "Build Version:", + env!("VERGEN_BUILD_SEMVER"), + "Commit SHA:", + env!("VERGEN_GIT_SHA"), + "Commit Date:", + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + "Commit Branch:", + env!("VERGEN_GIT_BRANCH"), + "rustc Version:", + env!("VERGEN_RUSTC_SEMVER"), + "rustc Channel:", + env!("VERGEN_RUSTC_CHANNEL"), + "cargo Profile:", + env!("VERGEN_CARGO_PROFILE"), ) } diff --git a/validator-api/Cargo.toml b/validator-api/Cargo.toml index 27be478871..0ab06ca89a 100644 --- a/validator-api/Cargo.toml +++ b/validator-api/Cargo.toml @@ -61,3 +61,4 @@ coconut = ["coconut-interface", "credentials", "gateway-client/coconut"] [build-dependencies] tokio = { version = "1.4", features = ["rt-multi-thread", "macros"] } sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate"] } +vergen = { version = "5", default-features = false, features = ["build", "git", "rustc", "cargo"] } \ No newline at end of file diff --git a/validator-api/build.rs b/validator-api/build.rs index a46399c281..a1f997d492 100644 --- a/validator-api/build.rs +++ b/validator-api/build.rs @@ -1,5 +1,6 @@ use sqlx::{Connection, SqliteConnection}; use std::env; +use vergen::{vergen, Config}; #[tokio::main] async fn main() { @@ -22,4 +23,6 @@ async fn main() { // for some strange reason we need to add a leading `/` to the windows path even though it's // not a valid windows path... but hey, it works... println!("cargo:rustc-env=DATABASE_URL=sqlite:///{}", &database_path); + + vergen(Config::default()).expect("failed to extract build metadata") } diff --git a/validator-api/src/main.rs b/validator-api/src/main.rs index a4812a8d6f..5cebcecbe1 100644 --- a/validator-api/src/main.rs +++ b/validator-api/src/main.rs @@ -15,7 +15,7 @@ use crate::storage::ValidatorApiStorage; use ::config::NymConfig; use anyhow::Result; use cache::ValidatorCache; -use clap::{App, Arg, ArgMatches}; +use clap::{crate_version, App, Arg, ArgMatches}; use log::{info, warn}; use rocket::fairing::AdHoc; use rocket::http::Method; @@ -78,13 +78,46 @@ fn parse_validators(raw: &str) -> Vec { .collect() } +fn long_version() -> String { + format!( + r#" +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +{:<20}{} +"#, + "Build Timestamp:", + env!("VERGEN_BUILD_TIMESTAMP"), + "Build Version:", + env!("VERGEN_BUILD_SEMVER"), + "Commit SHA:", + env!("VERGEN_GIT_SHA"), + "Commit Date:", + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + "Commit Branch:", + env!("VERGEN_GIT_BRANCH"), + "rustc Version:", + env!("VERGEN_RUSTC_SEMVER"), + "rustc Channel:", + env!("VERGEN_RUSTC_CHANNEL"), + "cargo Profile:", + env!("VERGEN_CARGO_PROFILE"), + ) +} + fn parse_args<'a>() -> ArgMatches<'a> { #[cfg(feature = "coconut")] let monitor_reqs = &[]; #[cfg(not(feature = "coconut"))] let monitor_reqs = &[ETH_ENDPOINT, ETH_PRIVATE_KEY]; - + let build_details = long_version(); let base_app = App::new("Nym Validator API") + .version(crate_version!()) + .long_version(&*build_details) .author("Nymtech") .arg( Arg::with_name(MONITORING_ENABLED) @@ -407,13 +440,9 @@ async fn setup_rocket(config: &Config, liftoff_notify: Arc) -> Result Result<()> { - setup_logging(); +async fn run_validator_api(matches: ArgMatches<'static>) -> Result<()> { let system_version = env!("CARGO_PKG_VERSION"); - println!("Starting validator api..."); - // try to load config from the file, if it doesn't exist, use default values let config = match Config::load_from_file(None) { Ok(cfg) => cfg, @@ -430,8 +459,6 @@ async fn main() -> Result<()> { } }; - let matches = parse_args(); - let config = override_config(config, &matches); // if we just wanted to write data to the config, exit if matches.is_present(WRITE_CONFIG_ARG) { @@ -517,3 +544,12 @@ async fn main() -> Result<()> { Ok(()) } + +#[tokio::main] +async fn main() -> Result<()> { + println!("Starting validator api..."); + + setup_logging(); + let args = parse_args(); + run_validator_api(args).await +}