diff --git a/Cargo.lock b/Cargo.lock index d5d3341b38..e3ea54b176 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4337,8 +4337,6 @@ dependencies = [ "tracing", "urlencoding", "utoipa", - "vergen", - "vergen-gitcl", ] [[package]] @@ -4499,6 +4497,7 @@ dependencies = [ "indoc", "lz4_flex", "namespace", + "once_cell", "pegboard", "pegboard-runner", "pegboard-serverless", @@ -4935,6 +4934,8 @@ dependencies = [ "url", "utoipa", "uuid", + "vergen", + "vergen-gitcl", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fc88edc9fc..f90578c745 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,7 +149,7 @@ features = ["now"] [workspace.dependencies.clap] version = "4.3" -features = ["derive"] +features = ["derive", "cargo"] [workspace.dependencies.rivet-term] git = "https://github.com/rivet-dev/rivet-term" diff --git a/engine/packages/api-public/Cargo.toml b/engine/packages/api-public/Cargo.toml index 77e6aa2f61..18d04cb394 100644 --- a/engine/packages/api-public/Cargo.toml +++ b/engine/packages/api-public/Cargo.toml @@ -36,5 +36,3 @@ utoipa.workspace = true [build-dependencies] anyhow.workspace = true fs_extra.workspace = true -vergen.workspace = true -vergen-gitcl.workspace = true diff --git a/engine/packages/api-public/build.rs b/engine/packages/api-public/build.rs index 36cbe97b44..975d29deab 100644 --- a/engine/packages/api-public/build.rs +++ b/engine/packages/api-public/build.rs @@ -5,14 +5,6 @@ use std::fs; use std::path::Path; fn main() -> Result<()> { - // Configure vergen to emit build metadata - vergen::Emitter::default() - .add_instructions(&vergen::BuildBuilder::all_build()?)? - .add_instructions(&vergen::CargoBuilder::all_cargo()?)? - .add_instructions(&vergen::RustcBuilder::all_rustc()?)? - .add_instructions(&vergen_gitcl::GitclBuilder::all_git()?)? - .emit()?; - let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap(); let ui_dir = Path::new(&out_dir).join("ui"); diff --git a/engine/packages/api-public/src/metadata.rs b/engine/packages/api-public/src/metadata.rs index 07cdfd8c5d..1a06f32376 100644 --- a/engine/packages/api-public/src/metadata.rs +++ b/engine/packages/api-public/src/metadata.rs @@ -1,6 +1,7 @@ use axum::Json; use axum::response::IntoResponse; use rivet_api_builder::extract::Extension; +use rivet_util::build_meta; use serde_json::json; use crate::ctx::ApiCtx; @@ -11,13 +12,13 @@ pub async fn get_metadata(Extension(ctx): Extension) -> impl IntoRespons ctx.skip_auth(); Json(json!({ - "runtime": "engine", - "version": env!("CARGO_PKG_VERSION"), - "git_sha": env!("VERGEN_GIT_SHA"), - "build_timestamp": env!("VERGEN_BUILD_TIMESTAMP"), - "rustc_version": env!("VERGEN_RUSTC_SEMVER"), - "rustc_host": env!("VERGEN_RUSTC_HOST_TRIPLE"), - "cargo_target": env!("VERGEN_CARGO_TARGET_TRIPLE"), - "cargo_profile": if env!("VERGEN_CARGO_DEBUG") == "true" { "debug" } else { "release" } + "runtime": build_meta::RUNTIME, + "version": build_meta::VERSION, + "git_sha": build_meta::GIT_SHA, + "build_timestamp": build_meta::BUILD_TIMESTAMP, + "rustc_version": build_meta::RUSTC_VERSION, + "rustc_host": build_meta::RUSTC_HOST, + "cargo_target": build_meta::CARGO_TARGET, + "cargo_profile": build_meta::cargo_profile() })) } diff --git a/engine/packages/engine/Cargo.toml b/engine/packages/engine/Cargo.toml index efda95749f..5ec6d4b841 100644 --- a/engine/packages/engine/Cargo.toml +++ b/engine/packages/engine/Cargo.toml @@ -20,6 +20,7 @@ hex.workspace = true include_dir.workspace = true indoc.workspace = true lz4_flex.workspace = true +once_cell.workspace = true pegboard-runner.workspace = true pegboard-serverless.workspace = true reqwest.workspace = true diff --git a/engine/packages/engine/src/main.rs b/engine/packages/engine/src/main.rs index b352e28ce4..7c1aa10de4 100644 --- a/engine/packages/engine/src/main.rs +++ b/engine/packages/engine/src/main.rs @@ -2,10 +2,25 @@ use std::{path::PathBuf, sync::Arc}; use anyhow::*; use clap::Parser; +use once_cell::sync::Lazy; use rivet_engine::{SubCommand, run_config}; +use rivet_util::build_meta; + +static LONG_VERSION: Lazy = Lazy::new(|| { + format!( + "{}\nGit SHA: {}\nBuild Timestamp: {}\nRustc Version: {}\nRustc Host: {}\nCargo Target: {}\nCargo Profile: {}", + build_meta::VERSION, + build_meta::GIT_SHA, + build_meta::BUILD_TIMESTAMP, + build_meta::RUSTC_VERSION, + build_meta::RUSTC_HOST, + build_meta::CARGO_TARGET, + build_meta::cargo_profile() + ) +}); #[derive(Parser)] -#[command(name = "Rivet", version, about)] +#[command(name = "Rivet", version, long_version = LONG_VERSION.as_str(), about)] struct Cli { #[command(subcommand)] command: SubCommand, diff --git a/engine/packages/util/Cargo.toml b/engine/packages/util/Cargo.toml index ae306cf3d3..32e55dcaaa 100644 --- a/engine/packages/util/Cargo.toml +++ b/engine/packages/util/Cargo.toml @@ -34,3 +34,8 @@ tracing.workspace = true url.workspace = true uuid.workspace = true utoipa.workspace = true + +[build-dependencies] +anyhow.workspace = true +vergen.workspace = true +vergen-gitcl.workspace = true diff --git a/engine/packages/util/build.rs b/engine/packages/util/build.rs new file mode 100644 index 0000000000..8ecec41e3b --- /dev/null +++ b/engine/packages/util/build.rs @@ -0,0 +1,13 @@ +use anyhow::Result; + +fn main() -> Result<()> { + // Configure vergen to emit build metadata + vergen::Emitter::default() + .add_instructions(&vergen::BuildBuilder::all_build()?)? + .add_instructions(&vergen::CargoBuilder::all_cargo()?)? + .add_instructions(&vergen::RustcBuilder::all_rustc()?)? + .add_instructions(&vergen_gitcl::GitclBuilder::all_git()?)? + .emit()?; + + Ok(()) +} diff --git a/engine/packages/util/src/build_meta.rs b/engine/packages/util/src/build_meta.rs new file mode 100644 index 0000000000..f5d808d59b --- /dev/null +++ b/engine/packages/util/src/build_meta.rs @@ -0,0 +1,33 @@ +/// Runtime identifier for the engine +pub const RUNTIME: &str = "engine"; + +/// Package version from Cargo.toml +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); + +/// Git commit SHA +pub const GIT_SHA: &str = env!("VERGEN_GIT_SHA"); + +/// Build timestamp +pub const BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP"); + +/// Rustc version used to compile +pub const RUSTC_VERSION: &str = env!("VERGEN_RUSTC_SEMVER"); + +/// Rustc host triple +pub const RUSTC_HOST: &str = env!("VERGEN_RUSTC_HOST_TRIPLE"); + +/// Cargo target triple +pub const CARGO_TARGET: &str = env!("VERGEN_CARGO_TARGET_TRIPLE"); + +/// Cargo debug flag as string +const CARGO_DEBUG: &str = env!("VERGEN_CARGO_DEBUG"); + +/// Cargo profile (debug or release) +/// Returns "debug" if VERGEN_CARGO_DEBUG is "true", otherwise "release" +pub fn cargo_profile() -> &'static str { + if CARGO_DEBUG == "true" { + "debug" + } else { + "release" + } +} diff --git a/engine/packages/util/src/lib.rs b/engine/packages/util/src/lib.rs index d69d627a2a..5a9037666f 100644 --- a/engine/packages/util/src/lib.rs +++ b/engine/packages/util/src/lib.rs @@ -3,6 +3,7 @@ pub use rivet_util_id as id; pub mod backoff; pub mod billing; +pub mod build_meta; pub mod check; pub mod duration; pub mod faker;