bytecodealliance / javy

JS to WebAssembly toolchain
Apache License 2.0
2.15k stars 102 forks source link

Can javy receive command line args / env. Are they in scope? #592

Open ieugen opened 7 months ago

ieugen commented 7 months ago

What is your question?

This is probably a noob question, but here it goes:

Would it be possible to pass command line options to a wasm module? How about environment variables ?!

I've read https://github.com/bytecodealliance/javy#invoking-javy-generated-modules-programatically .

jeffcharles commented 7 months ago

WASI preview 1 supports environment variables and command line arguments and Javy modules are compiled as WASI preview 1 Wasm modules. However, Javy does not currently expose APIs to read environment variables or command line arguments to the JavaScript source code it runs.

We'd be open to a contribution adding those APIs! But I'd recommend proposing and aligning on what those APIs would look like before writing too much code given there isn't a standard API in JavaScript for reading environment variables and command line arguments.

ieugen commented 7 months ago

Hi @jeffcharles ,

Can be added under Javy object? https://github.com/bytecodealliance/javy/blob/main/npm/javy/src/index.ts

The API could be the same / similar API that nodejs exposes. but under Javy:

The data is an array and a map / JS object . WDYT?

jeffcharles commented 7 months ago

Have you read through https://github.com/bytecodealliance/javy/blob/main/docs/contributing-architecture.md#javy-apis?

The APIs you're proposing make sense to me!

I guess before we go too far down this path, what's your use case for getting command line arguments and environment variables?

ieugen commented 7 months ago

Have you read through https://github.com/bytecodealliance/javy/blob/main/docs/contributing-architecture.md#javy-apis?

No I haven't . Just discovered the process yesterday and I made this https://github.com/ieugen/cherry-wasm-demo . Right now I want to experiment and see how far can I go with Clojure(Script) and wasm.

I do DevOps so my focus will be on making some CLI's and tooling to help with that.

== Some time into the future My big dream is to be push WASM apps to something like a OCI registry https://opencontainers.org/posts/blog/2023-07-07-summary-of-upcoming-changes-in-oci-image-and-distribution-specs-v-1-1/ .

This should make app distribution on systems very robust and easy (one tool to install any app / software package you want) . being wasm should work on any architecture. There are also offerings of private OCI registry hosting so you can get a highly available one if you need. And also self hosted versions.

jeffcharles commented 7 months ago

No I haven't . Just discovered the process yesterday and I made this https://github.com/ieugen/cherry-wasm-demo .

Alright, take a look at the process for adding a new API there and let me know if you have any questions!

My big dream is to be push WASM apps to something like a OCI registry https://opencontainers.org/posts/blog/2023-07-07-summary-of-upcoming-changes-in-oci-image-and-distribution-specs-v-1-1/ .

Have you taken a look at warg?

ieugen commented 7 months ago

Alright, take a look at the process for adding a new API there and let me know if you have any questions!

Can you teach me rust ? :D

Have you taken a look at warg? I am looking now. thanks.

jeffcharles commented 7 months ago

Can you teach me rust ? :D

Unfortunately I would not have time haha! I used Rustlings and Exercism to learn in the past. And fortunately the changes involved are not too difficult in terms of the amount of Rust knowledge that would be necessary to learn.

ieugen commented 7 months ago

I was able to build javy on my system. Will see what I can do with the others. Thanks.

ieugen commented 7 months ago

@jeffcharles : Is wasmtime 17 necessary for this work? https://github.com/bytecodealliance/wasmtime/releases/tag/v17.0.0

It does include wasi preview 2 with env vars and cli args and other things. I noticed javy uses wasmtime 16 for now.

If that is the case, is there a plan /estimate to update to wasmtime 17 ?

jeffcharles commented 6 months ago

Wasmtime 17 shouldn't be necessary since Javy will continue to target WASI preview 1 for now.