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

Environment variables are broken #181

Closed
syrusakbary opened this issue Mar 5, 2020 · 4 comments
Closed

Environment variables are broken #181

syrusakbary opened this issue Mar 5, 2020 · 4 comments

Comments

@syrusakbary
Copy link

syrusakbary commented Mar 5, 2020

I just encountered this issue when updating @wasmer/wasi to be compatible with wasi_snapshot_preview1).

Having this file:

use std::env;

fn main() {
    let existing = env::var_os("WASM_EXISTING");
    println!("should be set (WASM_EXISTING): {:?}", existing);
    let unexisting = env::var_os("WASM_UNEXISTING");
    println!("shouldn't be set (WASM_UNEXISTING): {:?}", unexisting);

    env::set_var("WASM_EXISTING", "NEW_VALUE");
    let existing = env::var_os("WASM_EXISTING");
    println!("Set existing var (WASM_EXISTING): {:?}", existing);
    env::set_var("WASM_UNEXISTING", "NEW_VALUE");
    let unexisting = env::var_os("WASM_UNEXISTING");
    println!("Set unexisting var (WASM_UNEXISTING): {:?}", unexisting);

    println!("All vars in env:");
    for (key, value) in env::vars() {
        println!("{}: {}", key, value);
    }
}

Compiling it with rustc env.rs --target wasm32-wasi -O

If running it without env vars:

wasmer packages/wasi/test/rs/wasi_snapshot_preview1/env.wasm

This will show the correct output:

should be set (WASM_EXISTING): None
shouldn't be set (WASM_UNEXISTING): None
Set existing var (WASM_EXISTING): Some("NEW_VALUE")
Set unexisting var (WASM_UNEXISTING): Some("NEW_VALUE")
All vars in env:
WASM_EXISTING: NEW_VALUE
WASM_UNEXISTING: NEW_VALUE

However, the following will fail (without printing anything) with error code 71:

wasmer packages/wasi/test/rs/wasi_snapshot_preview1/env.wasm --env "WASM_EXISTING=VALUE"

Note: this issue is independent of the runtime, it also happens in any other runtimes

@MarkMcCaskey
Copy link

I believe this was fixed in #159 but hasn't made it to stable Rust yet

@syrusakbary
Copy link
Author

Yeah, thanks for pointing it @MarkMcCaskey!

@syrusakbary
Copy link
Author

(to the maintainers: feel free to close this issue if is no longer relevant)

@tschneidereit
Copy link
Member

@MarkMcCaskey, thanks for clearing this up!

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

No branches or pull requests

3 participants