Skip to content
Open
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
125 changes: 98 additions & 27 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ tracing-bunyan-formatter = "0.3.3"
tracing-subscriber = "0.3.14"
usdt = { version = "0.6", default-features = false }
uuid = "1.3.2"
vergen-git2 = { version = "10.0.0" }
zerocopy = "0.8.25"


#
# It's common during development to use a local copy of various complex
# dependencies. If you want to use those, uncomment one of these blocks.
Expand Down
4 changes: 3 additions & 1 deletion bin/propolis-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn parse_log_level(s: &str) -> anyhow::Result<slog::Level> {
}

#[derive(Debug, Parser)]
#[clap(about, version)]
#[clap(about, version = propolis::version())]
/// An HTTP server providing access to Propolis
enum Args {
/// Runs the Propolis server.
Expand Down Expand Up @@ -122,6 +122,8 @@ fn run_server(
) -> anyhow::Result<()> {
use propolis::api_version;

slog::info!(log, "Running {}", propolis::version());

// Check that devices conform to expected API version
if let Err(e) = api_version::check() {
use api_version::{Error, VersionCheckError};
Expand Down
3 changes: 3 additions & 0 deletions bin/propolis-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ fn api_version_checks(log: &slog::Logger) -> std::io::Result<()> {
}

#[derive(clap::Parser)]
#[clap(version = propolis::version())]
/// Propolis command-line frontend for running a VM.
struct Args {
/// Either the VM config file or a previously captured snapshot image.
Expand Down Expand Up @@ -1624,6 +1625,8 @@ fn main() -> anyhow::Result<ExitCode> {

let log = build_log(log_level);

slog::info!(log, "Running {}", propolis::version());

// Check that vmm and viona device version match what we expect
api_version_checks(&log).context("API version checks")?;

Expand Down
4 changes: 4 additions & 0 deletions lib/propolis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ softnpu = { workspace = true, optional = true }
dlpi = { workspace = true, optional = true }
static_assertions = "1.1.0"

[build-dependencies]
anyhow.workspace = true
vergen-git2.workspace = true

[dev-dependencies]
crossbeam-channel.workspace = true
tempfile.workspace = true
Expand Down
18 changes: 18 additions & 0 deletions lib/propolis/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

fn main() -> anyhow::Result<()> {
let git2 = vergen_git2::Git2::builder()
.branch(true)
.commit_count(true)
.dirty(true)
.sha(true)
.build();
vergen_git2::Emitter::default()
.idempotent()
.add_instructions(&git2)?
.emit()?;

Ok(())
}
73 changes: 73 additions & 0 deletions lib/propolis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,76 @@ pub mod vsock;

pub use exits::{VmEntry, VmExit};
pub use vmm::Machine;

pub fn version() -> &'static str {
lazy_static::lazy_static! {
static ref VERSION: String = {
use std::fmt::Write;

let git = match (
option_env!("VERGEN_GIT_BRANCH"),
option_env!("VERGEN_GIT_SHA"),
option_env!("VERGEN_GIT_COMMIT_COUNT"),
option_env!("VERGEN_GIT_DIRTY"),
) {
(Some(branch), Some(sha), Some(commit), Some(dirty)) => {
Some((branch, sha, commit, dirty))
},
_ => {
None
}
};

let mut version = format!("v{}", env!("CARGO_PKG_VERSION"));
if let Some((branch, sha, commit, dirty)) = git {
write!(version, "-{commit} ").unwrap();
let sha_prefix = sha.get(..9).unwrap_or(sha);
if dirty == "true" {
write!(version, "(DIRTY {sha_prefix}) ").unwrap();
} else {
write!(version, "({sha_prefix}) ").unwrap();
}
write!(version, "{branch}").unwrap();
} else {
version.push_str(" <unknown git commit>");
}

version.push_str(", ");
match bhyve_api::api_version() {
Ok(v) => {
write!(version, "bhyve API v{v}").unwrap();
}
Err(_) => {
version.push_str("<unknown bhyve API version>");
}
}

version.push_str(", ");
match viona_api::api_version() {
Ok(v) => {
write!(version, "viona API v{v}").unwrap();
}
Err(_) => {
version.push_str("<unknown viona API version>");
}
}

version
};
};
&VERSION
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn print_version() {
let v = version();
eprintln!("propolis {v}");
assert!(v.contains(env!("CARGO_PKG_VERSION")));
assert!(v.contains("bhyve API"));
assert!(v.contains("viona API"));
}
}
Loading