wasmer_c_api/wasm_c_api/unstable/
features.rs

1//! Unstable non-standard Wasmer-specific API that contains a Features
2//! API for the engine and the compiler.
3//!
4//!
5//! # Example
6//!
7//! ```rust
8//! # use wasmer_inline_c::assert_c;
9//! # fn main() {
10//! #    (assert_c! {
11//! # #include "tests/wasmer.h"
12//! #
13//! int main() {
14//!     // Declare features.
15//!     wasmer_features_t* features = wasmer_features_new();
16//!
17//!     // Now, let's enable the SIMD feature.
18//!     wasmer_features_simd(features, true);
19//!
20//!     // And also the memory64 feature.     
21//!     wasmer_features_memory64(features, true);
22//!
23//!     wasmer_features_delete(features);
24//!
25//!     return 0;
26//! }
27//! #    })
28//! #    .success();
29//! # }
30//! ```
31//!
32//! To go further, see
33//! [`wasm_config_set_features`](super::engine::wasm_config_set_features).
34
35use wasmer_types::Features;
36
37/// Controls which experimental features will be enabled.
38/// Features usually have a corresponding [WebAssembly proposal].
39///
40/// [WebAssembly proposal]: https://github.com/WebAssembly/proposals
41///
42/// # Example
43///
44/// See the module's documentation.
45#[derive(Debug)]
46#[allow(non_camel_case_types)]
47pub struct wasmer_features_t {
48    pub(crate) inner: Features,
49}
50
51/// Creates a new [`wasmer_features_t`].
52///
53/// # Example
54///
55/// See the module's documentation.
56#[unsafe(no_mangle)]
57pub extern "C" fn wasmer_features_new() -> Box<wasmer_features_t> {
58    Box::new(wasmer_features_t {
59        inner: Features::new(),
60    })
61}
62
63/// Delete a [`wasmer_features_t`].
64///
65/// # Example
66///
67/// See the module's documentation.
68#[unsafe(no_mangle)]
69pub extern "C" fn wasmer_features_delete(_features: Option<Box<wasmer_features_t>>) {}
70
71/// Configures whether the WebAssembly threads proposal will be enabled.
72///
73/// The [WebAssembly threads proposal][threads] is not currently fully
74/// standardized and is undergoing development. Support for this feature can
75/// be disabled through this method for appropriate WebAssembly modules.
76///
77/// This feature gates items such as shared memories and atomic
78/// instructions.
79///
80/// This is `true` by default.
81///
82/// [threads]: https://github.com/webassembly/threads
83///
84/// # Example
85///
86/// See the module's documentation.
87#[unsafe(no_mangle)]
88pub extern "C" fn wasmer_features_threads(
89    features: Option<&mut wasmer_features_t>,
90    enable: bool,
91) -> bool {
92    let features = match features {
93        Some(features) => features,
94        _ => return false,
95    };
96
97    features.inner.threads(enable);
98
99    true
100}
101
102/// Configures whether the WebAssembly reference types proposal will be
103/// enabled.
104///
105/// The [WebAssembly reference types proposal][proposal] is now
106/// fully standardized and enabled by default.
107///
108/// This feature gates items such as the `externref` type and multiple tables
109/// being in a module. Note that enabling the reference types feature will
110/// also enable the bulk memory feature.
111///
112/// This is `false` by default.
113///
114/// [proposal]: https://github.com/webassembly/reference-types
115///
116/// # Example
117///
118/// See the module's documentation.
119#[unsafe(no_mangle)]
120pub extern "C" fn wasmer_features_reference_types(
121    features: Option<&mut wasmer_features_t>,
122    enable: bool,
123) -> bool {
124    let features = match features {
125        Some(features) => features,
126        _ => return false,
127    };
128
129    features.inner.reference_types(enable);
130
131    true
132}
133
134/// Configures whether the WebAssembly SIMD proposal will be
135/// enabled.
136///
137/// The [WebAssembly SIMD proposal][proposal] is now
138/// fully standardized.
139/// Support for this feature can be enabled through this method
140/// for appropriate WebAssembly modules.
141///
142/// This feature gates items such as the `v128` type and all of its
143/// operators being in a module.
144///
145/// This is `false` by default.
146///
147/// [proposal]: https://github.com/webassembly/simd
148///
149/// # Example
150///
151/// See the module's documentation.
152#[unsafe(no_mangle)]
153pub extern "C" fn wasmer_features_simd(
154    features: Option<&mut wasmer_features_t>,
155    enable: bool,
156) -> bool {
157    let features = match features {
158        Some(features) => features,
159        _ => return false,
160    };
161
162    features.inner.simd(enable);
163
164    true
165}
166
167/// Configures whether the WebAssembly bulk memory operations proposal will
168/// be enabled.
169///
170/// The [WebAssembly bulk memory operations proposal][proposal] is now
171/// fully standardized and enabled by default.
172///
173/// This feature gates items such as the `memory.copy` instruction, passive
174/// data/table segments, etc, being in a module.
175///
176/// This is `true` by default.
177///
178/// [proposal]: https://github.com/webassembly/bulk-memory-operations
179///
180/// # Example
181///
182/// See the module's documentation.
183#[unsafe(no_mangle)]
184pub extern "C" fn wasmer_features_bulk_memory(
185    features: Option<&mut wasmer_features_t>,
186    enable: bool,
187) -> bool {
188    let features = match features {
189        Some(features) => features,
190        _ => return false,
191    };
192
193    features.inner.bulk_memory(enable);
194
195    true
196}
197
198/// Configures whether the WebAssembly multi-value proposal will
199/// be enabled.
200///
201/// The [WebAssembly multi-value proposal][proposal] is now fully
202/// standardized and enabled by default.
203///
204/// This feature gates functions and blocks returning multiple values in a
205/// module, for example.
206///
207/// This is `true` by default.
208///
209/// [proposal]: https://github.com/webassembly/multi-value
210///
211/// # Example
212///
213/// See the module's documentation.
214#[unsafe(no_mangle)]
215pub extern "C" fn wasmer_features_multi_value(
216    features: Option<&mut wasmer_features_t>,
217    enable: bool,
218) -> bool {
219    let features = match features {
220        Some(features) => features,
221        _ => return false,
222    };
223
224    features.inner.multi_value(enable);
225
226    true
227}
228
229/// Configures whether the WebAssembly tail-call proposal will
230/// be enabled.
231///
232/// The [WebAssembly tail-call proposal][proposal] is not
233/// currently fully standardized and is undergoing development.
234/// Support for this feature can be enabled through this method for
235/// appropriate WebAssembly modules.
236///
237/// This feature gates tail-call functions in WebAssembly.
238///
239/// This is `false` by default.
240///
241/// [proposal]: https://github.com/webassembly/tail-call
242///
243/// # Example
244///
245/// See the module's documentation.
246#[unsafe(no_mangle)]
247pub extern "C" fn wasmer_features_tail_call(
248    features: Option<&mut wasmer_features_t>,
249    enable: bool,
250) -> bool {
251    let features = match features {
252        Some(features) => features,
253        _ => return false,
254    };
255
256    features.inner.tail_call(enable);
257
258    true
259}
260
261/// Configures whether the WebAssembly module linking proposal will
262/// be enabled.
263///
264/// The [WebAssembly module linking proposal][proposal] is not
265/// currently fully standardized and is undergoing development.
266/// Support for this feature can be enabled through this method for
267/// appropriate WebAssembly modules.
268///
269/// This feature allows WebAssembly modules to define, import and
270/// export modules and instances.
271///
272/// This is `false` by default.
273///
274/// [proposal]: https://github.com/webassembly/module-linking
275///
276/// # Example
277///
278/// See the module's documentation.
279#[unsafe(no_mangle)]
280pub extern "C" fn wasmer_features_module_linking(
281    features: Option<&mut wasmer_features_t>,
282    enable: bool,
283) -> bool {
284    let features = match features {
285        Some(features) => features,
286        _ => return false,
287    };
288
289    features.inner.module_linking(enable);
290
291    true
292}
293
294/// Configures whether the WebAssembly multi-memory proposal will
295/// be enabled.
296///
297/// The [WebAssembly multi-memory proposal][proposal] is now
298/// fully standardized.
299/// Support for this feature can be enabled through this method
300/// for appropriate WebAssembly modules.
301///
302/// This feature adds the ability to use multiple memories within a
303/// single Wasm module.
304///
305/// This is `false` by default.
306///
307/// [proposal]: https://github.com/WebAssembly/multi-memory
308///
309/// # Example
310///
311/// See the module's documentation.
312#[unsafe(no_mangle)]
313pub extern "C" fn wasmer_features_multi_memory(
314    features: Option<&mut wasmer_features_t>,
315    enable: bool,
316) -> bool {
317    let features = match features {
318        Some(features) => features,
319        _ => return false,
320    };
321
322    features.inner.multi_memory(enable);
323
324    true
325}
326
327/// Configures whether the WebAssembly 64-bit memory proposal will
328/// be enabled.
329///
330/// The [WebAssembly 64-bit memory proposal][proposal] is now
331/// fully standardized.
332/// Support for this feature can be enabled through this method
333/// for appropriate WebAssembly modules.
334///
335/// This feature gates support for linear memory of sizes larger than
336/// 2^32 bits.
337///
338/// This is `false` by default.
339///
340/// [proposal]: https://github.com/WebAssembly/memory64
341///
342/// # Example
343///
344/// See the module's documentation.
345#[unsafe(no_mangle)]
346pub extern "C" fn wasmer_features_memory64(
347    features: Option<&mut wasmer_features_t>,
348    enable: bool,
349) -> bool {
350    let features = match features {
351        Some(features) => features,
352        _ => return false,
353    };
354
355    features.inner.memory64(enable);
356
357    true
358}