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 de 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 not currently
106/// fully standardized and is undergoing development. Support for this
107/// feature can be enabled through this method for appropriate WebAssembly
108/// modules.
109///
110/// This feature gates items such as the `externref` type and multiple tables
111/// being in a module. Note that enabling the reference types feature will
112/// also enable the bulk memory feature.
113///
114/// This is `false` by default.
115///
116/// [proposal]: https://github.com/webassembly/reference-types
117///
118/// # Example
119///
120/// See the module's documentation.
121#[unsafe(no_mangle)]
122pub extern "C" fn wasmer_features_reference_types(
123 features: Option<&mut wasmer_features_t>,
124 enable: bool,
125) -> bool {
126 let features = match features {
127 Some(features) => features,
128 _ => return false,
129 };
130
131 features.inner.reference_types(enable);
132
133 true
134}
135
136/// Configures whether the WebAssembly SIMD proposal will be
137/// enabled.
138///
139/// The [WebAssembly SIMD proposal][proposal] is not currently
140/// fully standardized and is undergoing development. Support for this
141/// feature can be enabled through this method for appropriate WebAssembly
142/// modules.
143///
144/// This feature gates items such as the `v128` type and all of its
145/// operators being in a module.
146///
147/// This is `false` by default.
148///
149/// [proposal]: https://github.com/webassembly/simd
150///
151/// # Example
152///
153/// See the module's documentation.
154#[unsafe(no_mangle)]
155pub extern "C" fn wasmer_features_simd(
156 features: Option<&mut wasmer_features_t>,
157 enable: bool,
158) -> bool {
159 let features = match features {
160 Some(features) => features,
161 _ => return false,
162 };
163
164 features.inner.simd(enable);
165
166 true
167}
168
169/// Configures whether the WebAssembly bulk memory operations proposal will
170/// be enabled.
171///
172/// The [WebAssembly bulk memory operations proposal][proposal] is not
173/// currently fully standardized and is undergoing development.
174/// Support for this feature can be enabled through this method for
175/// appropriate WebAssembly modules.
176///
177/// This feature gates items such as the `memory.copy` instruction, passive
178/// data/table segments, etc, being in a module.
179///
180/// This is `false` by default.
181///
182/// [proposal]: https://github.com/webassembly/bulk-memory-operations
183///
184/// # Example
185///
186/// See the module's documentation.
187#[unsafe(no_mangle)]
188pub extern "C" fn wasmer_features_bulk_memory(
189 features: Option<&mut wasmer_features_t>,
190 enable: bool,
191) -> bool {
192 let features = match features {
193 Some(features) => features,
194 _ => return false,
195 };
196
197 features.inner.bulk_memory(enable);
198
199 true
200}
201
202/// Configures whether the WebAssembly multi-value proposal will
203/// be enabled.
204///
205/// The [WebAssembly multi-value proposal][proposal] is not
206/// currently fully standardized and is undergoing development.
207/// Support for this feature can be enabled through this method for
208/// appropriate WebAssembly modules.
209///
210/// This feature gates functions and blocks returning multiple values in a
211/// module, for example.
212///
213/// This is `false` by default.
214///
215/// [proposal]: https://github.com/webassembly/multi-value
216///
217/// # Example
218///
219/// See the module's documentation.
220#[unsafe(no_mangle)]
221pub extern "C" fn wasmer_features_multi_value(
222 features: Option<&mut wasmer_features_t>,
223 enable: bool,
224) -> bool {
225 let features = match features {
226 Some(features) => features,
227 _ => return false,
228 };
229
230 features.inner.multi_value(enable);
231
232 true
233}
234
235/// Configures whether the WebAssembly tail-call proposal will
236/// be enabled.
237///
238/// The [WebAssembly tail-call proposal][proposal] is not
239/// currently fully standardized and is undergoing development.
240/// Support for this feature can be enabled through this method for
241/// appropriate WebAssembly modules.
242///
243/// This feature gates tail-call functions in WebAssembly.
244///
245/// This is `false` by default.
246///
247/// [proposal]: https://github.com/webassembly/tail-call
248///
249/// # Example
250///
251/// See the module's documentation.
252#[unsafe(no_mangle)]
253pub extern "C" fn wasmer_features_tail_call(
254 features: Option<&mut wasmer_features_t>,
255 enable: bool,
256) -> bool {
257 let features = match features {
258 Some(features) => features,
259 _ => return false,
260 };
261
262 features.inner.tail_call(enable);
263
264 true
265}
266
267/// Configures whether the WebAssembly tail-call proposal will
268/// be enabled.
269///
270/// The [WebAssembly tail-call proposal][proposal] is not
271/// currently fully standardized and is undergoing development.
272/// Support for this feature can be enabled through this method for
273/// appropriate WebAssembly modules.
274///
275/// This feature allows WebAssembly modules to define, import and
276/// export modules and instances.
277///
278/// This is `false` by default.
279///
280/// [proposal]: https://github.com/webassembly/module-linking
281///
282/// # Example
283///
284/// See the module's documentation.
285#[unsafe(no_mangle)]
286pub extern "C" fn wasmer_features_module_linking(
287 features: Option<&mut wasmer_features_t>,
288 enable: bool,
289) -> bool {
290 let features = match features {
291 Some(features) => features,
292 _ => return false,
293 };
294
295 features.inner.module_linking(enable);
296
297 true
298}
299
300/// Configures whether the WebAssembly multi-memory proposal will
301/// be enabled.
302///
303/// The [WebAssembly multi-memory proposal][proposal] is not
304/// currently fully standardized and is undergoing development.
305/// Support for this feature can be enabled through this method for
306/// appropriate WebAssembly modules.
307///
308/// This feature adds the ability to use multiple memories within a
309/// single Wasm module.
310///
311/// This is `false` by default.
312///
313/// [proposal]: https://github.com/WebAssembly/multi-memory
314///
315/// # Example
316///
317/// See the module's documentation.
318#[unsafe(no_mangle)]
319pub extern "C" fn wasmer_features_multi_memory(
320 features: Option<&mut wasmer_features_t>,
321 enable: bool,
322) -> bool {
323 let features = match features {
324 Some(features) => features,
325 _ => return false,
326 };
327
328 features.inner.multi_memory(enable);
329
330 true
331}
332
333/// Configures whether the WebAssembly 64-bit memory proposal will
334/// be enabled.
335///
336/// The [WebAssembly 64-bit memory proposal][proposal] is not
337/// currently fully standardized and is undergoing development.
338/// Support for this feature can be enabled through this method for
339/// appropriate WebAssembly modules.
340///
341/// This feature gates support for linear memory of sizes larger than
342/// 2^32 bits.
343///
344/// This is `false` by default.
345///
346/// [proposal]: https://github.com/WebAssembly/memory64
347///
348/// # Example
349///
350/// See the module's documentation.
351#[unsafe(no_mangle)]
352pub extern "C" fn wasmer_features_memory64(
353 features: Option<&mut wasmer_features_t>,
354 enable: bool,
355) -> bool {
356 let features = match features {
357 Some(features) => features,
358 _ => return false,
359 };
360
361 features.inner.memory64(enable);
362
363 true
364}