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

Added invoke option to the command #968

Merged
merged 5 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#968](https://github.com/wasmerio/wasmer/pull/968) Added `--invoke` option to the command
- [#925](https://github.com/wasmerio/wasmer/pull/925) Host functions can be closures with a captured environment.
- [#917](https://github.com/wasmerio/wasmer/pull/917) Host functions (aka imported functions) may not have `&mut vm::Ctx` as first argument, i.e. the presence of the `&mut vm::Ctx` argument is optional.
- [#915](https://github.com/wasmerio/wasmer/pull/915) All backends share the same definition of `Trampoline` (defined in `wasmer-runtime-core`).
Expand Down
10 changes: 9 additions & 1 deletion src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ struct Run {
)]
backend: Backend,

/// Invoke a specified function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "specify the name of the start function" or "of the main function" of something like that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not a main function, but a raw function that you might want to invoke.

#[structopt(long = "invoke", short = "i")]
invoke: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛳️

Consider:

#[structopt(long = "invoke", short = "i", default = "main")]
invoke: String

This is less flexible, but for the code as it is now, this is a cleaner solution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that much, because depending on the integration you use (emscripten, wasi, ...) the default might vary. Will go through the other approach


/// Emscripten symbol map
#[structopt(long = "em-symbol-map", parse(from_os_str), group = "emscripten")]
em_symbol_map: Option<PathBuf>,
Expand Down Expand Up @@ -683,8 +687,12 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
args.push(Value::I32(x));
}

let invoke_fn = match options.invoke.as_ref() {
Some(fun) => fun,
_ => "main",
};
syrusakbary marked this conversation as resolved.
Show resolved Hide resolved
instance
.dyn_func("main")
.dyn_func(&invoke_fn)
.map_err(|e| format!("{:?}", e))?
.call(&args)
.map_err(|e| format!("{:?}", e))?;
Expand Down