holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.72k stars 117 forks source link

environment variables are not available to unmodified WASI Wasm modules #79

Open dmitshur opened 4 years ago

dmitshur commented 4 years ago

Thank you for making a-Shell, it already brings me a lot of joy. This is a feature request.

It's possible to execute a WebAssembly module in a-Shell, as documented at https://github.com/holzschu/a-shell#programming--add-more-commands, which is very useful. However, environment variables that are set in the shell are not propagated to the executed program. As far as I can see, the relevant code is:

https://github.com/holzschu/a-shell/blob/7572fb5b82e3b17c38402067784a86fd236711a7/hterm.html#L128

Environment variables are a critical input for many existing programs, so many more useful programs could be compiled to WebAssembly and used in a-Shell if this is implemented.

holzschu commented 4 years ago

Environment variables should be available in webAssembly programs if they are queried through getenv and the code has been compiled with the adapted SDK (https://github.com/holzschu/wasi-sdk). Line 2368 in SceneDelegate.swift sends the getenv query to the system.

The underlying issue here is that the environment is shared between all windows and some environment variables (LINES and COLUMNS, at least) are specific to each window.

dmitshur commented 4 years ago

Environment variables should be available in webAssembly programs if they are queried through getenv and the code has been compiled with the adapted SDK (https://github.com/holzschu/wasi-sdk).

I see, thank you for pointing that out.

I'm using an experimental implementation of WASI support in Go at https://github.com/neelance/go/commits/wasi, so using the adapted SDK directly isn't an option for me, but I can certainly adjust things on my end by doing what the adapted SDK does to get environment variable values.

That said, please consider this a feature request to make it possible to get environment variables with an unmodified WASI SDK, if it's possible. It would be helpful as it would remove the need to do something different when compiling a WASI-enabled Wasm module, and the same binary could work in a-Shell as well as other environments that support WASI.

holzschu commented 4 years ago

You're right. I will.

holzschu commented 3 years ago

Access to environment variables with an unmodified WASI SDK will be in build 120 (soon to be in TestFlight). It's already available in the source code, if you're brave enough to compile the entire project.

holzschu commented 3 years ago

Access to environment variables with an unmodified WASI SDK is now available with the AppStore version (1.6.2). I am looking forward to applications using this experimental implementation of WASI support in Go.