Skip to content

Commit

Permalink
rust: add Wasmtime bindings
Browse files Browse the repository at this point in the history
The C++ bindings provided by wasmtime are lacking a crucial
capability: asynchronous execution of the wasm functions.
This forces us to stop the execution of the function after
a short time to prevent increasing the latency. Fortunately,
this feature is implemented in the native language
of Wasmtime - Rust. Support for Rust was recently added to
scylla, so we can implement the async bindings ourselves,
which is done in this patch.

The bindings expose all the objects necessary for creating
and calling wasm functions. The majority of code implemented
in Rust is a translation of code that was previously present
in C++.

Types exported from Rust are currently required to be defined
by the  same crate that contains the bridge using them, so
wasmtime types can't be exported directly. Instead, for each
class that was supposed to be exported, a wrapper type is
created, where its first member is the wasmtime class. Note
that the members are not visible from C++ anyway, the
difference only applies to Rust code.

Aside from wasmtime types and methods, two additional types
are exported with some associated methods.
- The first one is ValVec, which is a wrapper for a rust Vec
of wasmtime Vals. The underlying vector is required by
wasmtime methods for calling wasm functions. By having it
exported we avoid multiple conversions from a Val wrapper
to a wasmtime Val, as would be required if we exported a
rust Vec of Val wrappers (the rust Vec itself does not
require wrappers if the type it contains is already wrapped)
- The second one is Fut. This class represents an computation
tha may or may not be ready. We're currently using it
to control the execution of wasm functions from C++. This
class exposes one method: resume(), which returns a bool
that signals whether the computation is finished or not.

Signed-off-by: Wojciech Mitros <wojciech.mitros@scylladb.com>
  • Loading branch information
wmitros committed Aug 29, 2022
1 parent 7899366 commit bc91707
Show file tree
Hide file tree
Showing 7 changed files with 2,207 additions and 24 deletions.
3 changes: 3 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ def find_headers(repodir, excluded_dirs):
'rust/Cargo.lock',
'rust/inc/src/lib.rs',
'rust/inc/Cargo.toml',
'rust/wasmtime_bindings/src/lib.rs',
'rust/wasmtime_bindings/src/memory_creator.rs',
'rust/wasmtime_bindings/Cargo.toml',
]

scylla_core = (['message/messaging_service.cc',
Expand Down

0 comments on commit bc91707

Please sign in to comment.