Skip to content

Commit

Permalink
feat: add version flag to all the shims
Browse files Browse the repository at this point in the history
Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
  • Loading branch information
Mossaka committed Aug 24, 2023
1 parent c83ea96 commit 0344777
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/containerd-shim-wasmedge/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::process::Command;
use std::str::from_utf8;

fn main() {
let output = match Command::new("git").arg("rev-parse").arg("HEAD").output() {
Ok(output) => output,
Err(_) => {
return;
}
};
let mut hash = from_utf8(&output.stdout).unwrap().trim().to_string();

let output_dirty = match Command::new("git").arg("diff").arg("--exit-code").output() {
Ok(output) => output,
Err(_) => {
return;
}
};

if !output_dirty.status.success() {
hash.push_str(".m");
}
println!("cargo:rustc-env=CARGO_GIT_HASH={}", hash);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use containerd_shim as shim;
use containerd_shim_wasm::sandbox::ShimCli;
use containerd_shim_wasmedge::instance::Wasi as WasiInstance;
use containerd_shim_wasmedge::parse_version;

fn main() {
parse_version();
shim::run::<ShimCli<WasiInstance>>("io.containerd.wasmedge.v1", None);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use containerd_shim as shim;
use containerd_shim_wasm::sandbox::manager::Shim;
use containerd_shim_wasmedge::parse_version;

fn main() {
parse_version();
shim::run::<Shim>("containerd-shim-wasmedged-v1", None)
}
17 changes: 17 additions & 0 deletions crates/containerd-shim-wasmedge/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::env;

use containerd_shim::parse;

pub mod error;

#[cfg_attr(unix, path = "instance/instance_linux.rs")]
Expand All @@ -8,6 +12,19 @@ pub mod oci_utils;
#[cfg(unix)]
pub mod executor;

pub fn parse_version() {
let os_args: Vec<_> = env::args_os().collect();
let flags = parse(&os_args[1..]).unwrap();
if flags.version {
println!("{}:", os_args[0].to_string_lossy());
println!(" Version: {}", env!("CARGO_PKG_VERSION"));
println!(" Revision: {}", env!("CARGO_GIT_HASH"));
println!();

std::process::exit(0);
}
}

#[cfg(unix)]
#[cfg(test)]
mod test {
Expand Down
24 changes: 24 additions & 0 deletions crates/containerd-shim-wasmtime/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::process::Command;
use std::str::from_utf8;

fn main() {
let output = match Command::new("git").arg("rev-parse").arg("HEAD").output() {
Ok(output) => output,
Err(_) => {
return;
}
};
let mut hash = from_utf8(&output.stdout).unwrap().trim().to_string();

let output_dirty = match Command::new("git").arg("diff").arg("--exit-code").output() {
Ok(output) => output,
Err(_) => {
return;
}
};

if !output_dirty.status.success() {
hash.push_str(".m");
}
println!("cargo:rustc-env=CARGO_GIT_HASH={}", hash);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use containerd_shim as shim;
use containerd_shim_wasm::sandbox::ShimCli;
use containerd_shim_wasmtime::instance::Wasi as WasiInstance;
use containerd_shim_wasmtime::parse_version;

fn main() {
parse_version();
shim::run::<ShimCli<WasiInstance>>("io.containerd.wasmtime.v1", None);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use containerd_shim as shim;
use containerd_shim_wasm::sandbox::manager::Shim;
use containerd_shim_wasmtime::parse_version;

fn main() {
parse_version();
shim::run::<Shim>("containerd-shim-wasmtimed-v1", None)
}
17 changes: 17 additions & 0 deletions crates/containerd-shim-wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::env;

use containerd_shim::parse;

pub mod error;
#[cfg_attr(unix, path = "instance/instance_linux.rs")]
#[cfg_attr(windows, path = "instance/instance_windows.rs")]
Expand All @@ -6,3 +10,16 @@ pub mod oci_wasmtime;

#[cfg(unix)]
pub mod executor;

pub fn parse_version() {
let os_args: Vec<_> = env::args_os().collect();
let flags = parse(&os_args[1..]).unwrap();
if flags.version {
println!("{}:", os_args[0].to_string_lossy());
println!(" Version: {}", env!("CARGO_PKG_VERSION"));
println!(" Revision: {}", env!("CARGO_GIT_HASH"));
println!();

std::process::exit(0);
}
}

0 comments on commit 0344777

Please sign in to comment.