mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-30 12:19:28 +00:00
doc(c-api) Update documentation.
This commit is contained in:
@ -8,7 +8,10 @@ use wasmer_engine_native::Native;
|
|||||||
#[cfg(feature = "object-file")]
|
#[cfg(feature = "object-file")]
|
||||||
use wasmer_engine_object_file::ObjectFile;
|
use wasmer_engine_object_file::ObjectFile;
|
||||||
|
|
||||||
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
|
/// Kind of compilers that can be used by the engines.
|
||||||
|
///
|
||||||
|
/// This is a Wasmer-specific type with Wasmer-specific functions for
|
||||||
|
/// manipulating it.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum wasmer_compiler_t {
|
pub enum wasmer_compiler_t {
|
||||||
@ -33,6 +36,10 @@ impl Default for wasmer_compiler_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Kind of engines that can be used by the store.
|
||||||
|
///
|
||||||
|
/// This is a Wasmer-specific type with Wasmer-specific functions for
|
||||||
|
/// manipulating it.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
@ -58,8 +65,9 @@ impl Default for wasmer_engine_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A configuration holds the compiler and the engine used by the store.
|
||||||
|
///
|
||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct wasm_config_t {
|
pub struct wasm_config_t {
|
||||||
@ -67,12 +75,15 @@ pub struct wasm_config_t {
|
|||||||
engine: wasmer_engine_t,
|
engine: wasmer_engine_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new Wasmer configuration.
|
||||||
|
///
|
||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
|
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
|
||||||
Box::new(wasm_config_t::default())
|
Box::new(wasm_config_t::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configure the compiler to use.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_config_set_compiler(
|
pub extern "C" fn wasm_config_set_compiler(
|
||||||
config: &mut wasm_config_t,
|
config: &mut wasm_config_t,
|
||||||
@ -81,13 +92,17 @@ pub extern "C" fn wasm_config_set_compiler(
|
|||||||
config.compiler = compiler;
|
config.compiler = compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configure the engine to use.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_config_set_engine(config: &mut wasm_config_t, engine: wasmer_engine_t) {
|
pub extern "C" fn wasm_config_set_engine(config: &mut wasm_config_t, engine: wasmer_engine_t) {
|
||||||
config.engine = engine;
|
config.engine = engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An engine is used by the store to drive the compilation and the
|
||||||
|
/// execution of a WebAssembly module.
|
||||||
|
///
|
||||||
/// cbindgen:ignore
|
/// cbindgen:ignore
|
||||||
#[allow(non_camel_case_types)]
|
#[repr(C)]
|
||||||
pub struct wasm_engine_t {
|
pub struct wasm_engine_t {
|
||||||
pub(crate) inner: Arc<dyn Engine + Send + Sync>,
|
pub(crate) inner: Arc<dyn Engine + Send + Sync>,
|
||||||
}
|
}
|
||||||
@ -112,6 +127,7 @@ fn get_default_compiler_config() -> Box<dyn CompilerConfig> {
|
|||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(all(feature = "jit", feature = "compiler"))] {
|
if #[cfg(all(feature = "jit", feature = "compiler"))] {
|
||||||
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
||||||
@ -121,6 +137,7 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
else if #[cfg(feature = "jit")] {
|
else if #[cfg(feature = "jit")] {
|
||||||
// Headless JIT
|
// Headless JIT
|
||||||
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::headless().engine());
|
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::headless().engine());
|
||||||
@ -128,6 +145,7 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if #[cfg(all(feature = "native", feature = "compiler"))] {
|
else if #[cfg(all(feature = "native", feature = "compiler"))] {
|
||||||
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let mut compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
let mut compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
||||||
@ -136,6 +154,7 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if #[cfg(feature = "native")] {
|
else if #[cfg(feature = "native")] {
|
||||||
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::headless().engine());
|
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::headless().engine());
|
||||||
@ -145,6 +164,7 @@ cfg_if! {
|
|||||||
// There are currently no uses of the object-file engine + compiler from the C API.
|
// There are currently no uses of the object-file engine + compiler from the C API.
|
||||||
// So if we get here, we default to headless mode regardless of if `compiler` is enabled.
|
// So if we get here, we default to headless mode regardless of if `compiler` is enabled.
|
||||||
else if #[cfg(feature = "object-file")] {
|
else if #[cfg(feature = "object-file")] {
|
||||||
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(ObjectFile::headless().engine());
|
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(ObjectFile::headless().engine());
|
||||||
@ -152,6 +172,7 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/// cbindgen:ignore
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||||
unimplemented!("The JITEngine is not attached; You might want to recompile `wasmer_c_api` with `--feature jit`");
|
unimplemented!("The JITEngine is not attached; You might want to recompile `wasmer_c_api` with `--feature jit`");
|
||||||
|
@ -56,7 +56,10 @@
|
|||||||
#include "wasm.h"
|
#include "wasm.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this can be a wasmer-specific type with wasmer-specific functions for manipulating it
|
* Kind of compilers that can be used by the engines.
|
||||||
|
*
|
||||||
|
* This is a Wasmer-specific type with Wasmer-specific functions for
|
||||||
|
* manipulating it.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CRANELIFT = 0,
|
CRANELIFT = 0,
|
||||||
@ -64,6 +67,12 @@ typedef enum {
|
|||||||
SINGLEPASS = 2,
|
SINGLEPASS = 2,
|
||||||
} wasmer_compiler_t;
|
} wasmer_compiler_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kind of engines that can be used by the store.
|
||||||
|
*
|
||||||
|
* This is a Wasmer-specific type with Wasmer-specific functions for
|
||||||
|
* manipulating it.
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
JIT = 0,
|
JIT = 0,
|
||||||
NATIVE = 1,
|
NATIVE = 1,
|
||||||
@ -159,8 +168,14 @@ wasm_func_t *wasi_get_start_function(wasm_instance_t *instance);
|
|||||||
wasi_version_t wasi_get_wasi_version(const wasm_module_t *module);
|
wasi_version_t wasi_get_wasi_version(const wasm_module_t *module);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the compiler to use.
|
||||||
|
*/
|
||||||
void wasm_config_set_compiler(wasm_config_t *config, wasmer_compiler_t compiler);
|
void wasm_config_set_compiler(wasm_config_t *config, wasmer_compiler_t compiler);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the engine to use.
|
||||||
|
*/
|
||||||
void wasm_config_set_engine(wasm_config_t *config, wasmer_engine_t engine);
|
void wasm_config_set_engine(wasm_config_t *config, wasmer_engine_t engine);
|
||||||
|
|
||||||
void wasm_module_name(const wasm_module_t *module, wasm_name_t *out);
|
void wasm_module_name(const wasm_module_t *module, wasm_name_t *out);
|
||||||
|
Reference in New Issue
Block a user