Skip to content

Commit

Permalink
Enable env_logger in the C API
Browse files Browse the repository at this point in the history
This commit ensures that `env_logger` and `RUST_LOG` are configured to
work with the C API.
  • Loading branch information
alexcrichton committed May 21, 2020
1 parent c9e3b71 commit a9499ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions crates/c-api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ wasmtime_c_api_macros::declare_own!(wasm_engine_t);

#[no_mangle]
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 {
engine: HostRef::new(Engine::default()),
})
Expand Down

0 comments on commit a9499ec

Please sign in to comment.