xref: /wasmtime-44.0.1/crates/c-api/src/engine.rs (revision 331b0dee)
1 use crate::wasm_config_t;
2 use wasmtime::Engine;
3 
4 #[repr(C)]
5 #[derive(Clone)]
6 pub struct wasm_engine_t {
7     pub(crate) engine: Engine,
8 }
9 
10 wasmtime_c_api_macros::declare_own!(wasm_engine_t);
11 
12 #[no_mangle]
13 pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
14     // Enable the `env_logger` crate since this is as good a place as any to
15     // support some "top level initialization" for the C API. Almost all support
16     // should go through this one way or another, so this ensures that
17     // `RUST_LOG` should work reasonably well.
18     //
19     // Note that we `drop` the result here since this fails after the first
20     // initialization attempt. We don't mind that though because this function
21     // can be called multiple times, so we just ignore the result.
22     drop(env_logger::try_init());
23 
24     Box::new(wasm_engine_t {
25         engine: Engine::default(),
26     })
27 }
28 
29 #[no_mangle]
30 pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
31     let config = c.config;
32     Box::new(wasm_engine_t {
33         engine: Engine::new(&config).unwrap(),
34     })
35 }
36