Skip to content

Commit

Permalink
Merge pull request #27 from iawia002/version-info
Browse files Browse the repository at this point in the history
Customize the version information output for CLI
  • Loading branch information
iawia002 authored Dec 21, 2023
2 parents 1d3b80a + 2d7ceab commit 4d3d9f4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
26 changes: 26 additions & 0 deletions wacker-cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::process::Command;

fn main() {
set_commit_info_for_rustc();
}

fn set_commit_info_for_rustc() {
let output = match Command::new("git")
.arg("log")
.arg("-1")
.arg("--date=short")
.arg("--format=%H %h %cd")
.output()
{
// Something like: 1d3b80a2765e46a51290819b82f772dff09c2c49 1d3b80a 2023-12-21
Ok(output) if output.status.success() => String::from_utf8(output.stdout).unwrap(),
_ => return,
};
let mut parts = output.split_whitespace().skip(1);
println!(
"cargo:rustc-env=WACKER_VERSION_INFO={} ({} {})",
env!("CARGO_PKG_VERSION"),
parts.next().unwrap(),
parts.next().unwrap()
);
}
7 changes: 6 additions & 1 deletion wacker-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ use wacker::new_client;

#[derive(Parser)]
#[command(name = "wacker")]
#[command(author, version, about, long_about = None)]
#[command(author, version = version(), about, long_about = None)]
struct Wacker {
#[command(subcommand)]
subcommand: Subcommand,
}

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

#[derive(Parser)]
enum Subcommand {
/// Runs a WebAssembly module
Expand Down
26 changes: 26 additions & 0 deletions wacker-daemon/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::process::Command;

fn main() {
set_commit_info_for_rustc();
}

fn set_commit_info_for_rustc() {
let output = match Command::new("git")
.arg("log")
.arg("-1")
.arg("--date=short")
.arg("--format=%H %h %cd")
.output()
{
// Something like: 1d3b80a2765e46a51290819b82f772dff09c2c49 1d3b80a 2023-12-21
Ok(output) if output.status.success() => String::from_utf8(output.stdout).unwrap(),
_ => return,
};
let mut parts = output.split_whitespace().skip(1);
println!(
"cargo:rustc-env=WACKER_VERSION_INFO={} ({} {})",
env!("CARGO_PKG_VERSION"),
parts.next().unwrap(),
parts.next().unwrap()
);
}
7 changes: 6 additions & 1 deletion wacker-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ use wacker::{Config, ModulesServer, Server};

#[derive(Parser)]
#[command(name = "wackerd")]
#[command(author, version, about, long_about = None)]
#[command(author, version = version(), about, long_about = None)]
struct WackerDaemon {}

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

impl WackerDaemon {
async fn execute(self) -> Result<()> {
let config = Config::new()?;
Expand Down
1 change: 1 addition & 0 deletions wacker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ const_format = "0.2.32"
async-stream = "0.3.5"

[build-dependencies]
anyhow.workspace = true
tonic-build = "0.10.2"
4 changes: 3 additions & 1 deletion wacker/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
use anyhow::Result;

fn main() -> Result<()> {
tonic_build::compile_protos("proto/module.proto")?;
Ok(())
}

0 comments on commit 4d3d9f4

Please sign in to comment.