From 82e4d8e6cc596a6563513a38f58d3f055d5784db Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 13 Nov 2019 15:54:09 +0100 Subject: [PATCH 1/4] feat(runtime-core) `func!` supports closures. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch allows to write: ```rs func!(|…| -> … { … }) ``` --- lib/runtime-core/src/macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/macros.rs b/lib/runtime-core/src/macros.rs index a9dc6721c..bb0c84fb2 100644 --- a/lib/runtime-core/src/macros.rs +++ b/lib/runtime-core/src/macros.rs @@ -47,7 +47,7 @@ macro_rules! trace { /// Helper macro to create a new `Func` object using the provided function pointer. #[macro_export] macro_rules! func { - ($func:path) => {{ + ($func:expr) => {{ $crate::Func::new($func) }}; } From 7b809a765f2e3134411f57bc46dd1f1c3eaf6cc8 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 13 Nov 2019 15:54:41 +0100 Subject: [PATCH 2/4] doc(runtime-core) Improve documentation of `func!`. This patch explains that `func!` can consume closures. --- lib/runtime-core/src/macros.rs | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/runtime-core/src/macros.rs b/lib/runtime-core/src/macros.rs index bb0c84fb2..9005b115d 100644 --- a/lib/runtime-core/src/macros.rs +++ b/lib/runtime-core/src/macros.rs @@ -45,6 +45,44 @@ macro_rules! trace { } /// Helper macro to create a new `Func` object using the provided function pointer. +/// +/// # Usage +/// +/// Function pointers or closures are supported. Closures can capture +/// their environment (with `move). The first parameter is likely to +/// be of kind `vm::Ctx`, though it can be optional. +/// +/// ``` +/// # use wasmer_runtime_core::{imports, func}; +/// # use wasmer_runtime_core::vm; +/// +/// // A function that has access to `vm::Ctx`. +/// fn func_with_vmctx(_: &mut vm::Ctx, n: i32) -> i32 { +/// n +/// } +/// +/// // A function that cannot access `vm::Ctx`. +/// fn func(n: i32) -> i32 { +/// n +/// } +/// +/// let i = 7; +/// +/// let import_object = imports! { +/// "env" => { +/// "foo" => func!(func_with_vmctx), +/// "bar" => func!(func), +/// // A closure with a captured environment, and an access to `vm::Ctx`. +/// "baz" => func!(move |_: &mut vm::Ctx, n: i32| -> i32 { +/// n + i +/// }), +/// // A closure without a captured environment, and no access to `vm::Ctx`. +/// "qux" => func!(|n: i32| -> i32 { +/// n +/// }), +/// }, +/// }; +/// ``` #[macro_export] macro_rules! func { ($func:expr) => {{ From c4dffd6f59d97c5ae6896aff7dfb6e96a602f13a Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 13 Nov 2019 15:55:45 +0100 Subject: [PATCH 3/4] doc(runtime-core) Fix typos. --- lib/runtime-core/src/macros.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime-core/src/macros.rs b/lib/runtime-core/src/macros.rs index 9005b115d..71e8c2e2f 100644 --- a/lib/runtime-core/src/macros.rs +++ b/lib/runtime-core/src/macros.rs @@ -94,12 +94,12 @@ macro_rules! func { /// /// [`ImportObject`]: struct.ImportObject.html /// -/// # Note: +/// # Note /// The `import` macro currently only supports /// importing functions. /// /// -/// # Usage: +/// # Usage /// ``` /// # use wasmer_runtime_core::{imports, func}; /// # use wasmer_runtime_core::vm::Ctx; From 9127eaf825f4f8ea9f1f82c7b064e799a5d3f6d8 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Wed, 13 Nov 2019 15:09:18 -0800 Subject: [PATCH 4/4] Add categories and keywords to `Cargo.toml`s --- lib/clif-backend/Cargo.toml | 2 ++ lib/emscripten/Cargo.toml | 2 ++ lib/llvm-backend/Cargo.toml | 4 ++++ lib/middleware-common/Cargo.toml | 2 ++ lib/runtime-c-api/Cargo.toml | 2 ++ lib/runtime-core/Cargo.toml | 2 ++ lib/runtime/Cargo.toml | 2 ++ lib/singlepass-backend/Cargo.toml | 2 ++ lib/wasi/Cargo.toml | 2 ++ 9 files changed, 20 insertions(+) diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index ff83c1315..b38e40b82 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -5,6 +5,8 @@ description = "Wasmer runtime Cranelift compiler backend" license = "MIT" authors = ["The Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "compiler", "JIT", "AOT"] +categories = ["wasm"] edition = "2018" readme = "README.md" diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index 104312256..3db03310f 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -5,6 +5,8 @@ description = "Wasmer runtime emscripten implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "ABI", "emscripten", "posix"] +categories = ["wasm"] edition = "2018" [dependencies] diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index b9c851b07..a728a9cec 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "wasmer-llvm-backend" version = "0.10.1" +license = "MIT" authors = ["The Wasmer Engineering Team "] +repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "compiler", "JIT", "llvm"] +categories = ["wasm"] edition = "2018" readme = "README.md" diff --git a/lib/middleware-common/Cargo.toml b/lib/middleware-common/Cargo.toml index 5840729d6..1c325183d 100644 --- a/lib/middleware-common/Cargo.toml +++ b/lib/middleware-common/Cargo.toml @@ -5,6 +5,8 @@ repository = "https://github.com/wasmerio/wasmer" description = "Wasmer runtime common middlewares" license = "MIT" authors = ["The Wasmer Engineering Team "] +keywords = ["wasm", "webassembly", "middleware", "metering"] +categories = ["wasm"] edition = "2018" [dependencies] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index cc689e889..90d97ff82 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -5,6 +5,8 @@ description = "Wasmer C API library" license = "MIT" authors = ["The Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "runtime"] +categories = ["wasm"] edition = "2018" readme = "README.md" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 0acbe718e..3d1b856ff 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -5,6 +5,8 @@ description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "runtime"] +categories = ["wasm"] edition = "2018" [dependencies] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 6e6be013c..8e272815a 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -5,6 +5,8 @@ description = "Wasmer runtime library" license = "MIT" authors = ["The Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "runtime", "sandbox", "secure"] +categories = ["wasm", "api-bindings"] edition = "2018" readme = "README.md" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 291d44455..5c28ff5e1 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -5,6 +5,8 @@ repository = "https://github.com/wasmerio/wasmer" description = "Wasmer runtime single pass compiler backend" license = "MIT" authors = ["The Wasmer Engineering Team "] +keywords = ["wasm", "webassembly", "compiler", "JIT", "AOT"] +categories = ["wasm"] edition = "2018" readme = "README.md" diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 8a85acc2d..6341ffb54 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -5,6 +5,8 @@ description = "Wasmer runtime WASI implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] repository = "https://github.com/wasmerio/wasmer" +keywords = ["wasm", "webassembly", "wasi", "sandbox", "ABI"] +categories = ["wasm"] edition = "2018" [dependencies]