From df22f90b99d6458bcd39987e2ed78bdb563a3154 Mon Sep 17 00:00:00 2001 From: Jan Ciolek Date: Fri, 26 Apr 2024 14:48:19 +0000 Subject: [PATCH] Print all enabled features in `neard --version` --- neard/build.rs | 23 +++++++++++++++++++++++ neard/src/main.rs | 5 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/neard/build.rs b/neard/build.rs index 331f5e4ddf2..7352cd73fa6 100644 --- a/neard/build.rs +++ b/neard/build.rs @@ -92,6 +92,27 @@ fn get_git_version() -> Result { } } +/// Get features enabled using the --features flag. +fn get_enabled_features() -> String { + let mut features: Vec = Vec::new(); + + // Every enabled feature has a corresponding environment variable that is set to 1 + // For example: + // CARGO_FEATURE_JSON_RPC=1 + // CARGO_FEATURE_ROSETTA_RPC=1 + // .. + + let feature_start = "CARGO_FEATURE_"; + for (variable, value) in std::env::vars() { + if variable.starts_with(feature_start) && value == "1" { + features.push(variable[feature_start.len()..].to_string().to_lowercase()); + } + } + features.sort(); + + features.join(", ") +} + fn main() { if let Err(err) = try_main() { eprintln!("{}", err); @@ -114,5 +135,7 @@ fn try_main() -> Result<()> { println!("cargo:rustc-env=NEARD_RUSTC_VERSION={}", rustc_version::version()?); + println!("cargo:rustc-env=NEARD_FEATURES={}", get_enabled_features()); + Ok(()) } diff --git a/neard/src/main.rs b/neard/src/main.rs index b679618d809..7ba36737a05 100644 --- a/neard/src/main.rs +++ b/neard/src/main.rs @@ -13,11 +13,12 @@ use std::time::Duration; static NEARD_VERSION: &str = env!("NEARD_VERSION"); static NEARD_BUILD: &str = env!("NEARD_BUILD"); static RUSTC_VERSION: &str = env!("NEARD_RUSTC_VERSION"); +static NEARD_FEATURES: &str = env!("NEARD_FEATURES"); static NEARD_VERSION_STRING: Lazy = Lazy::new(|| { format!( - "(release {}) (build {}) (rustc {}) (protocol {}) (db {})", - NEARD_VERSION, NEARD_BUILD, RUSTC_VERSION, PROTOCOL_VERSION, DB_VERSION + "(release {}) (build {}) (rustc {}) (protocol {}) (db {})\nfeatures: [{}]", + NEARD_VERSION, NEARD_BUILD, RUSTC_VERSION, PROTOCOL_VERSION, DB_VERSION, NEARD_FEATURES ) });