-
Notifications
You must be signed in to change notification settings - Fork 848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable multiple backends supported by the api crate to be used in the c-api as well #5443
base: main
Are you sure you want to change the base?
Enable multiple backends supported by the api crate to be used in the c-api as well #5443
Conversation
…efault backend ... so that we don't have to build an engine to find out which engine is the default one per the enabled features.
📝 Documentation updates detected! A separate PR for documentation updates has been made here: wasmerio/docs.wasmer.io#118 |
|
||
impl Default for BackendKind { | ||
fn default() -> Self { | ||
#[cfg(feature = "sys-default")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the features collide and show a compiler error if that's the case? (eg: you can't enable sys-default
and wamr-default
at the same time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we already have this in the wasmer
crate: https://github.com/wasmerio/wasmer/blob/main/lib/api/src/lib.rs#L457
#[cfg(feature = "sys")] | ||
pub mod sys; | ||
#[cfg(feature = "sys")] | ||
pub use sys::wasm_config_set_sys_compiler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this wasm_config_sys_set_compiler
, so we can customize more settings in the future via wasm_config_sys_*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…epass` and `llvm` in `wasmer-api`
pub struct wasmer_wasmi_engine_config_t; | ||
|
||
/// Create a new [`wasm_engine_t`] backed by a `wasmi` engine. | ||
pub fn wasm_wasmi_engine_new_with_config(config: wasm_config_t) -> Option<Box<wasm_engine_t>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct wasmer_wamr_engine_config_t; | ||
|
||
/// Create a new [`wasm_engine_t`] backed by a `wamr` engine. | ||
pub fn wasm_wamr_engine_new_with_config(config: wasm_config_t) -> Option<Box<wasm_engine_t>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct wasmer_v8_engine_config_t; | ||
|
||
/// Create a new [`wasm_engine_t`] backed by a `v8` engine. | ||
pub fn wasm_v8_engine_new_with_config(config: wasm_config_t) -> Option<Box<wasm_engine_t>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
/// Create a new [`wasm_engine_t`] backed by a `sys` engine. | ||
pub fn wasm_sys_engine_new_with_config(config: wasm_config_t) -> Option<Box<wasm_engine_t>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct wasmer_jsc_engine_config_t; | ||
|
||
/// Create a new [`wasm_engine_t`] backed by a `jsc` engine. | ||
pub fn wasm_jsc_engine_new_with_config(config: wasm_config_t) -> Option<Box<wasm_engine_t>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…use `is_engine_available` to match
…e::get_exports()` in c_api backends
(fixes #5224)
This PR adds to the
wasm_engine_t
enum the kindsV8
,WAMR
,WASMI
andJSC
to reflect the different possible kinds of engine that can actually be used in the underlying implementation. These enum variants can be by users used as a means to set the wanted engine in the underlying implementation.Together with this addition, this PR changes the
wasm_config_t
type to (internally) hold an engine-specific configuration:where
wasmer_engine_config_t
is an enumeration of all the configurations for all the available engines:The two separate fields are needed because one,
wasmer_engine_t
, is public and users can set it; the other is definitely private and users cannot interact directly with it. This PR also introduces the relevant features to enable each of the backends cited above, with the matchingX-default
features to chose one as default.Note: this PR produces a number of breaking changes in the API. Most notably, functions that were implicitly tied to the
sys
engine only, are now scoped with thesys
name:wasm_config_canonicalize_nans
is nowwasm_config_sys_canonicalize_nans
. Same goes forwasm_config_set_sys_target
(previouslywasm_config_set_target
),wasm_config_sys_push_middleware
(previouslywasm_config_push_middleware
), andwasm_config_set_sys_compiler
(previouslywasm_config_set_compiler
).Furthermore, a chage in the semantics of these functions is (debatably) introduced: what does it mean to call
wasm_config_sys_push_middleware
on a config whose selectedwasmer_engine_t
is notsys
? In this PR the introduced behaviour is that of regardlessly change the selected engine tosys
:On one hand, this behaviour is transparent to the user - which should nonetheless expect the underlying engine to be the
sys
one, while on the other this function does not return a value, so we can't signal the user that the an error occurred in the case the currentconfig.engine != sys
.Notice, also, that to maintain a bit of backwards compatibility, the enum constructor in the
wasmer_engine_t
corresponding tosys
is stillUNIVERSAL
.Missing bits: