second-state / wasmedge-wasi-helper

A rust crate to call the wasm-wasi initialization helper function. https://crates.io/crates/wasmedge-wasi-helper
0 stars 0 forks source link

Not able to read env vars. #3

Closed vishalchandra closed 2 years ago

vishalchandra commented 2 years ago

Below is the code to use the wasi helper function. This is not able to read the env vars. The same rust code (excluding the wasi helper function and lines) is able to read the env vars and print them.

use std::env;
use wasmedge_wasi_helper::wasmedge_wasi_helper::_initialize;

fn main() {
    println!("Hello, world!");
    _initialize();
    println!("The env vars are as follows.");
    for (key, value) in env::vars() {
        println!("{}: {}", key, value);
    }
}

Following is the output on the terminal

wasm~ wasmedge examples/helper/target/wasm32-wasi/release/helper.wasm
Hello, world!
The env vars are as follows.
wasm~ uname -sr
Darwin 21.6.0
wasm~ uname -a                                                       
Darwin GLUE.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64
wasm~ wasmedge --version                                             
wasmedge version 0.11.1
wasm~ cargo --version                                                
cargo 1.64.0 (387270bc7 2022-09-16)

Thank you for your help.

vishalchandra commented 2 years ago

So the following works.

wasm~ wasmedge --env ENVVAR=VAR1 examples/helper/target/wasm32-wasi/release/helper.wasm 
Hello, world!
The env vars are as follows.
ENVVAR: VAR1

Might be a good idea to take a look at options for the wasmedge cli including for dir etc.