Fixed an issue where capi did not have a tokio runtime

This commit is contained in:
Johnathan Sharratt
2023-06-27 15:18:20 +10:00
parent 6f475ecf4e
commit 45825d7be4
3 changed files with 10 additions and 0 deletions

View File

@ -42,6 +42,7 @@ libc = { version = "^0.2", default-features = false }
thiserror = "1"
typetag = { version = "0.1", optional = true }
paste = "1.0"
tokio = { version = "1", features = [ "rt", "rt-multi-thread", "io-util", "sync", "macros"], default_features = false }
[dev-dependencies]
field-offset = "0.3.3"

View File

@ -30,6 +30,7 @@ pub struct wasi_config_t {
inherit_stderr: bool,
inherit_stdin: bool,
builder: WasiEnvBuilder,
runtime: tokio::runtime::Runtime,
}
#[no_mangle]
@ -41,11 +42,18 @@ pub unsafe extern "C" fn wasi_config_new(
let name_c_str = CStr::from_ptr(program_name);
let prog_name = c_try!(name_c_str.to_str());
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
let _guard = runtime.enter();
Some(Box::new(wasi_config_t {
inherit_stdout: true,
inherit_stderr: true,
inherit_stdin: true,
builder: WasiEnv::builder(prog_name).fs(default_fs_backing()),
runtime,
}))
}