Make WASI and wat support optional in the C API (#1419)
Add some crate features to compile out support for these features of the C API. Avoiding these two features if they're not necessary shaves about 2MB off the final shared object in some local tests!
This commit is contained in:
@@ -21,8 +21,6 @@ mod trap;
|
||||
mod types;
|
||||
mod val;
|
||||
mod vec;
|
||||
mod wasi;
|
||||
mod wat2wasm;
|
||||
|
||||
pub use crate::config::*;
|
||||
pub use crate::engine::*;
|
||||
@@ -40,7 +38,15 @@ pub use crate::trap::*;
|
||||
pub use crate::types::*;
|
||||
pub use crate::val::*;
|
||||
pub use crate::vec::*;
|
||||
|
||||
#[cfg(feature = "wasi")]
|
||||
mod wasi;
|
||||
#[cfg(feature = "wasi")]
|
||||
pub use crate::wasi::*;
|
||||
|
||||
#[cfg(feature = "wat")]
|
||||
mod wat2wasm;
|
||||
#[cfg(feature = "wat")]
|
||||
pub use crate::wat2wasm::*;
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{wasi_instance_t, wasm_extern_t, wasm_store_t, ExternHost};
|
||||
use crate::{wasm_extern_t, wasm_store_t, ExternHost};
|
||||
use crate::{wasm_instance_t, wasm_module_t, wasm_name_t, wasm_trap_t};
|
||||
use std::str;
|
||||
use wasmtime::{Extern, Linker};
|
||||
@@ -51,10 +51,11 @@ pub extern "C" fn wasmtime_linker_define(
|
||||
linker.define(module, name, item).is_ok()
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasi")]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_linker_define_wasi(
|
||||
linker: &mut wasmtime_linker_t,
|
||||
instance: &wasi_instance_t,
|
||||
instance: &crate::wasi_instance_t,
|
||||
) -> bool {
|
||||
let linker = &mut linker.linker;
|
||||
instance.add_to_linker(linker).is_ok()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::wasm_byte_vec_t;
|
||||
use std::str;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_wat2wasm(
|
||||
@@ -7,7 +6,7 @@ pub extern "C" fn wasmtime_wat2wasm(
|
||||
ret: &mut wasm_byte_vec_t,
|
||||
error: Option<&mut wasm_byte_vec_t>,
|
||||
) -> bool {
|
||||
let wat = match str::from_utf8(wat.as_slice()) {
|
||||
let wat = match std::str::from_utf8(wat.as_slice()) {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
if let Some(error) = error {
|
||||
|
||||
Reference in New Issue
Block a user