Enable env_logger in the C API (#1737)
This commit ensures that `env_logger` and `RUST_LOG` are configured to work with the C API.
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -2188,6 +2188,7 @@ name = "wasmtime-c-api"
|
|||||||
version = "0.16.0"
|
version = "0.16.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"env_logger 0.7.1",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"wasi-common",
|
"wasi-common",
|
||||||
"wasmtime",
|
"wasmtime",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ test = false
|
|||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
env_logger = "0.7"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
once_cell = "1.3"
|
once_cell = "1.3"
|
||||||
wasmtime = { path = "../wasmtime", default-features = false }
|
wasmtime = { path = "../wasmtime", default-features = false }
|
||||||
|
|||||||
@@ -11,6 +11,16 @@ wasmtime_c_api_macros::declare_own!(wasm_engine_t);
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
|
// Enable the `env_logger` crate since this is as good a place as any to
|
||||||
|
// support some "top level initialization" for the C API. Almost all support
|
||||||
|
// should go through this one way or another, so this ensures that
|
||||||
|
// `RUST_LOG` should work reasonably well.
|
||||||
|
//
|
||||||
|
// Note that we `drop` the result here since this fails after the first
|
||||||
|
// initialization attempt. We don't mind that though because this function
|
||||||
|
// can be called multiple times, so we just ignore the result.
|
||||||
|
drop(env_logger::try_init());
|
||||||
|
|
||||||
Box::new(wasm_engine_t {
|
Box::new(wasm_engine_t {
|
||||||
engine: HostRef::new(Engine::default()),
|
engine: HostRef::new(Engine::default()),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user