From b5fb4d06f8828326e1a6e5baa1237fa710062683 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 10 Dec 2020 17:02:38 +0100 Subject: [PATCH 01/14] feat(c-api) Add the `wasmer_version` function. --- lib/c-api/src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/c-api/src/lib.rs b/lib/c-api/src/lib.rs index 28946169b49..c44c3f96dc5 100644 --- a/lib/c-api/src/lib.rs +++ b/lib/c-api/src/lib.rs @@ -30,8 +30,51 @@ unreachable_patterns )] +use std::ffi::CString; +use std::mem; +use std::os::raw::c_char; + #[cfg(feature = "deprecated")] pub mod deprecated; pub mod error; mod ordered_resolver; pub mod wasm_c_api; + +/// Gets the version of the Wasmer C API. +/// +/// The returned string is guaranteed to be a valid C string. The +/// caller owns the string, so it's up to the caller to free it. +/// +/// # Example +/// +/// ```rust +/// # use inline_c::assert_c; +/// # fn main() { +/// # (assert_c! { +/// # #include "tests/wasmer_wasm.h" +/// # +/// int main() { +/// // Read and print the version. +/// char* version = wasmer_version(); +/// printf("%s", version); +/// +/// // Free it, as we own it. +/// free(version); +/// +/// return 0; +/// } +/// # }) +/// # .success() +/// # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); +/// # } +/// ``` +#[no_mangle] +pub extern "C" fn wasmer_version() -> *mut c_char { + let version = CString::new(env!("CARGO_PKG_VERSION")) + .expect("Failed to create a CString for the Wasmer C version"); + let ptr = version.as_ptr(); + + mem::forget(version); + + ptr as *mut _ +} From 417fc26d387742b210f6b3144a938ebe126b26dd Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 10 Dec 2020 17:08:06 +0100 Subject: [PATCH 02/14] doc(changelog) Add #1916. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8c5cc0b61d..fb2afd94f8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Added +* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `wasmer_version` function in the Wasmer C API * [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points` * [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError` * [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64` From 685ef32c292a9fb4f94fd78db2b66358adbf18bb Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 10 Dec 2020 17:08:32 +0100 Subject: [PATCH 03/14] chore(c-api) Update the header files. --- lib/c-api/wasmer.h | 32 ++++++++++++++++++++++++++++++++ lib/c-api/wasmer.hh | 30 ++++++++++++++++++++++++++++++ lib/c-api/wasmer_wasm.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/lib/c-api/wasmer.h b/lib/c-api/wasmer.h index f01244dbd46..22d02347994 100644 --- a/lib/c-api/wasmer.h +++ b/lib/c-api/wasmer.h @@ -1415,6 +1415,38 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e */ bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/** + * Gets the version of the Wasmer C API. + * + * The returned string is guaranteed to be a valid C string. The + * caller owns the string, so it's up to the caller to free it. + * + * # Example + * + * ```rust + * # use inline_c::assert_c; + * # fn main() { + * # (assert_c! { + * # #include "tests/wasmer_wasm.h" + * # + * int main() { + * // Read and print the version. + * char* version = wasmer_version(); + * printf("%s", version); + * + * // Free it, as we own it. + * free(version); + * + * return 0; + * } + * # }) + * # .success() + * # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); + * # } + * ``` + */ +char *wasmer_version(void); + #if defined(WASMER_WASI_ENABLED) /** * Convenience function that creates a WASI import object with no arguments, diff --git a/lib/c-api/wasmer.hh b/lib/c-api/wasmer.hh index 2c72b84b2f1..1444385413e 100644 --- a/lib/c-api/wasmer.hh +++ b/lib/c-api/wasmer.hh @@ -1173,6 +1173,36 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e /// ``` bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/// Gets the version of the Wasmer C API. +/// +/// The returned string is guaranteed to be a valid C string. The +/// caller owns the string, so it's up to the caller to free it. +/// +/// # Example +/// +/// ```rust +/// # use inline_c::assert_c; +/// # fn main() { +/// # (assert_c! { +/// # #include "tests/wasmer_wasm.h" +/// # +/// int main() { +/// // Read and print the version. +/// char* version = wasmer_version(); +/// printf("%s", version); +/// +/// // Free it, as we own it. +/// free(version); +/// +/// return 0; +/// } +/// # }) +/// # .success() +/// # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); +/// # } +/// ``` +char *wasmer_version(); + #if defined(WASMER_WASI_ENABLED) /// Convenience function that creates a WASI import object with no arguments, /// environment variables, preopened files, or mapped directories. diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 40a8c375dcb..609312d95c5 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -236,6 +236,38 @@ int wasmer_last_error_length(void); */ int wasmer_last_error_message(char *buffer, int length); +/** + * Gets the version of the Wasmer C API. + * + * The returned string is guaranteed to be a valid C string. The + * caller owns the string, so it's up to the caller to free it. + * + * # Example + * + * ```rust + * # use inline_c::assert_c; + * # fn main() { + * # (assert_c! { + * # #include "tests/wasmer_wasm.h" + * # + * int main() { + * // Read and print the version. + * char* version = wasmer_version(); + * printf("%s", version); + * + * // Free it, as we own it. + * free(version); + * + * return 0; + * } + * # }) + * # .success() + * # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); + * # } + * ``` + */ +char *wasmer_version(void); + /** * Parses in-memory bytes as either the WAT format, or a binary Wasm * module. This is wasmer-specific. From fdeb4a6845bdda90a46978a97fcc87bc1d39dcd7 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 11 Dec 2020 10:51:40 +0100 Subject: [PATCH 04/14] feat(c-api) Add the `WASMER_VERSION` constant in C. --- lib/c-api/build.rs | 27 +++++++++++++++++++++------ lib/c-api/wasmer.h | 10 +++++++--- lib/c-api/wasmer.hh | 10 +++++++--- lib/c-api/wasmer_wasm.h | 9 ++++++--- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index f2a57aa2877..fb29331ed8d 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -76,9 +76,9 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) { r#"// The Wasmer C/C++ header file compatible with the `wasm-c-api` standard API. // This file is generated by lib/c-api/build.rs. -#if !defined(WASMER_WASM_H_MACROS) +#if !defined(WASMER_WASM_H_PRELUDE) -#define WASMER_WASM_H_MACROS +#define WASMER_WASM_H_PRELUDE {pre_header}"#, pre_header = PRE_HEADER ); @@ -88,10 +88,12 @@ fn build_wasm_c_api_headers(crate_dir: &str, out_dir: &str) { map_feature_as_c_define!("wasi", WASI_FEATURE_AS_C_DEFINE, pre_header); map_feature_as_c_define!("emscripten", EMSCRIPTEN_FEATURE_AS_C_DEFINE, pre_header); + add_wasmer_version(&mut pre_header); + // Close pre header. pre_header.push_str( r#" -#endif // WASMER_WASM_H_MACROS +#endif // WASMER_WASM_H_PRELUDE // @@ -134,9 +136,9 @@ fn build_wasmer_headers(crate_dir: &str, out_dir: &str) { let mut pre_header = format!( r#"// The Wasmer C/C++ header file. -#if !defined(WASMER_H_MACROS) +#if !defined(WASMER_H_PRELUDE) -#define WASMER_H_MACROS +#define WASMER_H_PRELUDE {pre_header}"#, pre_header = PRE_HEADER ); @@ -144,9 +146,12 @@ fn build_wasmer_headers(crate_dir: &str, out_dir: &str) { map_feature_as_c_define!("wasi", WASI_FEATURE_AS_C_DEFINE, pre_header); map_feature_as_c_define!("emscritpen", EMSCRIPTEN_FEATURE_AS_C_DEFINE, pre_header); + add_wasmer_version(&mut pre_header); + // Close pre header. pre_header.push_str( - r#"#endif // WASMER_H_MACROS + r#" +#endif // WASMER_H_PRELUDE // @@ -196,6 +201,16 @@ fn build_wasmer_headers(crate_dir: &str, out_dir: &str) { } } +fn add_wasmer_version(pre_header: &mut String) { + pre_header.push_str(&format!( + r#" +// This file corresponds to the following Wasmer version. +#define WASMER_VERSION "{version}" +"#, + version = env!("CARGO_PKG_VERSION") + )); +} + /// Create a fresh new `Builder`, already pre-configured. fn new_builder(language: Language, crate_dir: &str, include_guard: &str, header: &str) -> Builder { Builder::new() diff --git a/lib/c-api/wasmer.h b/lib/c-api/wasmer.h index 22d02347994..771a87edd56 100644 --- a/lib/c-api/wasmer.h +++ b/lib/c-api/wasmer.h @@ -1,8 +1,8 @@ // The Wasmer C/C++ header file. -#if !defined(WASMER_H_MACROS) +#if !defined(WASMER_H_PRELUDE) -#define WASMER_H_MACROS +#define WASMER_H_PRELUDE // Define the `ARCH_X86_X64` constant. #if defined(MSVC) && defined(_M_AMD64) @@ -30,7 +30,11 @@ // The `wasi` feature has been enabled for this build. #define WASMER_WASI_ENABLED -#endif // WASMER_H_MACROS + +// This file corresponds to the following Wasmer version. +#define WASMER_VERSION "1.0.0-beta1" + +#endif // WASMER_H_PRELUDE // diff --git a/lib/c-api/wasmer.hh b/lib/c-api/wasmer.hh index 1444385413e..83edd2dc370 100644 --- a/lib/c-api/wasmer.hh +++ b/lib/c-api/wasmer.hh @@ -1,8 +1,8 @@ // The Wasmer C/C++ header file. -#if !defined(WASMER_H_MACROS) +#if !defined(WASMER_H_PRELUDE) -#define WASMER_H_MACROS +#define WASMER_H_PRELUDE // Define the `ARCH_X86_X64` constant. #if defined(MSVC) && defined(_M_AMD64) @@ -30,7 +30,11 @@ // The `wasi` feature has been enabled for this build. #define WASMER_WASI_ENABLED -#endif // WASMER_H_MACROS + +// This file corresponds to the following Wasmer version. +#define WASMER_VERSION "1.0.0-beta1" + +#endif // WASMER_H_PRELUDE // diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 3319de1c321..e27330c73f7 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -1,9 +1,9 @@ // The Wasmer C/C++ header file compatible with the `wasm-c-api` standard API. // This file is generated by lib/c-api/build.rs. -#if !defined(WASMER_WASM_H_MACROS) +#if !defined(WASMER_WASM_H_PRELUDE) -#define WASMER_WASM_H_MACROS +#define WASMER_WASM_H_PRELUDE // Define the `ARCH_X86_X64` constant. #if defined(MSVC) && defined(_M_AMD64) @@ -38,7 +38,10 @@ // The `wasi` feature has been enabled for this build. #define WASMER_WASI_ENABLED -#endif // WASMER_WASM_H_MACROS +// This file corresponds to the following Wasmer version. +#define WASMER_VERSION "1.0.0-beta1" + +#endif // WASMER_WASM_H_PRELUDE // From 2ce2c9c7d5a49a74afc165c3fb000b7baaa4d5db Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 11 Dec 2020 10:59:03 +0100 Subject: [PATCH 05/14] feat(c-api) Add the `WASMER_VERSION_{MAJOR|MINOR|PATCH|PRE}` constants in C. --- lib/c-api/build.rs | 12 ++++++++++-- lib/c-api/src/lib.rs | 43 ----------------------------------------- lib/c-api/wasmer.h | 36 ++++------------------------------ lib/c-api/wasmer.hh | 34 ++++---------------------------- lib/c-api/wasmer_wasm.h | 36 ++++------------------------------ 5 files changed, 22 insertions(+), 139 deletions(-) diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index fb29331ed8d..5c0539f8f0a 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -205,9 +205,17 @@ fn add_wasmer_version(pre_header: &mut String) { pre_header.push_str(&format!( r#" // This file corresponds to the following Wasmer version. -#define WASMER_VERSION "{version}" +#define WASMER_VERSION "{full}" +#define WASMER_VERSION_MAJOR {major} +#define WASMER_VERSION_MINOR {minor} +#define WASMER_VERSION_PATCH {patch} +#define WASMER_VERSION_PRE "{pre}" "#, - version = env!("CARGO_PKG_VERSION") + full = env!("CARGO_PKG_VERSION"), + major = env!("CARGO_PKG_VERSION_MAJOR"), + minor = env!("CARGO_PKG_VERSION_MINOR"), + patch = env!("CARGO_PKG_VERSION_PATCH"), + pre = env!("CARGO_PKG_VERSION_PRE"), )); } diff --git a/lib/c-api/src/lib.rs b/lib/c-api/src/lib.rs index c44c3f96dc5..28946169b49 100644 --- a/lib/c-api/src/lib.rs +++ b/lib/c-api/src/lib.rs @@ -30,51 +30,8 @@ unreachable_patterns )] -use std::ffi::CString; -use std::mem; -use std::os::raw::c_char; - #[cfg(feature = "deprecated")] pub mod deprecated; pub mod error; mod ordered_resolver; pub mod wasm_c_api; - -/// Gets the version of the Wasmer C API. -/// -/// The returned string is guaranteed to be a valid C string. The -/// caller owns the string, so it's up to the caller to free it. -/// -/// # Example -/// -/// ```rust -/// # use inline_c::assert_c; -/// # fn main() { -/// # (assert_c! { -/// # #include "tests/wasmer_wasm.h" -/// # -/// int main() { -/// // Read and print the version. -/// char* version = wasmer_version(); -/// printf("%s", version); -/// -/// // Free it, as we own it. -/// free(version); -/// -/// return 0; -/// } -/// # }) -/// # .success() -/// # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); -/// # } -/// ``` -#[no_mangle] -pub extern "C" fn wasmer_version() -> *mut c_char { - let version = CString::new(env!("CARGO_PKG_VERSION")) - .expect("Failed to create a CString for the Wasmer C version"); - let ptr = version.as_ptr(); - - mem::forget(version); - - ptr as *mut _ -} diff --git a/lib/c-api/wasmer.h b/lib/c-api/wasmer.h index 771a87edd56..506299f844c 100644 --- a/lib/c-api/wasmer.h +++ b/lib/c-api/wasmer.h @@ -33,6 +33,10 @@ // This file corresponds to the following Wasmer version. #define WASMER_VERSION "1.0.0-beta1" +#define WASMER_VERSION_MAJOR 1 +#define WASMER_VERSION_MINOR 0 +#define WASMER_VERSION_PATCH 0 +#define WASMER_VERSION_PRE "beta1" #endif // WASMER_H_PRELUDE @@ -1419,38 +1423,6 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e */ bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); -/** - * Gets the version of the Wasmer C API. - * - * The returned string is guaranteed to be a valid C string. The - * caller owns the string, so it's up to the caller to free it. - * - * # Example - * - * ```rust - * # use inline_c::assert_c; - * # fn main() { - * # (assert_c! { - * # #include "tests/wasmer_wasm.h" - * # - * int main() { - * // Read and print the version. - * char* version = wasmer_version(); - * printf("%s", version); - * - * // Free it, as we own it. - * free(version); - * - * return 0; - * } - * # }) - * # .success() - * # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); - * # } - * ``` - */ -char *wasmer_version(void); - #if defined(WASMER_WASI_ENABLED) /** * Convenience function that creates a WASI import object with no arguments, diff --git a/lib/c-api/wasmer.hh b/lib/c-api/wasmer.hh index 83edd2dc370..7cf1b38bf90 100644 --- a/lib/c-api/wasmer.hh +++ b/lib/c-api/wasmer.hh @@ -33,6 +33,10 @@ // This file corresponds to the following Wasmer version. #define WASMER_VERSION "1.0.0-beta1" +#define WASMER_VERSION_MAJOR 1 +#define WASMER_VERSION_MINOR 0 +#define WASMER_VERSION_PATCH 0 +#define WASMER_VERSION_PRE "beta1" #endif // WASMER_H_PRELUDE @@ -1177,36 +1181,6 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e /// ``` bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); -/// Gets the version of the Wasmer C API. -/// -/// The returned string is guaranteed to be a valid C string. The -/// caller owns the string, so it's up to the caller to free it. -/// -/// # Example -/// -/// ```rust -/// # use inline_c::assert_c; -/// # fn main() { -/// # (assert_c! { -/// # #include "tests/wasmer_wasm.h" -/// # -/// int main() { -/// // Read and print the version. -/// char* version = wasmer_version(); -/// printf("%s", version); -/// -/// // Free it, as we own it. -/// free(version); -/// -/// return 0; -/// } -/// # }) -/// # .success() -/// # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); -/// # } -/// ``` -char *wasmer_version(); - #if defined(WASMER_WASI_ENABLED) /// Convenience function that creates a WASI import object with no arguments, /// environment variables, preopened files, or mapped directories. diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index e27330c73f7..2fecb19cb92 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -40,6 +40,10 @@ // This file corresponds to the following Wasmer version. #define WASMER_VERSION "1.0.0-beta1" +#define WASMER_VERSION_MAJOR 1 +#define WASMER_VERSION_MINOR 0 +#define WASMER_VERSION_PATCH 0 +#define WASMER_VERSION_PRE "beta1" #endif // WASMER_WASM_H_PRELUDE @@ -305,38 +309,6 @@ int wasmer_last_error_length(void); */ int wasmer_last_error_message(char *buffer, int length); -/** - * Gets the version of the Wasmer C API. - * - * The returned string is guaranteed to be a valid C string. The - * caller owns the string, so it's up to the caller to free it. - * - * # Example - * - * ```rust - * # use inline_c::assert_c; - * # fn main() { - * # (assert_c! { - * # #include "tests/wasmer_wasm.h" - * # - * int main() { - * // Read and print the version. - * char* version = wasmer_version(); - * printf("%s", version); - * - * // Free it, as we own it. - * free(version); - * - * return 0; - * } - * # }) - * # .success() - * # .stdout(std::env::var("CARGO_PKG_VERSION").unwrap()); - * # } - * ``` - */ -char *wasmer_version(void); - /** * Parses in-memory bytes as either the WAT format, or a binary Wasm * module. This is wasmer-specific. From a0abe41d4af6bf254152a9cc14b4bcd6b124f77d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 11 Dec 2020 11:04:30 +0100 Subject: [PATCH 06/14] doc(changelog) Update #1916. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18d782d841e..b9f0ff88c25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Added -* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `wasmer_version` function in the Wasmer C API +* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `WASMER_VERSION*` constants in the Wasmer C API * [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points` * [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError` * [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64` From ae7ec9da3bd6f86ad5d17fe9558682fe85fbdf9e Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sun, 13 Dec 2020 23:41:14 +0100 Subject: [PATCH 07/14] Remove unused dependency memmap --- Cargo.lock | 1 - lib/cache/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e67b235f73f..d77df4e9ae0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2465,7 +2465,6 @@ version = "1.0.0-beta1" dependencies = [ "blake3", "hex", - "memmap", "thiserror", "wasmer", ] diff --git a/lib/cache/Cargo.toml b/lib/cache/Cargo.toml index 865e78500bf..5832d6946a1 100644 --- a/lib/cache/Cargo.toml +++ b/lib/cache/Cargo.toml @@ -12,7 +12,6 @@ edition = "2018" [dependencies] wasmer = { path = "../api", version = "1.0.0-beta1", default-features = false } -memmap = "0.7" hex = "0.4" thiserror = "1" blake3 = "0.3" From e5a52f195a75e5553b4291dcab5ddc07f06b95b4 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sun, 13 Dec 2020 23:53:16 +0100 Subject: [PATCH 08/14] Use memmap2 in deserialize_from_file --- CHANGELOG.md | 1 + Cargo.lock | 10 ++++++++++ lib/engine/Cargo.toml | 1 + lib/engine/src/engine.rs | 6 ++++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d35e464d741..e2dc56dd2e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points` * [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError` * [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64` +* [#1927](https://github.com/wasmerio/wasmer/pull/1927) Added mmap support in `Engine::deserialize_from_file` to speed up artifact loading ### Changed diff --git a/Cargo.lock b/Cargo.lock index d77df4e9ae0..a383d0cf98f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1186,6 +1186,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "memmap2" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b70ca2a6103ac8b665dc150b142ef0e4e89df640c9e6cf295d189c3caebe5a" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.6.1" @@ -2612,6 +2621,7 @@ dependencies = [ "backtrace", "bincode", "lazy_static", + "memmap2", "more-asserts", "rustc-demangle", "serde", diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml index efa4c8f900d..72aa3350f3d 100644 --- a/lib/engine/Cargo.toml +++ b/lib/engine/Cargo.toml @@ -18,6 +18,7 @@ target-lexicon = { version = "0.11", default-features = false } # flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" } backtrace = "0.3" rustc-demangle = "0.1" +memmap2 = "0.1.0" more-asserts = "0.2" thiserror = "1.0" serde = { version = "1.0", features = ["derive", "rc"] } diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index 2828bfc52a3..8cfceb3a83f 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -2,6 +2,7 @@ use crate::tunables::Tunables; use crate::{Artifact, DeserializeError}; +use memmap2::Mmap; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::Arc; @@ -51,8 +52,9 @@ pub trait Engine { &self, file_ref: &Path, ) -> Result, DeserializeError> { - let bytes = std::fs::read(file_ref)?; - self.deserialize(&bytes) + let file = std::fs::File::open(file_ref)?; + let mmap = Mmap::map(&file)?; + self.deserialize(&mmap) } /// A unique identifier for this object. From 3a8a0d3ed9f9eac50b4492b2a9e7f008f1eaabdd Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 14 Dec 2020 11:13:55 +0100 Subject: [PATCH 09/14] feat(c-api) Implement the `wasmer_version` function. When the `.h` files aren't accessible, it is useful to get a function to retrieve the version of the Wasmer C API. --- lib/c-api/src/wasm_c_api/mod.rs | 2 ++ lib/c-api/src/wasm_c_api/version.rs | 40 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/c-api/src/wasm_c_api/version.rs diff --git a/lib/c-api/src/wasm_c_api/mod.rs b/lib/c-api/src/wasm_c_api/mod.rs index 5fa5cf29bea..e3a851967ac 100644 --- a/lib/c-api/src/wasm_c_api/mod.rs +++ b/lib/c-api/src/wasm_c_api/mod.rs @@ -46,6 +46,8 @@ pub mod types; /// cbindgen:ignore pub mod value; +pub mod version; + #[cfg(feature = "wasi")] pub mod wasi; diff --git a/lib/c-api/src/wasm_c_api/version.rs b/lib/c-api/src/wasm_c_api/version.rs new file mode 100644 index 00000000000..ad746c58eaa --- /dev/null +++ b/lib/c-api/src/wasm_c_api/version.rs @@ -0,0 +1,40 @@ +use std::os::raw::c_char; + +static VERSION: &'static str = env!("CARGO_PKG_VERSION"); + +/// Get the version of Wasmer. +/// +/// 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 +/// +/// ```rust +/// # use inline_c::assert_c; +/// # fn main() { +/// # (assert_c! { +/// # #include "tests/wasmer_wasm.h" +/// # +/// int main() { +/// // Get and print the version. +/// const char* version = wasmer_version(); +/// printf("%s", version); +/// +/// // No need to free the string. It's statically allocated on +/// // the Rust side. +/// +/// return 0; +/// } +/// # }) +/// # .success() +/// # .stdout(env!("CARGO_PKG_VERSION")); +/// # } +/// ``` +#[no_mangle] +pub unsafe extern "C" fn wasmer_version() -> *const c_char { + VERSION.as_ptr() as *const _ +} From f75eb29620e7235413eb52c63d92c3716730069b Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 14 Dec 2020 11:17:46 +0100 Subject: [PATCH 10/14] chore(c-api) Update the header files. --- lib/c-api/wasmer.h | 36 ++++++++++++++++++++++++++++++++++++ lib/c-api/wasmer.hh | 34 ++++++++++++++++++++++++++++++++++ lib/c-api/wasmer_wasm.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/lib/c-api/wasmer.h b/lib/c-api/wasmer.h index 506299f844c..76a08d61197 100644 --- a/lib/c-api/wasmer.h +++ b/lib/c-api/wasmer.h @@ -1423,6 +1423,42 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e */ bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/** + * Get the version of Wasmer. + * + * 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 + * + * ```rust + * # use inline_c::assert_c; + * # fn main() { + * # (assert_c! { + * # #include "tests/wasmer_wasm.h" + * # + * int main() { + * // Get and print the version. + * const char* version = wasmer_version(); + * printf("%s", version); + * + * // No need to free the string. It's statically allocated on + * // the Rust side. + * + * return 0; + * } + * # }) + * # .success() + * # .stdout(env!("CARGO_PKG_VERSION")); + * # } + * ``` + */ +const char *wasmer_version(void); + #if defined(WASMER_WASI_ENABLED) /** * Convenience function that creates a WASI import object with no arguments, diff --git a/lib/c-api/wasmer.hh b/lib/c-api/wasmer.hh index 7cf1b38bf90..c72b0c43469 100644 --- a/lib/c-api/wasmer.hh +++ b/lib/c-api/wasmer.hh @@ -1181,6 +1181,40 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e /// ``` bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/// Get the version of Wasmer. +/// +/// 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 +/// +/// ```rust +/// # use inline_c::assert_c; +/// # fn main() { +/// # (assert_c! { +/// # #include "tests/wasmer_wasm.h" +/// # +/// int main() { +/// // Get and print the version. +/// const char* version = wasmer_version(); +/// printf("%s", version); +/// +/// // No need to free the string. It's statically allocated on +/// // the Rust side. +/// +/// return 0; +/// } +/// # }) +/// # .success() +/// # .stdout(env!("CARGO_PKG_VERSION")); +/// # } +/// ``` +const char *wasmer_version(); + #if defined(WASMER_WASI_ENABLED) /// Convenience function that creates a WASI import object with no arguments, /// environment variables, preopened files, or mapped directories. diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 2fecb19cb92..55f7b600882 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -309,6 +309,42 @@ int wasmer_last_error_length(void); */ int wasmer_last_error_message(char *buffer, int length); +/** + * Get the version of Wasmer. + * + * 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 + * + * ```rust + * # use inline_c::assert_c; + * # fn main() { + * # (assert_c! { + * # #include "tests/wasmer_wasm.h" + * # + * int main() { + * // Get and print the version. + * const char* version = wasmer_version(); + * printf("%s", version); + * + * // No need to free the string. It's statically allocated on + * // the Rust side. + * + * return 0; + * } + * # }) + * # .success() + * # .stdout(env!("CARGO_PKG_VERSION")); + * # } + * ``` + */ +const char *wasmer_version(void); + /** * Parses in-memory bytes as either the WAT format, or a binary Wasm * module. This is wasmer-specific. From 43caa8a66ba011a92cd1cd3c41977a71cde5af1c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 14 Dec 2020 11:19:37 +0100 Subject: [PATCH 11/14] doc(changelog) Update #1916. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc8f06084e8..d2000b84e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Added -* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `WASMER_VERSION*` constants in the Wasmer C API +* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `WASMER_VERSION*` constants with the `wasmer_version` function in the Wasmer C API * [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points` * [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError` * [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64` From f4e3f2a627098264e4f57285d1fd26ab56cce045 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 14 Dec 2020 13:42:08 +0100 Subject: [PATCH 12/14] feat(c-api) Add `wasmer_version_(major,minor,patch,pre)` functions. --- lib/c-api/src/wasm_c_api/version.rs | 108 +++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 2 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/version.rs b/lib/c-api/src/wasm_c_api/version.rs index ad746c58eaa..82aa42d415f 100644 --- a/lib/c-api/src/wasm_c_api/version.rs +++ b/lib/c-api/src/wasm_c_api/version.rs @@ -1,8 +1,22 @@ +use lazy_static::lazy_static; use std::os::raw::c_char; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const VERSION: &'static str = concat!(env!("CARGO_PKG_VERSION"), "\0"); +const VERSION_PRE: &'static str = concat!(env!("CARGO_PKG_VERSION_PRE"), "\0"); -/// Get the version of Wasmer. +lazy_static! { + static ref VERSION_MAJOR: u8 = env!("CARGO_PKG_VERSION_MAJOR") + .parse() + .expect("Failed to parse value for `VERSION_MAJOR` from `CARGO_PKG_VERSION_MAJOR`"); + static ref VERSION_MINOR: u8 = env!("CARGO_PKG_VERSION_MINOR") + .parse() + .expect("Failed to parse value for `VERSION_MINOR` from `CARGO_PKG_VERSION_MINOR`"); + static ref VERSION_PATCH: u8 = env!("CARGO_PKG_VERSION_PATCH") + .parse() + .expect("Failed to parse value for `VERSION_PATCH` from `CARGO_PKG_VERSION_PATCH`"); +} + +/// 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 @@ -38,3 +52,93 @@ static VERSION: &'static str = env!("CARGO_PKG_VERSION"); pub unsafe extern "C" fn wasmer_version() -> *const c_char { VERSION.as_ptr() as *const _ } + +/// 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") +/// # ) +/// # ); +/// # } +/// ``` +#[no_mangle] +pub unsafe extern "C" fn wasmer_version_major() -> u8 { + *VERSION_MAJOR +} + +/// Get the minor version of the Wasmer C API. +/// +/// See `wasmer_version_major` to learn more and get an example. +#[no_mangle] +pub unsafe extern "C" fn wasmer_version_minor() -> u8 { + *VERSION_MINOR +} + +/// Get the patch version of the Wasmer C API. +/// +/// See `wasmer_version_major` to learn more and get an example. +#[no_mangle] +pub unsafe extern "C" fn wasmer_version_patch() -> u8 { + *VERSION_PATCH +} + +/// 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")); +/// # } +/// ``` +#[no_mangle] +pub unsafe extern "C" fn wasmer_version_pre() -> *const c_char { + VERSION_PRE.as_ptr() as *const _ +} From b045b415f6cee626c6e03bee385b60daf9b2732a Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 14 Dec 2020 13:42:29 +0100 Subject: [PATCH 13/14] chore(c-api) Update the header files. --- lib/c-api/wasmer.h | 88 ++++++++++++++++++++++++++++++++++++++++- lib/c-api/wasmer.hh | 80 ++++++++++++++++++++++++++++++++++++- lib/c-api/wasmer_wasm.h | 88 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 253 insertions(+), 3 deletions(-) diff --git a/lib/c-api/wasmer.h b/lib/c-api/wasmer.h index 76a08d61197..fb365f77641 100644 --- a/lib/c-api/wasmer.h +++ b/lib/c-api/wasmer.h @@ -1424,7 +1424,7 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); /** - * Get the version of Wasmer. + * 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 @@ -1459,6 +1459,92 @@ bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); */ 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); + +/** + * 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); + +/** + * 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); + +/** + * 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); + #if defined(WASMER_WASI_ENABLED) /** * Convenience function that creates a WASI import object with no arguments, diff --git a/lib/c-api/wasmer.hh b/lib/c-api/wasmer.hh index c72b0c43469..b8a0ba6c934 100644 --- a/lib/c-api/wasmer.hh +++ b/lib/c-api/wasmer.hh @@ -1181,7 +1181,7 @@ wasmer_result_t wasmer_trap(const wasmer_instance_context_t *_ctx, const char *e /// ``` bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); -/// Get the version of Wasmer. +/// 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 @@ -1215,6 +1215,84 @@ bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); /// ``` const char *wasmer_version(); +/// 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(); + +/// 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(); + +/// 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(); + +/// 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(); + #if defined(WASMER_WASI_ENABLED) /// Convenience function that creates a WASI import object with no arguments, /// environment variables, preopened files, or mapped directories. diff --git a/lib/c-api/wasmer_wasm.h b/lib/c-api/wasmer_wasm.h index 55f7b600882..9b4511cbeaf 100644 --- a/lib/c-api/wasmer_wasm.h +++ b/lib/c-api/wasmer_wasm.h @@ -310,7 +310,7 @@ int wasmer_last_error_length(void); int wasmer_last_error_message(char *buffer, int length); /** - * Get the version of Wasmer. + * 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 @@ -345,6 +345,92 @@ int wasmer_last_error_message(char *buffer, int length); */ 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); + +/** + * 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); + +/** + * 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); + +/** + * 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); + /** * Parses in-memory bytes as either the WAT format, or a binary Wasm * module. This is wasmer-specific. From 110c6aa992d14bc5664dba8371a3db3eadff4cfa Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 14 Dec 2020 13:44:23 +0100 Subject: [PATCH 14/14] doc(changelog) Update #1916. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2000b84e76..5c93e25ce71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Added -* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `WASMER_VERSION*` constants with the `wasmer_version` function in the Wasmer C API +* [#1916](https://github.com/wasmerio/wasmer/pull/1916) Add the `WASMER_VERSION*` constants with the `wasmer_version*` functions in the Wasmer C API * [#1867](https://github.com/wasmerio/wasmer/pull/1867) Added `Metering::get_remaining_points` and `Metering::set_remaining_points` * [#1881](https://github.com/wasmerio/wasmer/pull/1881) Added `UnsupportedTarget` error to `CompileError` * [#1908](https://github.com/wasmerio/wasmer/pull/1908) Implemented `TryFrom>` for `i32`/`u32`/`i64`/`u64`/`f32`/`f64`