-
Notifications
You must be signed in to change notification settings - Fork 199
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
Environment variables don't work if main
isn't used
#180
Comments
Not sure if this is related: I encountered in programs with |
Closed
sunfishcode
added a commit
that referenced
this issue
Mar 10, 2020
This is the first in a series of PRs to make it easier to use WASI libc in Wasm modules that don't have a `main` function. By initializing the environment on demand, we avoid depending on having `__wasm_call_ctors` run. This uses weak symbols strategically to ensure that if `environ` is used, it is initialized eagerly, but if only `getenv` and friends are used, the environment is initialized lazily. Eventually, I expect we'll have a convention for wasm modules without main functions which will allow the `__wasm_call_ctors` function to be called automatically, but this helps in simple cases for now. Fixes #180.
sunfishcode
added a commit
that referenced
this issue
Mar 19, 2020
* Lazy-initialize the environment variables. This is the first in a series of PRs to make it easier to use WASI libc in Wasm modules that don't have a `main` function. By initializing the environment on demand, we avoid depending on having `__wasm_call_ctors` run. This uses weak symbols strategically to ensure that if `environ` is used, it is initialized eagerly, but if only `getenv` and friends are used, the environment is initialized lazily. Eventually, I expect we'll have a convention for wasm modules without main functions which will allow the `__wasm_call_ctors` function to be called automatically, but this helps in simple cases for now. Fixes #180. * Add comments explaining the libc-environ-compat.h header usage.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We discovered an issue in the Rust
wasm32-wasi
target today where a wasm binary usesstd::env
but doesn't end up importing the requisite wasi items to actually get env vars working.The broken example looks like this:
And when compiled:
This is showing that
environ_get
isn't imported at all!When compiled as a binary though it does indeed work:
I'm told that @sunfishcode is working on a fix!
The text was updated successfully, but these errors were encountered: