-
Notifications
You must be signed in to change notification settings - Fork 96
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
feat: add version flag to all the shims #268
Conversation
suggestion: use https://crates.io/crates/git-version and remove the build scripts. |
https://crates.io/crates/git-version uses ./target/debug/containerd-shim-wasmedge-v1:
Version: 0.1.1
Revision: containerd-shim-wasm/v0.1.2-278-ged85c04-modified |
Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
Could we use const fn get_rev() -> &'static str {
compile_time_run::run_command_str!("sh", "-c", "echo -n $(git rev-parse --short=10 HEAD)$(git diff --quiet || echo .m)")
} |
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: create a containerd_shim_wasm::run
function that takes the version / revision, and handles this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a good way to handle this in containerd-shim-wasm crate, as each shim implementation still needs to read os args, parse flags and get the version / revision... Could not save much logic here. With that said, I will leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant something like:
// somewhere in containerd-shim-wasm
pub fn run<Shim: ...>(runtime_id: &str, opts: Option<Config>, version: &str, revision: &str) {
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);
}
shim::run::<Shim>(runtime_id, opts)
}
and
// in main.rs
use containerd_shim_wasm::run;
fn main() {
run::<ShimCli<WasiInstance>>(
"io.containerd.wasmtime.v1",
None,
env!("CARGO_PKG_VERSION"),
env!("CARGO_GIT_HASH"),
);
}
then you can remove parse_version
from all the lib.rs
I am a bit hesitate because it introduces an external library basically doing the same thing we want in |
Haha, the opposite for me. I prefer the extra dep than adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking good. Some comments on ongoing discussions, but nothing major.
I will merge now! Thank you @jprendes |
This follows the PR containerd/rust-extensions#167