xref: /wasmtime-44.0.1/crates/wasmtime/src/lib.rs (revision 4a168844)
1 //! # Wasmtime's embedding API
2 //!
3 //! Wasmtime is a WebAssembly engine for JIT-compiled or ahead-of-time compiled
4 //! WebAssembly modules and components. More information about the Wasmtime
5 //! project as a whole can be found [in the documentation
6 //! book](https://docs.wasmtime.dev) whereas this documentation mostly focuses
7 //! on the API reference of the `wasmtime` crate itself.
8 //!
9 //! This crate contains an API used to interact with [WebAssembly modules] or
10 //! [WebAssembly components]. For example you can compile WebAssembly, create
11 //! instances, call functions, etc. As an embedder of WebAssembly you can also
12 //! provide guests functionality from the host by creating host-defined
13 //! functions, memories, globals, etc, which can do things that WebAssembly
14 //! cannot (such as print to the screen).
15 //!
16 //! [WebAssembly modules]: https://webassembly.github.io/spec
17 //! [WebAssembly components]: https://component-model.bytecodealliance.org
18 //!
19 //! The `wasmtime` crate is designed to be safe, efficient, and ergonomic.
20 //! This enables executing WebAssembly without the embedder needing to use
21 //! `unsafe` code, meaning that you're guaranteed there is no undefined behavior
22 //! or segfaults in either the WebAssembly guest or the host itself.
23 //!
24 //! The `wasmtime` crate can roughly be thought of as being split into two
25 //! halves:
26 //!
27 //! * One half of the crate is similar to the [JS WebAssembly
28 //!   API](https://developer.mozilla.org/en-US/docs/WebAssembly) as well as the
29 //!   [proposed C API](https://github.com/webassembly/wasm-c-api) and is
30 //!   intended for working with [WebAssembly modules]. This API resides in the
31 //!   root of the `wasmtime` crate's namespace, for example
32 //!   [`wasmtime::Module`](`Module`).
33 //!
34 //! * The second half of the crate is for use with the [WebAssembly Component
35 //!   Model]. The implementation of the component model is present in
36 //!   [`wasmtime::component`](`component`) and roughly mirrors the structure for
37 //!   core WebAssembly, for example [`component::Func`] mirrors [`Func`].
38 //!
39 //! [WebAssembly Component Model]: https://component-model.bytecodealliance.org
40 //!
41 //! An example of using Wasmtime to run a core WebAssembly module looks like:
42 //!
43 //! ```
44 //! use wasmtime::*;
45 //!
46 //! fn main() -> wasmtime::Result<()> {
47 //!     let engine = Engine::default();
48 //!
49 //!     // Modules can be compiled through either the text or binary format
50 //!     let wat = r#"
51 //!         (module
52 //!             (import "host" "host_func" (func $host_hello (param i32)))
53 //!
54 //!             (func (export "hello")
55 //!                 i32.const 3
56 //!                 call $host_hello)
57 //!         )
58 //!     "#;
59 //!     let module = Module::new(&engine, wat)?;
60 //!
61 //!     // Host functionality can be arbitrary Rust functions and is provided
62 //!     // to guests through a `Linker`.
63 //!     let mut linker = Linker::new(&engine);
64 //!     linker.func_wrap("host", "host_func", |caller: Caller<'_, u32>, param: i32| {
65 //!         println!("Got {} from WebAssembly", param);
66 //!         println!("my host state is: {}", caller.data());
67 //!     })?;
68 //!
69 //!     // All wasm objects operate within the context of a "store". Each
70 //!     // `Store` has a type parameter to store host-specific data, which in
71 //!     // this case we're using `4` for.
72 //!     let mut store: Store<u32> = Store::new(&engine, 4);
73 //!
74 //!     // Instantiation of a module requires specifying its imports and then
75 //!     // afterwards we can fetch exports by name, as well as asserting the
76 //!     // type signature of the function with `get_typed_func`.
77 //!     let instance = linker.instantiate(&mut store, &module)?;
78 //!     let hello = instance.get_typed_func::<(), ()>(&mut store, "hello")?;
79 //!
80 //!     // And finally we can call the wasm!
81 //!     hello.call(&mut store, ())?;
82 //!
83 //!     Ok(())
84 //! }
85 //! ```
86 //!
87 //! ## Core Concepts
88 //!
89 //! There are a number of core types and concepts that are important to be aware
90 //! of when using the `wasmtime` crate:
91 //!
92 //! * [`Engine`] - a global compilation and runtime environment for WebAssembly.
93 //!   An [`Engine`] is an object that can be shared concurrently across threads
94 //!   and is created with a [`Config`] with many knobs for configuring
95 //!   behavior. Compiling or executing any WebAssembly requires first
96 //!   configuring and creating an [`Engine`]. All [`Module`]s and
97 //!   [`Component`](component::Component)s belong to an [`Engine`], and
98 //!   typically there's one [`Engine`] per process.
99 //!
100 //! * [`Store`] - container for all information related to WebAssembly objects
101 //!   such as functions, instances, memories, etc. A [`Store<T>`][`Store`]
102 //!   allows customization of the `T` to store arbitrary host data within a
103 //!   [`Store`]. This host data can be accessed through host functions via the
104 //!   [`Caller`] function parameter in host-defined functions. A [`Store`] is
105 //!   required for all WebAssembly operations, such as calling a wasm function.
106 //!   The [`Store`] is passed in as a "context" to methods like [`Func::call`].
107 //!   Dropping a [`Store`] will deallocate all memory associated with
108 //!   WebAssembly objects within the [`Store`]. A [`Store`] is cheap to create
109 //!   and destroy and does not GC objects such as unused instances internally,
110 //!   so it's intended to be short-lived (or no longer than the instances it
111 //!   contains).
112 //!
113 //! * [`Linker`] (or [`component::Linker`]) - host functions are defined within
114 //!   a linker to provide them a string-based name which can be looked up when
115 //!   instantiating a WebAssembly module or component. Linkers are traditionally
116 //!   populated at startup and then reused for all future instantiations of all
117 //!   instances, assuming the set of host functions does not change over time.
118 //!   Host functions are `Fn(..) + Send + Sync` and typically do not close over
119 //!   mutable state. Instead it's recommended to store mutable state in the `T`
120 //!   of [`Store<T>`] which is accessed through [`Caller<'_,
121 //!   T>`](crate::Caller) provided to host functions.
122 //!
123 //! * [`Module`] (or [`Component`](component::Component)) - a compiled
124 //!   WebAssembly module or component. These structures contain compiled
125 //!   executable code from a WebAssembly binary which is ready to execute after
126 //!   being instantiated. These are expensive to create as they require
127 //!   compilation of the input WebAssembly. Modules and components are safe to
128 //!   share across threads, however. Modules and components can additionally be
129 //!   [serialized into a list of bytes](crate::Module::serialize) to later be
130 //!   [deserialized](crate::Module::deserialize) quickly. This enables JIT-style
131 //!   compilation through constructors such as [`Module::new`] and AOT-style
132 //!   compilation by having the compilation process use [`Module::serialize`]
133 //!   and the execution process use [`Module::deserialize`].
134 //!
135 //! * [`Instance`] (or [`component::Instance`]) - an instantiated WebAssembly
136 //!   module or component. An instance is where you can actually acquire a
137 //!   [`Func`] (or [`component::Func`]) from, for example, to call.
138 //!
139 //! * [`Func`] (or [`component::Func`]) - a WebAssembly function. This can be
140 //!   acquired as the export of an [`Instance`] to call WebAssembly functions,
141 //!   or it can be created via functions like [`Func::wrap`] to wrap
142 //!   host-defined functionality and give it to WebAssembly. Functions also have
143 //!   typed views as [`TypedFunc`] or [`component::TypedFunc`] for a more
144 //!   efficient calling convention.
145 //!
146 //! * [`Table`], [`Global`], [`Memory`], [`component::Resource`] - other
147 //!   WebAssembly objects which can either be defined on the host or in wasm
148 //!   itself (via instances). These all have various ways of being interacted
149 //!   with like [`Func`].
150 //!
151 //! All "store-connected" types such as [`Func`], [`Memory`], etc, require the
152 //! store to be passed in as a context to each method. Methods in wasmtime
153 //! frequently have their first parameter as either [`impl
154 //! AsContext`][`AsContext`] or [`impl AsContextMut`][`AsContextMut`]. These
155 //! traits are implemented for a variety of types, allowing you to, for example,
156 //! pass the following types into methods:
157 //!
158 //! * `&Store<T>`
159 //! * `&mut Store<T>`
160 //! * `&Caller<'_, T>`
161 //! * `&mut Caller<'_, T>`
162 //! * `StoreContext<'_, T>`
163 //! * `StoreContextMut<'_, T>`
164 //!
165 //! A [`Store`] is the sole owner of all WebAssembly internals. Types like
166 //! [`Func`] point within the [`Store`] and require the [`Store`] to be provided
167 //! to actually access the internals of the WebAssembly function, for instance.
168 //!
169 //! ## WASI
170 //!
171 //! The `wasmtime` crate does not natively provide support for WASI, but you can
172 //! use the [`wasmtime-wasi`] crate for that purpose. With [`wasmtime-wasi`] all
173 //! WASI functions can be added to a [`Linker`] and then used to instantiate
174 //! WASI-using modules. For more information see the [WASI example in the
175 //! documentation](https://docs.wasmtime.dev/examples-rust-wasi.html).
176 //!
177 //! [`wasmtime-wasi`]: https://crates.io/crates/wasmtime-wasi
178 //!
179 //! ## Async
180 //!
181 //! Wasmtime supports executing WebAssembly guests through Rust-level `async`
182 //! functions. This enables Wasmtime to block the guest without blocking the
183 //! host, interrupt infinite loops or long-running CPU-bound guests, and
184 //! integrate with Rust host functions that are themselves `async`.
185 //!
186 //! Many functions in the embedding API have a sync variant and an async
187 //! variant, for example [`Func::call`] and [`Func::call_async`]. Embedders
188 //! may decide which is most appropriate for their use case, but if certain
189 //! features of Wasmtime are configured then `*_async` variants of functions are
190 //! required. If any of these features are used, for example, then `*_async`
191 //! must be used:
192 //!
193 //! * Async core wasm host functions, for example via [`Linker::func_wrap_async`]
194 //! * Async component host functions, for example via [`component::LinkerInstance::func_wrap_async`]
195 //! * Async resource limiters, via [`Store::limiter_async`]
196 //! * Async yields with fuel via [`Store::fuel_async_yield_interval`]
197 //! * Async yields via epochs via [`Store::epoch_deadline_async_yield_and_update`]
198 //!
199 //! This is not an exhaustive list, but if any of these configurations/APIs are
200 //! used then all `*_async` APIs must be used in Wasmtime. If synchronous APIs
201 //! are used instead they will return an error.
202 //!
203 //! #### Asynchronous Wasm
204 //!
205 //! Core WebAssembly and synchronous WIT functions (e.g. WASIp2-and-prior)
206 //! require that all imported functions appear synchronous from the perspective
207 //! of the guest. Host functions which perform I/O and block, however, are often
208 //! defined with `async` in Rust. Wasmtime's async support bridges this gap with
209 //! asynchronous wasm execution.
210 //!
211 //! When using `*_async` APIs to execute WebAssembly Wasmtime will always
212 //! represent its computation as a [`Future`]. The `poll` method of the futures
213 //! returned by Wasmtime will perform the actual work of calling the
214 //! WebAssembly. Wasmtime won't manage its own thread pools or similar, that's
215 //! left up to the embedder.
216 //!
217 //! To implement futures in a way that WebAssembly sees asynchronous host
218 //! functions as synchronous, all async Wasmtime futures will execute on a
219 //! separately allocated native stack from the thread otherwise executing
220 //! Wasmtime. This separate native stack can then be switched to and from.
221 //! Using this whenever an `async` host function returns a future that
222 //! resolves to `Pending` we switch away from the temporary stack back to
223 //! the main stack and propagate the `Pending` status.
224 //!
225 //! #### Execution in `poll`
226 //!
227 //! The [`Future::poll`] method is the main driving force behind Rust's futures.
228 //! That method's own documentation states "an implementation of `poll` should
229 //! strive to return quickly, and should not block". This, however, can be at
230 //! odds with executing WebAssembly code as part of the `poll` method itself. If
231 //! your WebAssembly is untrusted then this could allow the `poll` method to
232 //! take arbitrarily long in the worst case, likely blocking all other
233 //! asynchronous tasks.
234 //!
235 //! To remedy this situation you have a few possible ways to solve this:
236 //!
237 //! * The most efficient solution is to enable
238 //!   [`Config::epoch_interruption`] in conjunction with
239 //!   [`crate::Store::epoch_deadline_async_yield_and_update`]. Coupled with
240 //!   periodic calls to [`crate::Engine::increment_epoch`] this will cause
241 //!   executing WebAssembly to periodically yield back according to the
242 //!   epoch configuration settings. This enables [`Future::poll`] to take at
243 //!   most a certain amount of time according to epoch configuration
244 //!   settings and when increments happen. The benefit of this approach is
245 //!   that the instrumentation in compiled code is quite lightweight, but a
246 //!   downside can be that the scheduling is somewhat nondeterministic since
247 //!   increments are usually timer-based which are not always deterministic.
248 //!
249 //!   Note that to prevent infinite execution of wasm it's recommended to
250 //!   place a timeout on the entire future representing executing wasm code
251 //!   and the periodic yields with epochs should ensure that when the
252 //!   timeout is reached it's appropriately recognized.
253 //!
254 //! * Alternatively you can enable the
255 //!   [`Config::consume_fuel`](crate::Config::consume_fuel) method as well
256 //!   as [`crate::Store::fuel_async_yield_interval`] When doing so this will
257 //!   configure Wasmtime futures to yield periodically while they're
258 //!   executing WebAssembly code. After consuming the specified amount of
259 //!   fuel wasm futures will return `Poll::Pending` from their `poll`
260 //!   method, and will get automatically re-polled later. This enables the
261 //!   `Future::poll` method to take roughly a fixed amount of time since
262 //!   fuel is guaranteed to get consumed while wasm is executing. Unlike
263 //!   epoch-based preemption this is deterministic since wasm always
264 //!   consumes a fixed amount of fuel per-operation. The downside of this
265 //!   approach, however, is that the compiled code instrumentation is
266 //!   significantly more expensive than epoch checks.
267 //!
268 //!   Note that to prevent infinite execution of wasm it's recommended to
269 //!   place a timeout on the entire future representing executing wasm code
270 //!   and the periodic yields with epochs should ensure that when the
271 //!   timeout is reached it's appropriately recognized.
272 //!
273 //! In all cases special care needs to be taken when integrating
274 //! asynchronous wasm into your application. You should carefully plan where
275 //! WebAssembly will execute and what compute resources will be allotted to
276 //! it. If Wasmtime doesn't support exactly what you'd like just yet, please
277 //! feel free to open an issue!
278 //!
279 //! ## Crate Features
280 //!
281 //! The `wasmtime` crate comes with a number of compile-time features that can
282 //! be used to customize what features it supports. Some of these features are
283 //! just internal details, but some affect the public API of the `wasmtime`
284 //! crate. Wasmtime APIs gated behind a Cargo feature should be indicated as
285 //! such in the documentation.
286 //!
287 //! * `runtime` - Enabled by default, this feature enables executing
288 //!   WebAssembly modules and components. If a compiler is not available (such
289 //!   as `cranelift`) then [`Module::deserialize`] must be used, for example, to
290 //!   provide an ahead-of-time compiled artifact to execute WebAssembly.
291 //!
292 //! * `cranelift` - Enabled by default, this features enables using Cranelift at
293 //!   runtime to compile a WebAssembly module to native code. This feature is
294 //!   required to process and compile new WebAssembly modules and components.
295 //!
296 //! * `cache` - Enabled by default, this feature adds support for wasmtime to
297 //!   perform internal caching of modules in a global location. This must still
298 //!   be enabled explicitly through [`Config::cache`].
299 //!
300 //! * `wat` - Enabled by default, this feature adds support for accepting the
301 //!   text format of WebAssembly in [`Module::new`] and
302 //!   [`Component::new`](component::Component::new). The text format will be
303 //!   automatically recognized and translated to binary when compiling a
304 //!   module.
305 //!
306 //! * `parallel-compilation` - Enabled by default, this feature enables support
307 //!   for compiling functions in parallel with `rayon`.
308 //!
309 //! * `async` - Enabled by default, this feature enables APIs and runtime
310 //!   support for defining asynchronous host functions and calling WebAssembly
311 //!   asynchronously. For more information see [async documentation](#async)
312 //!
313 //! * `profiling` - Enabled by default, this feature compiles in support for
314 //!   profiling guest code via a number of possible strategies. See
315 //!   [`Config::profiler`] for more information.
316 //!
317 //! * `all-arch` - Not enabled by default. This feature compiles in support for
318 //!   all architectures for both the JIT compiler and the `wasmtime compile` CLI
319 //!   command. This can be combined with [`Config::target`] to precompile
320 //!   modules for a different platform than the host.
321 //!
322 //! * `pooling-allocator` - Enabled by default, this feature adds support for
323 //!   [`PoolingAllocationConfig`] to pass to [`Config::allocation_strategy`].
324 //!   The pooling allocator can enable efficient reuse of resources for
325 //!   high-concurrency and high-instantiation-count scenarios.
326 //!
327 //! * `demangle` - Enabled by default, this will affect how backtraces are
328 //!   printed and whether symbol names from WebAssembly are attempted to be
329 //!   demangled. Rust and C++ demanglings are currently supported.
330 //!
331 //! * `coredump` - Enabled by default, this will provide support for generating
332 //!   a core dump when a trap happens. This can be configured via
333 //!   [`Config::coredump_on_trap`].
334 //!
335 //! * `addr2line` - Enabled by default, this feature configures whether traps
336 //!   will attempt to parse DWARF debug information and convert WebAssembly
337 //!   addresses to source filenames and line numbers.
338 //!
339 //! * `debug-builtins` - Enabled by default, this feature includes some built-in
340 //!   debugging utilities and symbols for native debuggers such as GDB and LLDB
341 //!   to attach to the process Wasmtime is used within. The intrinsics provided
342 //!   will enable debugging guest code compiled to WebAssembly. This must also
343 //!   be enabled via [`Config::debug_info`] as well for guests.
344 //!
345 //! * `component-model` - Enabled by default, this enables support for the
346 //!   [`wasmtime::component`](component) API for working with components.
347 //!
348 //! * `gc` - Enabled by default, this enables support for a number of
349 //!   WebAssembly proposals such as `reference-types`, `function-references`,
350 //!   and `gc`. Note that the implementation of the `gc` proposal itself is not
351 //!   yet complete at this time.
352 //!
353 //! * `threads` - Enabled by default, this enables compile-time support for the
354 //!   WebAssembly `threads` proposal, notably shared memories.
355 //!
356 //! * `call-hook` - Disabled by default, this enables support for the
357 //!   [`Store::call_hook`] API. This incurs a small overhead on all
358 //!   entries/exits from WebAssembly and may want to be disabled by some
359 //!   embedders.
360 //!
361 //! * `memory-protection-keys` - Disabled by default, this enables support for
362 //!   the [`PoolingAllocationConfig::memory_protection_keys`] API. This feature
363 //!   currently only works on x64 Linux and can enable compacting the virtual
364 //!   memory allocation for linear memories in the pooling allocator. This comes
365 //!   with the same overhead as the `call-hook` feature where entries/exits into
366 //!   WebAssembly will have more overhead than before.
367 //!
368 //! More crate features can be found in the [manifest] of Wasmtime itself for
369 //! seeing what can be enabled and disabled.
370 //!
371 //! [manifest]: https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/Cargo.toml
372 
373 #![deny(missing_docs)]
374 #![doc(test(attr(deny(warnings))))]
375 #![doc(test(attr(allow(dead_code, unused_variables, unused_mut))))]
376 #![cfg_attr(docsrs, feature(doc_cfg))]
377 // NB: this list is currently being burned down to remove all features listed
378 // here to get warnings in all configurations of Wasmtime.
379 #![cfg_attr(
380     any(not(feature = "runtime"), not(feature = "std")),
381     expect(dead_code, unused_imports, reason = "list not burned down yet")
382 )]
383 // Allow broken links when the default features is disabled because most of our
384 // documentation is written for the "one build" of the `main` branch which has
385 // most features enabled. This will present warnings in stripped-down doc builds
386 // and will prevent the doc build from failing.
387 #![cfg_attr(feature = "default", warn(rustdoc::broken_intra_doc_links))]
388 #![no_std]
389 // Wasmtime liberally uses #[cfg]'d definitions of structures to uninhabited
390 // types to reduce the total amount of #[cfg], but rustc warns that much usage
391 // of these structures, rightfully, leads to unreachable code. This unreachable
392 // code is only conditional, however, so it's generally just annoying to deal
393 // with. Disable the `unreachable_code` lint in situations like this when some
394 // major features are disabled. If all the features are enabled, though, we
395 // still want to get warned about this.
396 #![cfg_attr(
397     any(not(feature = "threads"), not(feature = "gc",)),
398     allow(unreachable_code, reason = "see comment")
399 )]
400 
401 #[cfg(feature = "std")]
402 #[macro_use]
403 extern crate std;
404 extern crate alloc;
405 
406 // Internal `use` statement which isn't used in this module but enable
407 // `use crate::prelude::*;` everywhere else within this crate, for example.
408 use wasmtime_environ::prelude;
409 
410 // FIXME(#12069) should transition to OOM-handling versions of these collections
411 // for all internal usage instead of using abort-on-OOM versions. Once that's
412 // done this can be removed and the collections should be directly imported from
413 // `wasmtime_environ::collections::*`.
414 #[allow(
415     unused_imports,
416     reason = "not all build configs use these; easier to allow than to precisely `cfg`"
417 )]
418 use wasmtime_environ::collections::oom_abort::{hash_map, hash_set};
419 
420 /// A helper macro to safely map `MaybeUninit<T>` to `MaybeUninit<U>` where `U`
421 /// is a field projection within `T`.
422 ///
423 /// This is intended to be invoked as:
424 ///
425 /// ```ignore
426 /// struct MyType {
427 ///     field: u32,
428 /// }
429 ///
430 /// let initial: &mut MaybeUninit<MyType> = ...;
431 /// let field: &mut MaybeUninit<u32> = map_maybe_uninit!(initial.field);
432 /// ```
433 ///
434 /// Note that array accesses are also supported:
435 ///
436 /// ```ignore
437 ///
438 /// let initial: &mut MaybeUninit<[u32; 2]> = ...;
439 /// let element: &mut MaybeUninit<u32> = map_maybe_uninit!(initial[1]);
440 /// ```
441 #[doc(hidden)]
442 #[macro_export]
443 macro_rules! map_maybe_uninit {
444     ($maybe_uninit:ident $($field:tt)*) => ({
445         #[allow(unused_unsafe, reason = "macro-generated code")]
446         {
447             unsafe {
448                 use $crate::MaybeUninitExt;
449 
450                 let m: &mut core::mem::MaybeUninit<_> = $maybe_uninit;
451                 // Note the usage of `&raw` here which is an attempt to "stay
452                 // safe" here where we never accidentally create `&mut T` where `T` is
453                 // actually uninitialized, hopefully appeasing the Rust unsafe
454                 // guidelines gods.
455                 m.map(|p| &raw mut (*p)$($field)*)
456             }
457         }
458     })
459 }
460 
461 #[doc(hidden)]
462 pub trait MaybeUninitExt<T> {
463     /// Maps `MaybeUninit<T>` to `MaybeUninit<U>` using the closure provided.
464     ///
465     /// # Safety
466     ///
467     /// Requires that `*mut U` is a field projection from `*mut T`. Use
468     /// `map_maybe_uninit!` above instead.
map<U>(&mut self, f: impl FnOnce(*mut T) -> *mut U) -> &mut core::mem::MaybeUninit<U>469     unsafe fn map<U>(&mut self, f: impl FnOnce(*mut T) -> *mut U)
470     -> &mut core::mem::MaybeUninit<U>;
471 }
472 
473 impl<T> MaybeUninitExt<T> for core::mem::MaybeUninit<T> {
map<U>( &mut self, f: impl FnOnce(*mut T) -> *mut U, ) -> &mut core::mem::MaybeUninit<U>474     unsafe fn map<U>(
475         &mut self,
476         f: impl FnOnce(*mut T) -> *mut U,
477     ) -> &mut core::mem::MaybeUninit<U> {
478         let new_ptr = f(self.as_mut_ptr());
479         // SAFETY: the memory layout of these two types are the same, and
480         // asserting that it's a safe reference with the same lifetime as `self`
481         // is a requirement of this function itself.
482         unsafe { core::mem::transmute::<*mut U, &mut core::mem::MaybeUninit<U>>(new_ptr) }
483     }
484 }
485 
486 #[cfg(feature = "runtime")]
487 mod runtime;
488 #[cfg(feature = "runtime")]
489 pub use runtime::*;
490 
491 #[cfg(any(feature = "cranelift", feature = "winch"))]
492 mod compile;
493 #[cfg(any(feature = "cranelift", feature = "winch"))]
494 pub use compile::{CodeBuilder, CodeHint};
495 
496 mod config;
497 mod engine;
498 mod profiling_agent;
499 
500 pub use crate::config::*;
501 pub use crate::engine::*;
502 
503 #[cfg(feature = "std")]
504 mod sync_std;
505 #[cfg(feature = "std")]
506 use sync_std as sync;
507 
508 mod sync_nostd;
509 #[cfg(not(feature = "std"))]
510 use sync_nostd as sync;
511 
512 pub use wasmtime_environ::OperatorCost;
513 pub use wasmtime_environ::ToWasmtimeResult;
514 #[doc(inline)]
515 pub use wasmtime_environ::error;
516 
517 // Only for use in `bindgen!`-generated code.
518 #[doc(hidden)]
519 #[cfg(feature = "anyhow")]
520 pub use wasmtime_environ::anyhow;
521 
522 pub use self::error::{Error, Result, bail, ensure, format_err};
523 
524 /// A re-exported instance of Wasmtime's `wasmparser` dependency.
525 ///
526 /// This may be useful for embedders that also use `wasmparser`
527 /// directly: it allows embedders to ensure that they are using the same
528 /// version as Wasmtime, both to eliminate redundant dependencies on
529 /// multiple versions of the library, and to ensure compatibility in
530 /// validation and feature support.
531 ///
532 /// Note that this re-export is *not subject to semver*: we reserve the
533 /// right to make patch releases of Wasmtime that bump the version of
534 /// wasmparser used, and hence the version re-exported, in
535 /// semver-incompatible ways. This is the tradeoff that the embedder
536 /// needs to opt into: in order to stay exactly in sync with an internal
537 /// detail of Wasmtime, the cost is visibility into potential internal
538 /// version changes.
539 #[cfg(feature = "reexport-wasmparser")]
540 pub use wasmparser;
541 
_assert_send_and_sync<T: Send + Sync>()542 fn _assert_send_and_sync<T: Send + Sync>() {}
543 
_assertions_lib()544 fn _assertions_lib() {
545     _assert_send_and_sync::<Engine>();
546     _assert_send_and_sync::<Config>();
547 }
548 
549 #[cfg(feature = "runtime")]
550 #[doc(hidden)]
551 pub mod _internal {
552     // Exported just for the CLI.
553     pub use crate::runtime::vm::MmapVec;
554 }
555