bytecodealliance / javy

JS to WebAssembly toolchain
Apache License 2.0
2.3k stars 111 forks source link

CLI: Allow Input from stdin and Output to stdout #701

Open konradkoschel opened 4 months ago

konradkoschel commented 4 months ago

Description of the change

In this PR, the CLI crate is enhanced so that a hyphen (-) can be passed for the input argument or the output option instead of a file name indicating that stdio streams should be used.

Possible usage

# Use stdin for input and file for output
echo "console.log('Hello World!');" | javy compile - -o my.wasm

# Pipe wasm output into another command
javy compile my.js -o - | wasm-opt ...

# Use no files at all
echo "console.log('Hello World!');" | javy compile - -o - | wasm-opt ...

Why am I making this change?

I built a wrapper around Javy. The wrapper is not inherently working with files, but to make it work with Javy, I need to write the JavaScript to the filesystem and read the WASM from the filesystem.

Generally, the changes make the CLI of Javy more flexible.

Checklist

konradkoschel commented 4 months ago

Thanks for the PR -- generally these changes seem reasonable to me. One thing to note is that we're currently thinking of revamping Javy's CLI interface (see #702).

Given that our intention is to move in the direction described in the issue linked above, it probably makes sense to include this change as part of the new build command. That said, you're not expected to take on the CLI changes, for this change to land. However, I'd like to ask if you're ok waiting until we at least introduce the command that will replace the current compile command in order to merge this?

Hi, thanks for the fast response! I agree on the point that it makes sense to incorporate the functionality into the upcoming build command. From my point of view, the option to use the standard streams as input and output for Javy is a nice addition, but it is not too urgent. So I can surely wait :)

saulecabrera commented 2 months ago

Hi @konradkoschel, wanted to let you know that most of the backing infrastructure for the CLI redesign has landed on main, and I think it's now a good time to rebase, update and move forward with this change. Let me know if you have any questions.

konradkoschel commented 2 months ago

Hi @konradkoschel, wanted to let you know that most of the backing infrastructure for the CLI redesign has landed on main, and I think it's now a good time to rebase, update and move forward with this change. Let me know if you have any questions.

Hi Saul,

I updated the branch. Could you check if the code changes are fine?

As discussed previously, I made the binary output the default instead of -o - as in the original implementation. Tests run successful on my side