Skip to content

Commit ba1623c

Browse files
committed
feat(engine): add long --version details (#3518)
1 parent e994210 commit ba1623c

File tree

11 files changed

+82
-22
lines changed

11 files changed

+82
-22
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ features = ["now"]
149149

150150
[workspace.dependencies.clap]
151151
version = "4.3"
152-
features = ["derive"]
152+
features = ["derive", "cargo"]
153153

154154
[workspace.dependencies.rivet-term]
155155
git = "https://github.com/rivet-dev/rivet-term"

engine/packages/api-public/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,3 @@ utoipa.workspace = true
3636
[build-dependencies]
3737
anyhow.workspace = true
3838
fs_extra.workspace = true
39-
vergen.workspace = true
40-
vergen-gitcl.workspace = true

engine/packages/api-public/build.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ use std::fs;
55
use std::path::Path;
66

77
fn main() -> Result<()> {
8-
// Configure vergen to emit build metadata
9-
vergen::Emitter::default()
10-
.add_instructions(&vergen::BuildBuilder::all_build()?)?
11-
.add_instructions(&vergen::CargoBuilder::all_cargo()?)?
12-
.add_instructions(&vergen::RustcBuilder::all_rustc()?)?
13-
.add_instructions(&vergen_gitcl::GitclBuilder::all_git()?)?
14-
.emit()?;
15-
168
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
179
let out_dir = env::var("OUT_DIR").unwrap();
1810
let ui_dir = Path::new(&out_dir).join("ui");
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use axum::Json;
22
use axum::response::IntoResponse;
33
use rivet_api_builder::extract::Extension;
4+
use rivet_util::build_meta;
45
use serde_json::json;
56

67
use crate::ctx::ApiCtx;
@@ -11,13 +12,13 @@ pub async fn get_metadata(Extension(ctx): Extension<ApiCtx>) -> impl IntoRespons
1112
ctx.skip_auth();
1213

1314
Json(json!({
14-
"runtime": "engine",
15-
"version": env!("CARGO_PKG_VERSION"),
16-
"git_sha": env!("VERGEN_GIT_SHA"),
17-
"build_timestamp": env!("VERGEN_BUILD_TIMESTAMP"),
18-
"rustc_version": env!("VERGEN_RUSTC_SEMVER"),
19-
"rustc_host": env!("VERGEN_RUSTC_HOST_TRIPLE"),
20-
"cargo_target": env!("VERGEN_CARGO_TARGET_TRIPLE"),
21-
"cargo_profile": if env!("VERGEN_CARGO_DEBUG") == "true" { "debug" } else { "release" }
15+
"runtime": build_meta::RUNTIME,
16+
"version": build_meta::VERSION,
17+
"git_sha": build_meta::GIT_SHA,
18+
"build_timestamp": build_meta::BUILD_TIMESTAMP,
19+
"rustc_version": build_meta::RUSTC_VERSION,
20+
"rustc_host": build_meta::RUSTC_HOST,
21+
"cargo_target": build_meta::CARGO_TARGET,
22+
"cargo_profile": build_meta::cargo_profile()
2223
}))
2324
}

engine/packages/engine/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ hex.workspace = true
2020
include_dir.workspace = true
2121
indoc.workspace = true
2222
lz4_flex.workspace = true
23+
once_cell.workspace = true
2324
pegboard-runner.workspace = true
2425
pegboard-serverless.workspace = true
2526
reqwest.workspace = true

engine/packages/engine/src/main.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@ use std::{path::PathBuf, sync::Arc};
22

33
use anyhow::*;
44
use clap::Parser;
5+
use once_cell::sync::Lazy;
56
use rivet_engine::{SubCommand, run_config};
7+
use rivet_util::build_meta;
8+
9+
static LONG_VERSION: Lazy<String> = Lazy::new(|| {
10+
format!(
11+
"{}\nGit SHA: {}\nBuild Timestamp: {}\nRustc Version: {}\nRustc Host: {}\nCargo Target: {}\nCargo Profile: {}",
12+
build_meta::VERSION,
13+
build_meta::GIT_SHA,
14+
build_meta::BUILD_TIMESTAMP,
15+
build_meta::RUSTC_VERSION,
16+
build_meta::RUSTC_HOST,
17+
build_meta::CARGO_TARGET,
18+
build_meta::cargo_profile()
19+
)
20+
});
621

722
#[derive(Parser)]
8-
#[command(name = "Rivet", version, about)]
23+
#[command(name = "Rivet", version, long_version = LONG_VERSION.as_str(), about)]
924
struct Cli {
1025
#[command(subcommand)]
1126
command: SubCommand,

engine/packages/util/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ tracing.workspace = true
3434
url.workspace = true
3535
uuid.workspace = true
3636
utoipa.workspace = true
37+
38+
[build-dependencies]
39+
anyhow.workspace = true
40+
vergen.workspace = true
41+
vergen-gitcl.workspace = true

engine/packages/util/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use anyhow::Result;
2+
3+
fn main() -> Result<()> {
4+
// Configure vergen to emit build metadata
5+
vergen::Emitter::default()
6+
.add_instructions(&vergen::BuildBuilder::all_build()?)?
7+
.add_instructions(&vergen::CargoBuilder::all_cargo()?)?
8+
.add_instructions(&vergen::RustcBuilder::all_rustc()?)?
9+
.add_instructions(&vergen_gitcl::GitclBuilder::all_git()?)?
10+
.emit()?;
11+
12+
Ok(())
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// Runtime identifier for the engine
2+
pub const RUNTIME: &str = "engine";
3+
4+
/// Package version from Cargo.toml
5+
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
6+
7+
/// Git commit SHA
8+
pub const GIT_SHA: &str = env!("VERGEN_GIT_SHA");
9+
10+
/// Build timestamp
11+
pub const BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
12+
13+
/// Rustc version used to compile
14+
pub const RUSTC_VERSION: &str = env!("VERGEN_RUSTC_SEMVER");
15+
16+
/// Rustc host triple
17+
pub const RUSTC_HOST: &str = env!("VERGEN_RUSTC_HOST_TRIPLE");
18+
19+
/// Cargo target triple
20+
pub const CARGO_TARGET: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
21+
22+
/// Cargo debug flag as string
23+
const CARGO_DEBUG: &str = env!("VERGEN_CARGO_DEBUG");
24+
25+
/// Cargo profile (debug or release)
26+
/// Returns "debug" if VERGEN_CARGO_DEBUG is "true", otherwise "release"
27+
pub fn cargo_profile() -> &'static str {
28+
if CARGO_DEBUG == "true" {
29+
"debug"
30+
} else {
31+
"release"
32+
}
33+
}

0 commit comments

Comments
 (0)