mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
feat(c-api) Rename wasmer_module_middleware_t to wasmer_middleware_t.
Also, move it into the `unstable::middleware` module.
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
pub use super::unstable::engine::{
|
||||
wasm_config_set_target, wasmer_is_compiler_available, wasmer_is_engine_available,
|
||||
};
|
||||
#[cfg(feature = "middlewares")]
|
||||
pub use super::unstable::middlewares::wasm_config_push_middleware;
|
||||
#[cfg(feature = "middlewares")]
|
||||
use super::unstable::middlewares::wasmer_middleware_t;
|
||||
use super::unstable::target_lexicon::wasmer_target_t;
|
||||
use crate::error::{update_last_error, CApiError};
|
||||
use cfg_if::cfg_if;
|
||||
use std::sync::Arc;
|
||||
use wasmer::Engine;
|
||||
#[cfg(feature = "middlewares")]
|
||||
use wasmer_compiler::ModuleMiddleware;
|
||||
#[cfg(feature = "jit")]
|
||||
use wasmer_engine_jit::JIT;
|
||||
#[cfg(feature = "native")]
|
||||
@@ -15,10 +17,6 @@ use wasmer_engine_native::Native;
|
||||
#[cfg(feature = "object-file")]
|
||||
use wasmer_engine_object_file::ObjectFile;
|
||||
|
||||
#[cfg(feature = "middlewares")]
|
||||
#[cfg(not(feature = "compiler"))]
|
||||
compile_error!("middlewares features requires compilers feature");
|
||||
|
||||
/// Kind of compilers that can be used by the engines.
|
||||
///
|
||||
/// This is a Wasmer-specific type with Wasmer-specific functions for
|
||||
@@ -94,15 +92,6 @@ impl Default for wasmer_engine_t {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opaque representing a middleware.
|
||||
///
|
||||
#[cfg(feature = "middlewares")]
|
||||
#[derive(Debug)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasmer_module_middleware_t {
|
||||
pub(super) inner: Arc<dyn ModuleMiddleware>,
|
||||
}
|
||||
|
||||
/// A configuration holds the compiler and the engine used by the store.
|
||||
///
|
||||
/// cbindgen:ignore
|
||||
@@ -113,7 +102,7 @@ pub struct wasm_config_t {
|
||||
#[cfg(feature = "compiler")]
|
||||
compiler: wasmer_compiler_t,
|
||||
#[cfg(feature = "middlewares")]
|
||||
pub(super) middlewares: Vec<wasmer_module_middleware_t>,
|
||||
pub(super) middlewares: Vec<wasmer_middleware_t>,
|
||||
pub(super) target: Option<Box<wasmer_target_t>>,
|
||||
}
|
||||
|
||||
@@ -283,16 +272,6 @@ pub extern "C" fn wasm_config_set_engine(config: &mut wasm_config_t, engine: was
|
||||
config.engine = engine;
|
||||
}
|
||||
|
||||
// TODO: documentation
|
||||
#[cfg(feature = "middlewares")]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_config_push_middleware(
|
||||
config: &mut wasm_config_t,
|
||||
middleware: Box<wasmer_module_middleware_t>,
|
||||
) {
|
||||
config.middlewares.push(*middleware);
|
||||
}
|
||||
|
||||
/// An engine is used by the store to drive the compilation and the
|
||||
/// execution of a WebAssembly module.
|
||||
///
|
||||
|
||||
@@ -104,8 +104,8 @@
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
use super::super::super::engine::wasmer_module_middleware_t;
|
||||
use super::super::super::instance::wasm_instance_t;
|
||||
use super::wasmer_middleware_t;
|
||||
use std::sync::Arc;
|
||||
use wasmer::wasmparser::Operator;
|
||||
use wasmer_middlewares::{
|
||||
@@ -189,10 +189,10 @@ pub unsafe extern "C" fn wasmer_metering_set_remaining_points(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasmer_metering_as_middleware(
|
||||
metering: Option<Box<wasmer_metering_t>>,
|
||||
) -> Option<Box<wasmer_module_middleware_t>> {
|
||||
) -> Option<Box<wasmer_middleware_t>> {
|
||||
let metering = metering?;
|
||||
|
||||
Some(Box::new(wasmer_module_middleware_t {
|
||||
Some(Box::new(wasmer_middleware_t {
|
||||
inner: metering.inner,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1 +1,23 @@
|
||||
pub mod metering;
|
||||
|
||||
use super::super::engine::wasm_config_t;
|
||||
use std::sync::Arc;
|
||||
use wasmer_compiler::ModuleMiddleware;
|
||||
|
||||
#[cfg(all(feature = "middlewares", not(feature = "compiler")))]
|
||||
compile_error!("The `middlewares` feature requires the `compiler` feature to be turned on");
|
||||
|
||||
/// Opaque representing a middleware.
|
||||
#[derive(Debug)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasmer_middleware_t {
|
||||
pub(in crate::wasm_c_api) inner: Arc<dyn ModuleMiddleware>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_config_push_middleware(
|
||||
config: &mut wasm_config_t,
|
||||
middleware: Box<wasmer_middleware_t>,
|
||||
) {
|
||||
config.middlewares.push(*middleware);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user