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

Add extended version information to wasmtime --version #7610

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
29 changes: 29 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use std::process::Command;
fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=build.rs");

set_commit_info_for_rustc();

let out_dir = PathBuf::from(
env::var_os("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
);
Expand Down Expand Up @@ -281,3 +283,30 @@ fn ignore(testsuite: &str, testname: &str, strategy: &str) -> bool {
_ => false,
}
}

fn set_commit_info_for_rustc() {
if !Path::new(".git").exists() {
return;
}
let output = match Command::new("git")
.arg("log")
.arg("-1")
.arg("--date=short")
.arg("--format=%H %h %cd")
.arg("--abbrev=9")
.output()
{
Ok(output) if output.status.success() => output,
_ => return,
};
let stdout = String::from_utf8(output.stdout).unwrap();
let mut parts = stdout.split_whitespace();
let mut next = || parts.next().unwrap();
println!("cargo:rustc-env=WASMTIME_GIT_HASH={}", next());
println!(
"cargo:rustc-env=WASMTIME_VERSION_INFO={} ({} {})",
env!("CARGO_PKG_VERSION"),
next(),
next()
);
}
7 changes: 6 additions & 1 deletion src/bin/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap::Parser;
/// Wasmtime WebAssembly Runtime
#[derive(Parser, PartialEq)]
#[clap(
version,
version = version(),
after_help = "If a subcommand is not provided, the `run` subcommand will be used.\n\
\n\
Usage examples:\n\
Expand Down Expand Up @@ -40,6 +40,11 @@ struct Wasmtime {
run: wasmtime_cli::commands::RunCommand,
}

/// If WASMTIME_VERSION_INFO is set, use it, otherwise use CARGO_PKG_VERSION.
fn version() -> &'static str {
option_env!("WASMTIME_VERSION_INFO").unwrap_or(env!("CARGO_PKG_VERSION"))
}

#[derive(Parser, PartialEq)]
enum Subcommand {
/// Runs a WebAssembly module
Expand Down