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

impemented --runtime-args flag #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

impemented --runtime-args flag #19

wants to merge 3 commits into from

Conversation

ibaryshnikov
Copy link
Contributor

@ibaryshnikov ibaryshnikov commented Nov 16, 2019

This pr adds the ability to pass arguments to runtime using --runtime-args flag.
At the moment I made a naive implementation of split_args function to separate arguments intended for binary from ones intended for runtime. Is it planned to use a library like clap or structopt? It may simplify the work with arguments a bit

Closes #17

@@ -177,9 +177,11 @@ fn rmain(config: &mut Config) -> Result<()> {

for run in build.runs.iter() {
config.status("Running", &format!("`{}`", run.join(" ")));
let (runtime_args, binary_args) = utils::split_args(run);
Copy link
Member

Choose a reason for hiding this comment

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

I believe the way we'll want to handle this is do some option parsing before the -- argument. Ideally this would use a full-fledged option parser, but we'll want to recognize --runtime-args as an argument to cargo wasi run, but not forward the argument to cargo run.

Put another way, --runtime-args is a flag to cargo wasi run, which means it needs to go before the --.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally this would use a full-fledged option parser

which one would you suggest to use here?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have one in mind per se, I haven't looked into doing this yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just pushed an example using structopt. What do you think about it? Is it viable to continue this way?

@alexcrichton
Copy link
Member

So the main thing to handle here is definitely the option parsing. We'll want to be careful to not do this with simple string iteration but to instead us some form of an argument parser. For example, although weird, something could look like --pass-as-an-argument "--runtime-args" and we'd accidentally misinterpret that.

The easiest, although still difficult, solution that I can think of is to copy Cargo's help text and option parsing into cargo wasi. We'd then augment it with --runtime-args for the run/bench/test/etc cases and would use that option parser to read off the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Granting access to files
2 participants