mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 22:58:18 +00:00
Merge branch 'master' into feat-c-api-cross-compilation-2
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
- [#2054](https://github.com/wasmerio/wasmer/pull/2054) Add `wasm_config_delete` to the Wasm C API.
|
- [#2054](https://github.com/wasmerio/wasmer/pull/2054) Add `wasm_config_delete` to the Wasm C API.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- [#2083](https://github.com/wasmerio/wasmer/pull/2083) Mark `wasi_env_set_(instance|memory)` as deprecated. You may simply remove them with no side-effect.
|
||||||
- [#2056](https://github.com/wasmerio/wasmer/pull/2056) Change back to depend on the `enumset` crate instead of `wasmer_enumset`
|
- [#2056](https://github.com/wasmerio/wasmer/pull/2056) Change back to depend on the `enumset` crate instead of `wasmer_enumset`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -89,8 +89,41 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) {
|
|||||||
out_header_file.push("wasmer_wasm");
|
out_header_file.push("wasmer_wasm");
|
||||||
|
|
||||||
let mut pre_header = format!(
|
let mut pre_header = format!(
|
||||||
r#"// The Wasmer C/C++ header file compatible with the `wasm-c-api` standard API.
|
r#"// The Wasmer C/C++ header file compatible with the [`wasm-c-api`]
|
||||||
// This file is generated by lib/c-api/build.rs.
|
// standard API, as `wasm.h` (included here).
|
||||||
|
//
|
||||||
|
// This file is automatically generated by `lib/c-api/build.rs` of the
|
||||||
|
// [`wasmer-c-api`] Rust crate.
|
||||||
|
//
|
||||||
|
// # Stability
|
||||||
|
//
|
||||||
|
// The [`wasm-c-api`] standard API is a _living_ standard. There is no
|
||||||
|
// commitment for stability yet. We (Wasmer) will try our best to keep
|
||||||
|
// backward compatibility as much as possible. Nonetheless, some
|
||||||
|
// necessary API aren't yet standardized, and as such, we provide a
|
||||||
|
// custom API, e.g. `wasi_*` types and functions.
|
||||||
|
//
|
||||||
|
// The documentation makes it clear whether a function is unstable.
|
||||||
|
//
|
||||||
|
// When a type or a function will be deprecated, it will be marked as
|
||||||
|
// such with the appropriated compiler warning, and will be removed at
|
||||||
|
// the next release round.
|
||||||
|
//
|
||||||
|
// # Documentation
|
||||||
|
//
|
||||||
|
// At the time of writing, the [`wasm-c-api`] standard has no
|
||||||
|
// documentation. This file also does not include inline
|
||||||
|
// documentation. However, we have made (and we continue to make) an
|
||||||
|
// important effort to document everything. [See the documentation
|
||||||
|
// online][documentation]. Please refer to this page for the real
|
||||||
|
// canonical documentation. It also contains numerous examples.
|
||||||
|
//
|
||||||
|
// To generate the documentation locally, run `cargo doc --open` from
|
||||||
|
// within the [`wasmer-c-api`] Rust crate.
|
||||||
|
//
|
||||||
|
// [`wasm-c-api`]: https://github.com/WebAssembly/wasm-c-api
|
||||||
|
// [`wasmer-c-api`]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api
|
||||||
|
// [documentation]: https://wasmerio.github.io/wasmer/crates/wasmer_c_api/
|
||||||
|
|
||||||
#if !defined(WASMER_WASM_H_PRELUDE)
|
#if !defined(WASMER_WASM_H_PRELUDE)
|
||||||
|
|
||||||
@@ -184,10 +217,12 @@ fn build_wasmer_c_api_headers(crate_dir: &str, out_dir: &str) {
|
|||||||
out_header_file.set_extension("h");
|
out_header_file.set_extension("h");
|
||||||
|
|
||||||
// Build and generate the header file.
|
// Build and generate the header file.
|
||||||
exclude_items_from_wasm_c_api(new_builder(Language::C, crate_dir, guard, &pre_header))
|
exclude_items_from_wasm_c_api(
|
||||||
.generate()
|
new_builder(Language::C, crate_dir, guard, &pre_header).with_documentation(true),
|
||||||
.expect("Unable to generate C bindings")
|
)
|
||||||
.write_to_file(out_header_file.as_path());
|
.generate()
|
||||||
|
.expect("Unable to generate C bindings")
|
||||||
|
.write_to_file(out_header_file.as_path());
|
||||||
|
|
||||||
// Copy the generated bindings from `OUT_DIR` to
|
// Copy the generated bindings from `OUT_DIR` to
|
||||||
// `CARGO_MANIFEST_DIR`.
|
// `CARGO_MANIFEST_DIR`.
|
||||||
@@ -203,10 +238,12 @@ fn build_wasmer_c_api_headers(crate_dir: &str, out_dir: &str) {
|
|||||||
out_header_file.set_extension("hh");
|
out_header_file.set_extension("hh");
|
||||||
|
|
||||||
// Build and generate the header file.
|
// Build and generate the header file.
|
||||||
exclude_items_from_wasm_c_api(new_builder(Language::Cxx, crate_dir, guard, &pre_header))
|
exclude_items_from_wasm_c_api(
|
||||||
.generate()
|
new_builder(Language::Cxx, crate_dir, guard, &pre_header).with_documentation(true),
|
||||||
.expect("Unable to generate C++ bindings")
|
)
|
||||||
.write_to_file(out_header_file.as_path());
|
.generate()
|
||||||
|
.expect("Unable to generate C++ bindings")
|
||||||
|
.write_to_file(out_header_file.as_path());
|
||||||
|
|
||||||
// Copy the generated bindings from `OUT_DIR` to
|
// Copy the generated bindings from `OUT_DIR` to
|
||||||
// `CARGO_MANIFEST_DIR`.
|
// `CARGO_MANIFEST_DIR`.
|
||||||
@@ -247,7 +284,7 @@ fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header:
|
|||||||
.with_crate(crate_dir)
|
.with_crate(crate_dir)
|
||||||
.with_include_guard(include_guard)
|
.with_include_guard(include_guard)
|
||||||
.with_header(header)
|
.with_header(header)
|
||||||
.with_documentation(true)
|
.with_documentation(false)
|
||||||
.with_define("target_family", "windows", "_WIN32")
|
.with_define("target_family", "windows", "_WIN32")
|
||||||
.with_define("target_arch", "x86_64", "ARCH_X86_64")
|
.with_define("target_arch", "x86_64", "ARCH_X86_64")
|
||||||
.with_define("feature", "jit", JIT_FEATURE_AS_C_DEFINE)
|
.with_define("feature", "jit", JIT_FEATURE_AS_C_DEFINE)
|
||||||
|
|||||||
@@ -199,30 +199,22 @@ pub extern "C" fn wasi_env_delete(_state: Option<Box<wasi_env_t>>) {}
|
|||||||
|
|
||||||
/// This function is deprecated. You may safely remove all calls to it and everything
|
/// This function is deprecated. You may safely remove all calls to it and everything
|
||||||
/// will continue to work.
|
/// will continue to work.
|
||||||
// Dead code: deprecate or remove
|
///
|
||||||
#[allow(unused_variables)]
|
/// cbindgen:prefix=DEPRECATED("This function is no longer necessary. You may safely remove all calls to it and everything will continue to work.")
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasi_env_set_instance(env: &mut wasi_env_t, instance: &wasm_instance_t) -> bool {
|
pub extern "C" fn wasi_env_set_instance(
|
||||||
/*
|
_env: &mut wasi_env_t,
|
||||||
let memory = if let Ok(memory) = instance.inner.exports.get_memory("memory") {
|
_instance: &wasm_instance_t,
|
||||||
memory
|
) -> bool {
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
env.inner.set_memory(memory.clone());
|
|
||||||
*/
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is deprecated. You may safely remove all calls to it and everything
|
/// This function is deprecated. You may safely remove all calls to it and everything
|
||||||
/// will continue to work.
|
/// will continue to work.
|
||||||
// Dead code: deprecate or remove
|
///
|
||||||
#[allow(unused_variables)]
|
/// cbindgen:prefix=DEPRECATED("This function is no longer necessary. You may safely remove all calls to it and everything will continue to work.")
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasi_env_set_memory(env: &mut wasi_env_t, memory: &wasm_memory_t) {
|
pub extern "C" fn wasi_env_set_memory(_env: &mut wasi_env_t, _memory: &wasm_memory_t) {}
|
||||||
//env.inner.set_memory(memory.inner.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasi_env_read_stdout(
|
pub unsafe extern "C" fn wasi_env_read_stdout(
|
||||||
|
|||||||
@@ -1,5 +1,38 @@
|
|||||||
// The Wasmer C/C++ header file compatible with the `wasm-c-api` standard API.
|
// The Wasmer C/C++ header file compatible with the [`wasm-c-api`]
|
||||||
// This file is generated by lib/c-api/build.rs.
|
// standard API, as `wasm.h` (included here).
|
||||||
|
//
|
||||||
|
// This file is automatically generated by `lib/c-api/build.rs` of the
|
||||||
|
// [`wasmer-c-api`] Rust crate.
|
||||||
|
//
|
||||||
|
// # Stability
|
||||||
|
//
|
||||||
|
// The [`wasm-c-api`] standard API is a _living_ standard. There is no
|
||||||
|
// commitment for stability yet. We (Wasmer) will try our best to keep
|
||||||
|
// backward compatibility as much as possible. Nonetheless, some
|
||||||
|
// necessary API aren't yet standardized, and as such, we provide a
|
||||||
|
// custom API, e.g. `wasi_*` types and functions.
|
||||||
|
//
|
||||||
|
// The documentation makes it clear whether a function is unstable.
|
||||||
|
//
|
||||||
|
// When a type or a function will be deprecated, it will be marked as
|
||||||
|
// such with the appropriated compiler warning, and will be removed at
|
||||||
|
// the next release round.
|
||||||
|
//
|
||||||
|
// # Documentation
|
||||||
|
//
|
||||||
|
// At the time of writing, the [`wasm-c-api`] standard has no
|
||||||
|
// documentation. This file also does not include inline
|
||||||
|
// documentation. However, we have made (and we continue to make) an
|
||||||
|
// important effort to document everything. [See the documentation
|
||||||
|
// online][documentation]. Please refer to this page for the real
|
||||||
|
// canonical documentation. It also contains numerous examples.
|
||||||
|
//
|
||||||
|
// To generate the documentation locally, run `cargo doc --open` from
|
||||||
|
// within the [`wasmer-c-api`] Rust crate.
|
||||||
|
//
|
||||||
|
// [`wasm-c-api`]: https://github.com/WebAssembly/wasm-c-api
|
||||||
|
// [`wasmer-c-api`]: https://github.com/wasmerio/wasmer/tree/master/lib/c-api
|
||||||
|
// [documentation]: https://wasmerio.github.io/wasmer/crates/wasmer_c_api/
|
||||||
|
|
||||||
#if !defined(WASMER_WASM_H_PRELUDE)
|
#if !defined(WASMER_WASM_H_PRELUDE)
|
||||||
|
|
||||||
@@ -63,94 +96,33 @@
|
|||||||
#include "wasm.h"
|
#include "wasm.h"
|
||||||
|
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* The version of WASI. This is determined by the imports namespace
|
|
||||||
* string.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* An invalid version.
|
|
||||||
*/
|
|
||||||
INVALID_VERSION = -1,
|
INVALID_VERSION = -1,
|
||||||
#endif
|
#endif
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* Latest version.
|
|
||||||
*
|
|
||||||
* It's a “floating” version, i.e. it's an alias to the latest
|
|
||||||
* version (for the moment, `Snapshot1`). Using this version is a
|
|
||||||
* way to ensure that modules will run only if they come with the
|
|
||||||
* latest WASI version (in case of security issues for instance),
|
|
||||||
* by just updating the runtime.
|
|
||||||
*
|
|
||||||
* Note that this version is never returned by an API. It is
|
|
||||||
* provided only by the user.
|
|
||||||
*/
|
|
||||||
LATEST = 0,
|
LATEST = 0,
|
||||||
#endif
|
#endif
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* `wasi_unstable`.
|
|
||||||
*/
|
|
||||||
SNAPSHOT0 = 1,
|
SNAPSHOT0 = 1,
|
||||||
#endif
|
#endif
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* `wasi_snapshot_preview1`.
|
|
||||||
*/
|
|
||||||
SNAPSHOT1 = 2,
|
SNAPSHOT1 = 2,
|
||||||
#endif
|
#endif
|
||||||
} wasi_version_t;
|
} wasi_version_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WASMER_COMPILER_ENABLED)
|
#if defined(WASMER_COMPILER_ENABLED)
|
||||||
/**
|
|
||||||
* 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 {
|
||||||
/**
|
|
||||||
* Variant to represent the Cranelift compiler. See the
|
|
||||||
* [`wasmer_compiler_cranelift`] Rust crate.
|
|
||||||
*/
|
|
||||||
CRANELIFT = 0,
|
CRANELIFT = 0,
|
||||||
/**
|
|
||||||
* Variant to represent the LLVM compiler. See the
|
|
||||||
* [`wasmer_compiler_llvm`] Rust crate.
|
|
||||||
*/
|
|
||||||
LLVM = 1,
|
LLVM = 1,
|
||||||
/**
|
|
||||||
* Variant to represent the Singlepass compiler. See the
|
|
||||||
* [`wasmer_compiler_singlepass`] Rust crate.
|
|
||||||
*/
|
|
||||||
SINGLEPASS = 2,
|
SINGLEPASS = 2,
|
||||||
} wasmer_compiler_t;
|
} wasmer_compiler_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 {
|
||||||
/**
|
|
||||||
* Variant to represent the JIT engine. See the
|
|
||||||
* [`wasmer_engine_jit`] Rust crate.
|
|
||||||
*/
|
|
||||||
JIT = 0,
|
JIT = 0,
|
||||||
/**
|
|
||||||
* Variant to represent the Native engine. See the
|
|
||||||
* [`wasmer_engine_native`] Rust crate.
|
|
||||||
*/
|
|
||||||
NATIVE = 1,
|
NATIVE = 1,
|
||||||
/**
|
|
||||||
* Variant to represent the Object File engine. See the
|
|
||||||
* [`wasmer_engine_object_file`] Rust crate.
|
|
||||||
*/
|
|
||||||
OBJECT_FILE = 2,
|
OBJECT_FILE = 2,
|
||||||
} wasmer_engine_t;
|
} wasmer_engine_t;
|
||||||
|
|
||||||
@@ -162,111 +134,10 @@ typedef struct wasi_config_t wasi_config_t;
|
|||||||
typedef struct wasi_env_t wasi_env_t;
|
typedef struct wasi_env_t wasi_env_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* Unstable non-standard Wasmer-specific API to represent a set of
|
|
||||||
* CPU features.
|
|
||||||
*
|
|
||||||
* CPU features are identified by their stringified names. The
|
|
||||||
* reference is the GCC options:
|
|
||||||
*
|
|
||||||
* * <https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html>,
|
|
||||||
* * <https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html>,
|
|
||||||
* * <https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html>.
|
|
||||||
*
|
|
||||||
* At the time of writing this documentation (it might be outdated in
|
|
||||||
* the future), the supported features are the following:
|
|
||||||
*
|
|
||||||
* * `sse2`,
|
|
||||||
* * `sse3`,
|
|
||||||
* * `ssse3`,
|
|
||||||
* * `sse4.1`,
|
|
||||||
* * `sse4.2`,
|
|
||||||
* * `popcnt`,
|
|
||||||
* * `avx`,
|
|
||||||
* * `bmi`,
|
|
||||||
* * `bmi2`,
|
|
||||||
* * `avx2`,
|
|
||||||
* * `avx512dq`,
|
|
||||||
* * `avx512vl`,
|
|
||||||
* * `lzcnt`.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Create a new CPU feature set.
|
|
||||||
* wasm_cpu_features_t* cpu_features = wasm_cpu_features_new();
|
|
||||||
*
|
|
||||||
* // Create a new feature name, here `sse2`, and add it to the set.
|
|
||||||
* {
|
|
||||||
* wasm_name_t cpu_feature_name;
|
|
||||||
* wasm_name_new_from_string(&cpu_feature_name, "sse2");
|
|
||||||
*
|
|
||||||
* wasm_cpu_features_add(cpu_features, &cpu_feature_name);
|
|
||||||
*
|
|
||||||
* wasm_name_delete(&cpu_feature_name);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* wasm_cpu_features_delete(cpu_features);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
typedef struct wasm_cpu_features_t wasm_cpu_features_t;
|
typedef struct wasm_cpu_features_t wasm_cpu_features_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* Unstable non-standard Wasmer-specific API to represent a triple +
|
|
||||||
* CPU features pair.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See the module's documentation.
|
|
||||||
*/
|
|
||||||
typedef struct wasm_target_t wasm_target_t;
|
typedef struct wasm_target_t wasm_target_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* Unstable non-standard Wasmer-specific API to represent a target
|
|
||||||
* “triple”.
|
|
||||||
*
|
|
||||||
* Historically such things had three fields, though they have added
|
|
||||||
* additional fields over time.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* wasm_name_t triple_name;
|
|
||||||
* wasm_name_new_from_string(&triple_name, "x86_64-apple-darwin");
|
|
||||||
*
|
|
||||||
* wasm_triple_t* triple = wasm_triple_new(&triple_name);
|
|
||||||
* assert(triple);
|
|
||||||
*
|
|
||||||
* wasm_triple_delete(triple);
|
|
||||||
* wasm_name_delete(&triple_name);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* See also [`wasm_triple_new_from_host`].
|
|
||||||
*/
|
|
||||||
typedef struct wasm_triple_t wasm_triple_t;
|
typedef struct wasm_triple_t wasm_triple_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -318,9 +189,6 @@ void wasi_env_delete(wasi_env_t *_state);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* Takes ownership over the `wasi_config_t`.
|
|
||||||
*/
|
|
||||||
wasi_env_t *wasi_env_new(wasi_config_t *config);
|
wasi_env_t *wasi_env_new(wasi_config_t *config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -333,25 +201,18 @@ intptr_t wasi_env_read_stdout(wasi_env_t *env, char *buffer, uintptr_t buffer_le
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
DEPRECATED("This function is no longer necessary. You may safely remove all calls to it and everything will continue to work.")
|
||||||
* This function is deprecated. You may safely remove all calls to it and everything
|
bool wasi_env_set_instance(wasi_env_t *_env,
|
||||||
* will continue to work.
|
const wasm_instance_t *_instance);
|
||||||
*/
|
|
||||||
bool wasi_env_set_instance(wasi_env_t *env, const wasm_instance_t *instance);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
DEPRECATED("This function is no longer necessary. You may safely remove all calls to it and everything will continue to work.")
|
||||||
* This function is deprecated. You may safely remove all calls to it and everything
|
void wasi_env_set_memory(wasi_env_t *_env,
|
||||||
* will continue to work.
|
const wasm_memory_t *_memory);
|
||||||
*/
|
|
||||||
void wasi_env_set_memory(wasi_env_t *env, const wasm_memory_t *memory);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WASMER_WASI_ENABLED)
|
#if defined(WASMER_WASI_ENABLED)
|
||||||
/**
|
|
||||||
* Takes ownership of `wasi_env_t`.
|
|
||||||
*/
|
|
||||||
bool wasi_get_imports(const wasm_store_t *store,
|
bool wasi_get_imports(const wasm_store_t *store,
|
||||||
const wasm_module_t *module,
|
const wasm_module_t *module,
|
||||||
const wasi_env_t *wasi_env,
|
const wasi_env_t *wasi_env,
|
||||||
@@ -367,491 +228,47 @@ wasi_version_t wasi_get_wasi_version(const wasm_module_t *module);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WASMER_COMPILER_ENABLED)
|
#if defined(WASMER_COMPILER_ENABLED)
|
||||||
/**
|
|
||||||
* Updates the configuration to specify a particular compiler to use.
|
|
||||||
*
|
|
||||||
* This is a Wasmer-specific function.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust,no_run
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Create the configuration.
|
|
||||||
* wasm_config_t* config = wasm_config_new();
|
|
||||||
*
|
|
||||||
* // Use the Cranelift compiler.
|
|
||||||
* wasm_config_set_compiler(config, CRANELIFT);
|
|
||||||
*
|
|
||||||
* // Create the engine.
|
|
||||||
* wasm_engine_t* engine = wasm_engine_new_with_config(config);
|
|
||||||
*
|
|
||||||
* // Check we have an engine!
|
|
||||||
* assert(engine);
|
|
||||||
*
|
|
||||||
* // Free everything.
|
|
||||||
* wasm_engine_delete(engine);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
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);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the configuration to specify a particular engine to use.
|
|
||||||
*
|
|
||||||
* This is a Wasmer-specific function.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust,no_run
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Create the configuration.
|
|
||||||
* wasm_config_t* config = wasm_config_new();
|
|
||||||
*
|
|
||||||
* // Use the JIT engine.
|
|
||||||
* wasm_config_set_engine(config, JIT);
|
|
||||||
*
|
|
||||||
* // Create the engine.
|
|
||||||
* wasm_engine_t* engine = wasm_engine_new_with_config(config);
|
|
||||||
*
|
|
||||||
* // Check we have an engine!
|
|
||||||
* assert(engine);
|
|
||||||
*
|
|
||||||
* // Free everything.
|
|
||||||
* wasm_engine_delete(engine);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
|
||||||
* Unstable non-standard Wasmer-specific API to update the
|
|
||||||
* configuration to specify a particular target for the engine.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Create the configuration.
|
|
||||||
* wasm_config_t* config = wasm_config_new();
|
|
||||||
*
|
|
||||||
* // Set the target.
|
|
||||||
* {
|
|
||||||
* wasm_triple_t* triple = wasm_triple_new_from_host();
|
|
||||||
* wasm_cpu_features_t* cpu_features = wasm_cpu_features_new();
|
|
||||||
* wasm_target_t* target = wasm_target_new(triple, cpu_features);
|
|
||||||
*
|
|
||||||
* wasm_config_set_target(config, target);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* // Create the engine.
|
|
||||||
* wasm_engine_t* engine = wasm_engine_new_with_config(config);
|
|
||||||
*
|
|
||||||
* // Check we have an engine!
|
|
||||||
* assert(engine);
|
|
||||||
*
|
|
||||||
* // Free everything.
|
|
||||||
* wasm_engine_delete(engine);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
void wasm_config_set_target(wasm_config_t *config, wasm_target_t *target);
|
void wasm_config_set_target(wasm_config_t *config, wasm_target_t *target);
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new CPU feature into the set represented by
|
|
||||||
* [`wasm_cpu_features_t`].
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See [`wasm_cpu_features_t`].
|
|
||||||
*/
|
|
||||||
bool wasm_cpu_features_add(wasm_cpu_features_t *cpu_features, const wasm_name_t *feature);
|
bool wasm_cpu_features_add(wasm_cpu_features_t *cpu_features, const wasm_name_t *feature);
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a [`wasm_cpu_features_t`].
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See [`wasm_cpu_features_t`].
|
|
||||||
*/
|
|
||||||
void wasm_cpu_features_delete(wasm_cpu_features_t *_cpu_features);
|
void wasm_cpu_features_delete(wasm_cpu_features_t *_cpu_features);
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new [`wasm_cpu_features_t`].
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See [`wasm_cpu_features_t`].
|
|
||||||
*/
|
|
||||||
wasm_cpu_features_t *wasm_cpu_features_new(void);
|
wasm_cpu_features_t *wasm_cpu_features_new(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Unstable non-standard Wasmer-specific API to get the module's
|
|
||||||
* name, otherwise `out->size` is set to `0` and `out->data` to
|
|
||||||
* `NULL`.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Create the engine and the store.
|
|
||||||
* wasm_engine_t* engine = wasm_engine_new();
|
|
||||||
* wasm_store_t* store = wasm_store_new(engine);
|
|
||||||
*
|
|
||||||
* // Create a WebAssembly module from a WAT definition.
|
|
||||||
* wasm_byte_vec_t wat;
|
|
||||||
* wasmer_byte_vec_new_from_string(&wat, "(module $moduleName)");
|
|
||||||
* // ^~~~~~~~~~~ that's the name!
|
|
||||||
* wasm_byte_vec_t wasm;
|
|
||||||
* wat2wasm(&wat, &wasm);
|
|
||||||
*
|
|
||||||
* // Create the module.
|
|
||||||
* wasm_module_t* module = wasm_module_new(store, &wasm);
|
|
||||||
*
|
|
||||||
* // Read the module's name.
|
|
||||||
* wasm_name_t name;
|
|
||||||
* wasm_module_name(module, &name);
|
|
||||||
*
|
|
||||||
* // It works!
|
|
||||||
* wasmer_assert_name(&name, "moduleName");
|
|
||||||
*
|
|
||||||
* // Free everything.
|
|
||||||
* wasm_byte_vec_delete(&name);
|
|
||||||
* wasm_module_delete(module);
|
|
||||||
* wasm_byte_vec_delete(&wasm);
|
|
||||||
* wasm_byte_vec_delete(&wat);
|
|
||||||
* wasm_store_delete(store);
|
|
||||||
* wasm_engine_delete(engine);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
|
||||||
* Unstable non-standard Wasmer-specific API to set the module's
|
|
||||||
* name. The function returns `true` if the name has been updated,
|
|
||||||
* `false` otherwise.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Create the engine and the store.
|
|
||||||
* wasm_engine_t* engine = wasm_engine_new();
|
|
||||||
* wasm_store_t* store = wasm_store_new(engine);
|
|
||||||
*
|
|
||||||
* // Create a WebAssembly module from a WAT definition.
|
|
||||||
* wasm_byte_vec_t wat;
|
|
||||||
* wasmer_byte_vec_new_from_string(&wat, "(module)");
|
|
||||||
* wasm_byte_vec_t wasm;
|
|
||||||
* wat2wasm(&wat, &wasm);
|
|
||||||
*
|
|
||||||
* // Create the module.
|
|
||||||
* wasm_module_t* module = wasm_module_new(store, &wasm);
|
|
||||||
*
|
|
||||||
* // Read the module's name. There is none for the moment.
|
|
||||||
* {
|
|
||||||
* wasm_name_t name;
|
|
||||||
* wasm_module_name(module, &name);
|
|
||||||
*
|
|
||||||
* assert(name.size == 0);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* // So, let's set a new name.
|
|
||||||
* {
|
|
||||||
* wasm_name_t name;
|
|
||||||
* wasmer_byte_vec_new_from_string(&name, "hello");
|
|
||||||
* wasm_module_set_name(module, &name);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* // And now, let's see the new name.
|
|
||||||
* {
|
|
||||||
* wasm_name_t name;
|
|
||||||
* wasm_module_name(module, &name);
|
|
||||||
*
|
|
||||||
* // It works!
|
|
||||||
* wasmer_assert_name(&name, "hello");
|
|
||||||
*
|
|
||||||
* wasm_byte_vec_delete(&name);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* // Free everything.
|
|
||||||
* wasm_module_delete(module);
|
|
||||||
* wasm_byte_vec_delete(&wasm);
|
|
||||||
* wasm_byte_vec_delete(&wat);
|
|
||||||
* wasm_store_delete(store);
|
|
||||||
* wasm_engine_delete(engine);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
bool wasm_module_set_name(wasm_module_t *module, const wasm_name_t *name);
|
bool wasm_module_set_name(wasm_module_t *module, const wasm_name_t *name);
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a [`wasm_target_t`].
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See the module's documentation.
|
|
||||||
*/
|
|
||||||
void wasm_target_delete(wasm_target_t *_target);
|
void wasm_target_delete(wasm_target_t *_target);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new [`wasm_target_t`].
|
|
||||||
*
|
|
||||||
* It takes ownership of `triple` and `cpu_features`.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See the module's documentation.
|
|
||||||
*/
|
|
||||||
wasm_target_t *wasm_target_new(wasm_triple_t *triple, wasm_cpu_features_t *cpu_features);
|
wasm_target_t *wasm_target_new(wasm_triple_t *triple, wasm_cpu_features_t *cpu_features);
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a [`wasm_triple_t`].
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See [`wasm_triple_t`].
|
|
||||||
*/
|
|
||||||
void wasm_triple_delete(wasm_triple_t *_triple);
|
void wasm_triple_delete(wasm_triple_t *_triple);
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new [`wasm_triple_t`] based on a triple string.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See [`wasm_triple_t`] or [`wasm_triple_new_from_host`].
|
|
||||||
*/
|
|
||||||
wasm_triple_t *wasm_triple_new(const wasm_name_t *triple);
|
wasm_triple_t *wasm_triple_new(const wasm_name_t *triple);
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the [`wasm_triple_t`] for the current host.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* wasm_triple_t* triple = wasm_triple_new_from_host();
|
|
||||||
* assert(triple);
|
|
||||||
*
|
|
||||||
* wasm_triple_delete(triple);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success();
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* See also [`wasm_triple_new`].
|
|
||||||
*/
|
|
||||||
wasm_triple_t *wasm_triple_new_from_host(void);
|
wasm_triple_t *wasm_triple_new_from_host(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the length in bytes of the last error if any, zero otherwise.
|
|
||||||
*
|
|
||||||
* This can be used to dynamically allocate a buffer with the correct number of
|
|
||||||
* bytes needed to store a message.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See this module's documentation to get a complete example.
|
|
||||||
*/
|
|
||||||
int wasmer_last_error_length(void);
|
int wasmer_last_error_length(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last error message if any into the provided buffer
|
|
||||||
* `buffer` up to the given `length`.
|
|
||||||
*
|
|
||||||
* The `length` parameter must be large enough to store the last
|
|
||||||
* error message. Ideally, the value should come from
|
|
||||||
* [`wasmer_last_error_length`].
|
|
||||||
*
|
|
||||||
* The function returns the length of the string in bytes, `-1` if an
|
|
||||||
* error occurs. Potential errors are:
|
|
||||||
*
|
|
||||||
* * The `buffer` is a null pointer,
|
|
||||||
* * The `buffer` is too small to hold the error message.
|
|
||||||
*
|
|
||||||
* Note: The error message always has a trailing NUL character.
|
|
||||||
*
|
|
||||||
* Important note: If the provided `buffer` is non-null, once this
|
|
||||||
* function has been called, regardless whether it fails or succeeds,
|
|
||||||
* the error is cleared.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See this module's documentation to get a complete example.
|
|
||||||
*/
|
|
||||||
int wasmer_last_error_message(char *buffer, int length);
|
int wasmer_last_error_message(char *buffer, int length);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the version of the Wasmer C API.
|
|
||||||
*
|
|
||||||
* The `.h` files already define variables like `WASMER_VERSION*`,
|
|
||||||
* but if this file is unreachable, one can use this function to
|
|
||||||
* retrieve the full semver version of the Wasmer C API.
|
|
||||||
*
|
|
||||||
* The returned string is statically allocated. It must _not_ be
|
|
||||||
* freed!
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See the module's documentation.
|
|
||||||
*/
|
|
||||||
const char *wasmer_version(void);
|
const char *wasmer_version(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the major version of the Wasmer C API.
|
|
||||||
*
|
|
||||||
* See [`wasmer_version`] to learn more.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Get and print the version components.
|
|
||||||
* uint8_t version_major = wasmer_version_major();
|
|
||||||
* uint8_t version_minor = wasmer_version_minor();
|
|
||||||
* uint8_t version_patch = wasmer_version_patch();
|
|
||||||
*
|
|
||||||
* printf("%d.%d.%d", version_major, version_minor, version_patch);
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success()
|
|
||||||
* # .stdout(
|
|
||||||
* # format!(
|
|
||||||
* # "{}.{}.{}",
|
|
||||||
* # env!("CARGO_PKG_VERSION_MAJOR"),
|
|
||||||
* # env!("CARGO_PKG_VERSION_MINOR"),
|
|
||||||
* # env!("CARGO_PKG_VERSION_PATCH")
|
|
||||||
* # )
|
|
||||||
* # );
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
uint8_t wasmer_version_major(void);
|
uint8_t wasmer_version_major(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the minor version of the Wasmer C API.
|
|
||||||
*
|
|
||||||
* See [`wasmer_version_major`] to learn more and get an example.
|
|
||||||
*/
|
|
||||||
uint8_t wasmer_version_minor(void);
|
uint8_t wasmer_version_minor(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the patch version of the Wasmer C API.
|
|
||||||
*
|
|
||||||
* See [`wasmer_version_major`] to learn more and get an example.
|
|
||||||
*/
|
|
||||||
uint8_t wasmer_version_patch(void);
|
uint8_t wasmer_version_patch(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the minor version of the Wasmer C API.
|
|
||||||
*
|
|
||||||
* See [`wasmer_version_major`] to learn more.
|
|
||||||
*
|
|
||||||
* The returned string is statically allocated. It must _not_ be
|
|
||||||
* freed!
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* ```rust
|
|
||||||
* # use inline_c::assert_c;
|
|
||||||
* # fn main() {
|
|
||||||
* # (assert_c! {
|
|
||||||
* # #include "tests/wasmer_wasm.h"
|
|
||||||
* #
|
|
||||||
* int main() {
|
|
||||||
* // Get and print the pre version.
|
|
||||||
* const char* version_pre = wasmer_version_pre();
|
|
||||||
* printf("%s", version_pre);
|
|
||||||
*
|
|
||||||
* // No need to free the string. It's statically allocated on
|
|
||||||
* // the Rust side.
|
|
||||||
*
|
|
||||||
* return 0;
|
|
||||||
* }
|
|
||||||
* # })
|
|
||||||
* # .success()
|
|
||||||
* # .stdout(env!("CARGO_PKG_VERSION_PRE"));
|
|
||||||
* # }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
const char *wasmer_version_pre(void);
|
const char *wasmer_version_pre(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses in-memory bytes as either the WAT format, or a binary Wasm
|
|
||||||
* module. This is wasmer-specific.
|
|
||||||
*
|
|
||||||
* In case of failure, `wat2wasm` sets the `out->data = NULL` and `out->size = 0`.
|
|
||||||
*
|
|
||||||
* # Example
|
|
||||||
*
|
|
||||||
* See the module's documentation.
|
|
||||||
*/
|
|
||||||
void wat2wasm(const wasm_byte_vec_t *wat, wasm_byte_vec_t *out);
|
void wat2wasm(const wasm_byte_vec_t *wat, wasm_byte_vec_t *out);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Reference in New Issue
Block a user