diff --git a/Cargo.lock b/Cargo.lock index 33dc454f5f50..0859dec9bd46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2188,6 +2188,7 @@ name = "wasmtime-c-api" version = "0.16.0" dependencies = [ "anyhow", + "env_logger 0.7.1", "once_cell", "wasi-common", "wasmtime", diff --git a/crates/c-api/Cargo.toml b/crates/c-api/Cargo.toml index b4ebb8c28ecd..8618634035d2 100644 --- a/crates/c-api/Cargo.toml +++ b/crates/c-api/Cargo.toml @@ -17,6 +17,7 @@ test = false doctest = false [dependencies] +env_logger = "0.7" anyhow = "1.0" once_cell = "1.3" wasmtime = { path = "../wasmtime", default-features = false } diff --git a/crates/c-api/src/engine.rs b/crates/c-api/src/engine.rs index 38f0e985dbb5..843c261ea631 100644 --- a/crates/c-api/src/engine.rs +++ b/crates/c-api/src/engine.rs @@ -11,6 +11,16 @@ wasmtime_c_api_macros::declare_own!(wasm_engine_t); #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { + // 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 { engine: HostRef::new(Engine::default()), })