Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve --version for non-releases #495

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [BREAKING] Renamed `off-chain` and `on-chain` to `private` and `public` respectively for the account storage modes (#489).
- Optimized state synchronizations by removing unnecessary fetching and parsing of note details (#462).
- [BREAKING] Changed `GetAccountDetailsResponse` field to `details` (#481).
- Improve `--version` by adding build metadata (#495).

## 0.5.1 (2024-09-12)

Expand Down
196 changes: 196 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion bin/faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ actix-cors = "0.7"
actix-web = "4.8"
actix-web-static-files = "4.0"
async-mutex = "1.4"
clap = { version = "4.5", features = ["derive"] }
clap = { version = "4.5", features = ["derive", "string"] }
derive_more = "0.99"
figment = { version = "0.10", features = ["toml", "env"] }
miden-lib = { workspace = true, features = ["concurrent"] }
Expand All @@ -39,4 +39,6 @@ tonic = { workspace = true }
tracing = { workspace = true }

[build-dependencies]
# Required to inject build metadata.
miden-node-utils = { workspace = true, features = ["vergen"] }
static-files = "0.2"
13 changes: 11 additions & 2 deletions bin/faucet/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
use std::str::FromStr;

fn main() -> std::io::Result<()> {
/// Embeds static faucet website files and generates build metadata for --version.
fn main() {
// The location of our static faucet website files.
let static_dir = std::path::PathBuf::from_str(std::env!("CARGO_MANIFEST_DIR"))
.unwrap()
.join("src")
.join("static");
println!("cargo::rerun-if-changed={}", static_dir.to_str().expect("Valid utf-8"));
// This makes the static files available as an embedded resource.
static_files::resource_dir(static_dir).build()
static_files::resource_dir(static_dir).build().expect("Resources should build");

// Configures environment variables for build metadata intended for extended version
// information.
if let Err(e) = miden_node_utils::version::vergen() {
// Don't let an error here bring down the build. Build metadata will be empty which isn't a
// critical failure.
println!("cargo:warning=Failed to embed build metadata: {e:?}");
}
}
21 changes: 19 additions & 2 deletions bin/faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use actix_web::{
};
use clap::{Parser, Subcommand};
use errors::FaucetError;
use miden_node_utils::config::load_config;
use miden_node_utils::{config::load_config, version::LongVersion};
use state::FaucetState;
use tracing::info;

Expand All @@ -32,7 +32,7 @@ const FAUCET_CONFIG_FILE_PATH: &str = "miden-faucet.toml";
// ================================================================================================

#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(version, about, long_about = None, long_version = long_version().to_string())]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
Expand Down Expand Up @@ -129,3 +129,20 @@ async fn main() -> Result<(), FaucetError> {
mod static_resources {
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
}

/// Generates [LongVersion] using the metadata generated by build.rs.
fn long_version() -> LongVersion {
// Use optional to allow for build script embedding failure.
LongVersion {
version: env!("CARGO_PKG_VERSION"),
sha: option_env!("VERGEN_GIT_SHA").unwrap_or_default(),
branch: option_env!("VERGEN_GIT_BRANCH").unwrap_or_default(),
dirty: option_env!("VERGEN_GIT_DIRTY").unwrap_or_default(),
features: option_env!("VERGEN_CARGO_FEATURES").unwrap_or_default(),
rust_version: option_env!("VERGEN_RUSTC_SEMVER").unwrap_or_default(),
host: option_env!("VERGEN_RUSTC_HOST_TRIPLE").unwrap_or_default(),
target: option_env!("VERGEN_CARGO_TARGET_TRIPLE").unwrap_or_default(),
opt_level: option_env!("VERGEN_CARGO_OPT_LEVEL").unwrap_or_default(),
debug: option_env!("VERGEN_CARGO_DEBUG").unwrap_or_default(),
}
}
6 changes: 5 additions & 1 deletion bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tracing-forest = ["miden-node-block-producer/tracing-forest"]

[dependencies]
anyhow = { version = "1.0" }
clap = { version = "4.5", features = ["derive"] }
clap = { version = "4.5", features = ["derive", "string"] }
Mirko-von-Leipzig marked this conversation as resolved.
Show resolved Hide resolved
miden-lib = { workspace = true, features = ["concurrent"] }
miden-node-block-producer = { workspace = true }
miden-node-rpc = { workspace = true }
Expand All @@ -36,3 +36,7 @@ tracing-subscriber = { workspace = true }
[dev-dependencies]
figment = { version = "0.10", features = ["toml", "env", "test"] }
miden-node-utils = { workspace = true, features = ["tracing-forest"] }

[build-dependencies]
# Required to inject build metadata.
miden-node-utils = { workspace = true, features = ["vergen"] }
9 changes: 9 additions & 0 deletions bin/node/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
// Configures environment variables for build metadata intended for extended version
// information.
if let Err(e) = miden_node_utils::version::vergen() {
// Don't let an error here bring down the build. Build metadata will be empty which isn't a
// critical failure.
println!("cargo:warning=Failed to embed build metadata: {e:?}");
}
}
Loading
Loading