wasmi_c_api/
lib.rs

1//! Implements C-API support for the Wasmi WebAssembly interpreter.
2//!
3//! Namely implements the Wasm C-API proposal found here: <https://github.com/WebAssembly/wasm-c-api/>
4//!
5//! # Crate features
6//!
7//! ## The `prefix-symbols` feature
8//! Adds a `wasmi_` prefix to all the public symbols. This means that, for example, the function `wasm_store_delete`
9//! will be given the public (not mangled) symbol `wasmi_wasm_store_delete`.
10//!
11//! ### Rationale
12//! This feature allows users that need to separate multiple C-API implementers to segregate wasmi's C-API symbols,
13//! avoiding symbol clashes.
14//!
15//! ### Note
16//! It's important to notice that when the `prefix-symbols` feature is enabled, the symbols declared in the C-API header
17//! are not given the prefix, introducing - by design, in order to keep the C-API header same as the actual
18//! specification - an asymmetry. For example, Rust users that want to enable this feature, can use `bindgen` to
19//! generate correct C-to-Rust interop code:
20//!
21//! ```ignore
22//!    #[derive(Debug)]
23//!    struct WasmiRenamer {}
24//!
25//!    impl ParseCallbacks for WasmiRenamer {
26//!        /// This function will run for every extern variable and function. The returned value determines
27//!        /// the link name in the bindings.
28//!        fn generated_link_name_override(
29//!            &self,
30//!            item_info: bindgen::callbacks::ItemInfo<'_>,
31//!        ) -> Option<String> {
32//!            if item_info.name.starts_with("wasm") {
33//!                let new_name = if cfg!(any(target_os = "macos", target_os = "ios")) {
34//!                    format!("_wasmi_{}", item_info.name)
35//!                } else {
36//!                    format!("wasmi_{}", item_info.name)
37//!                };
38//!
39//!                Some(new_name)
40//!            } else {
41//!                None
42//!            }
43//!        }
44//!    }
45//!
46//!    let bindings = bindgen::Builder::default()
47//!        .header(
48//!            PathBuf::from(std::env::var("DEP_WASMI_C_API_INCLUDE").unwrap())
49//!                .join("wasm.h")
50//!                .to_string_lossy(),
51//!        )
52//!        .derive_default(true)
53//!        .derive_debug(true)
54//!        .parse_callbacks(Box::new(WasmiRenamer {}))
55//!        .generate()
56//!        .expect("Unable to generate bindings for `wasmi`!");
57//! ```
58
59#![no_std]
60#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
61
62extern crate alloc;
63#[cfg(feature = "std")]
64#[macro_use]
65extern crate std;
66
67pub use wasmi;
68
69mod config;
70mod engine;
71mod error;
72mod r#extern;
73mod foreign;
74mod frame;
75mod func;
76mod global;
77mod instance;
78mod memory;
79mod module;
80mod r#ref;
81mod store;
82mod table;
83mod trap;
84mod types;
85mod utils;
86mod val;
87mod vec;
88
89use self::utils::*;
90pub use self::{
91    config::*,
92    engine::*,
93    error::*,
94    foreign::*,
95    frame::*,
96    func::*,
97    global::*,
98    instance::*,
99    memory::*,
100    module::*,
101    r#extern::*,
102    r#ref::*,
103    store::*,
104    table::*,
105    trap::*,
106    types::*,
107    val::*,
108    vec::*,
109};