Finish merge with C API refactor

This commit is contained in:
Mark McCaskey
2020-10-05 12:30:58 -07:00
parent f0487763bf
commit 0f8d68652f
8 changed files with 46 additions and 21 deletions

View File

@@ -86,15 +86,6 @@ build-capi-llvm:
cargo build --manifest-path lib/c-api/Cargo.toml --release \ cargo build --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features jit,object-file,llvm,wasi --no-default-features --features jit,object-file,llvm,wasi
# this is debug code; we probably shouldn't ship it like this
build-capi-native:
cargo build --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features object-file,wasi
build-capi-native-debug:
cargo build --manifest-path lib/c-api/Cargo.toml \
--no-default-features --features object-file,wasi
########### ###########
# Testing # # Testing #
########### ###########

View File

@@ -374,4 +374,9 @@ fn exclude_items_from_wasm_c_api(builder: Builder) -> Builder {
.exclude_item("wasi_get_start_function") .exclude_item("wasi_get_start_function")
.exclude_item("wasi_get_wasi_version") .exclude_item("wasi_get_wasi_version")
.exclude_item("wasi_version_t") .exclude_item("wasi_version_t")
.exclude_item("wasm_instance_get_vmctx_ptr")
.exclude_item("wasmer_compiler_t")
.exclude_item("wasmer_engine_t")
.exclude_item("wasm_config_set_compiler")
.exclude_item("wasm_config_set_engine")
} }

View File

@@ -8,7 +8,6 @@ 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;
// cbindegn should see this
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it /// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(C)] #[repr(C)]
@@ -34,7 +33,6 @@ impl Default for wasmer_compiler_t {
} }
} }
// cbindegn should see this
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[repr(C)] #[repr(C)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
@@ -60,6 +58,7 @@ impl Default for wasmer_engine_t {
} }
} }
/// cbindgen:ignore
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it /// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
#[derive(Debug, Default)] #[derive(Debug, Default)]
#[repr(C)] #[repr(C)]
@@ -68,12 +67,12 @@ pub struct wasm_config_t {
engine: wasmer_engine_t, engine: wasmer_engine_t,
} }
/// 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())
} }
// cbindegn should see this
#[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,
@@ -82,12 +81,12 @@ pub extern "C" fn wasm_config_set_compiler(
config.compiler = compiler; config.compiler = compiler;
} }
// cbindegn should see this
#[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;
} }
/// cbindgen:ignore
#[repr(C)] #[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>,
@@ -166,9 +165,11 @@ cfg_if! {
} }
} }
/// cbindgen:ignore
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasm_engine_delete(_wasm_engine_address: Option<Box<wasm_engine_t>>) {} pub unsafe extern "C" fn wasm_engine_delete(_wasm_engine_address: Option<Box<wasm_engine_t>>) {}
/// cbindgen:ignore
#[no_mangle] #[no_mangle]
pub extern "C" fn wasm_engine_new_with_config( pub extern "C" fn wasm_engine_new_with_config(
config: Box<wasm_config_t>, config: Box<wasm_config_t>,

View File

@@ -3,7 +3,6 @@
#[macro_use] #[macro_use]
pub mod macros; pub mod macros;
/// cbindgen:ignore
pub mod engine; pub mod engine;
/// cbindgen:ignore /// cbindgen:ignore
@@ -30,8 +29,4 @@ pub mod value;
#[cfg(feature = "wasi")] #[cfg(feature = "wasi")]
pub mod wasi; pub mod wasi;
// TODO: find a home for this function pub mod wasmer;
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_get_vmctx_ptr(instance: &wasm_instance_t) -> *mut c_void {
instance.inner.vmctx_ptr() as _
}

View File

@@ -0,0 +1,9 @@
//! Wasmer-specific extensions to the Wasm C API.
use crate::wasm_c_api::instance::wasm_instance_t;
use std::ffi::c_void;
#[no_mangle]
pub unsafe extern "C" fn wasm_instance_get_vmctx_ptr(instance: &wasm_instance_t) -> *mut c_void {
instance.inner.vmctx_ptr() as _
}

View File

@@ -28,6 +28,9 @@
# define DEPRECATED(message) __declspec(deprecated(message)) # define DEPRECATED(message) __declspec(deprecated(message))
#endif #endif
// The `jit` feature has been enabled for this build.
#define WASMER_JIT_ENABLED
// The `compiler` feature has been enabled for this build. // The `compiler` feature has been enabled for this build.
#define WASMER_COMPILER_ENABLED #define WASMER_COMPILER_ENABLED
@@ -51,6 +54,21 @@
#include <stdlib.h> #include <stdlib.h>
#include "wasm.h" #include "wasm.h"
/**
* this can be a wasmer-specific type with wasmer-specific functions for manipulating it
*/
typedef enum {
CRANELIFT = 0,
LLVM = 1,
SINGLEPASS = 2,
} wasmer_compiler_t;
typedef enum {
JIT = 0,
NATIVE = 1,
OBJECT_FILE = 2,
} wasmer_engine_t;
#if defined(WASMER_WASI_ENABLED) #if defined(WASMER_WASI_ENABLED)
typedef struct wasi_config_t wasi_config_t; typedef struct wasi_config_t wasi_config_t;
#endif #endif
@@ -132,6 +150,12 @@ 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
void wasm_config_set_compiler(wasm_config_t *config, wasmer_compiler_t compiler);
void wasm_config_set_engine(wasm_config_t *config, wasmer_engine_t engine);
void *wasm_instance_get_vmctx_ptr(const wasm_instance_t *instance);
/** /**
* Gets the length in bytes of the last error if any. * Gets the length in bytes of the last error if any.
* *

View File

@@ -1 +1 @@
../../../../lib/c-api/tests/assets/qjs.wasm ../../../../lib/c-api/tests/wasm_c_api/assets/qjs.wasm

View File

@@ -1 +1 @@
../../../../lib/c-api/tests/wasm-c-api/include/wasm.h ../../../../lib/c-api/wasm.h