|
9 | 9 |
|
10 | 10 | //! `tinywasm` provides a small, portable WebAssembly interpreter with support for |
11 | 11 | //! the WebAssembly MVP, WebAssembly 2.0, and a growing set of newer proposals. |
| 12 | +//! It also supports the [Lime1](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1) |
| 13 | +//! interoperability target. |
12 | 14 | //! It is designed to stay lightweight while still being practical to embed in |
13 | 15 | //! applications, tools, and `no_std + alloc` environments. |
14 | | -//! |
15 | | -//! ## Features |
16 | | -//! - **`std`**\ |
17 | | -//! Enables parsing from files and streams. Enabled by default. |
18 | | -//! - **`log`**\ |
19 | | -//! Enables integration with the `log` crate. Enabled by default. |
20 | | -//! - **`parser`**\ |
21 | | -//! Enables the bundled `tinywasm-parser` crate and top-level parse helpers. Enabled by default. |
22 | | -//! - **`archive`**\ |
23 | | -//! Enables serialization and deserialization of compiled modules in the internal `twasm` format. Enabled by default. |
24 | | -//! - **`canonicalize-nans`**\ |
25 | | -//! Canonicalizes NaN values to a single representation. Enabled by default. |
26 | | -//! - **`debug`**\ |
27 | | -//! Derives `Debug` for runtime types. Enabled by default. |
28 | | -//! - **`parallel-parser`**\ |
29 | | -//! Parallelizes function parsing and validation across threads when `std` is enabled. Enabled by default. |
30 | | -//! - **`guest-debug`**\ |
31 | | -//! Exposes module-internal by-index inspection APIs (`*_by_index`). |
32 | | -//! - **`simd-x86`**\ |
33 | | -//! Enables x86-specific SIMD intrinsics for selected operations and uses `unsafe` internally. |
34 | | -//! |
35 | | -//! With default features disabled, `tinywasm` only depends on `core`, `alloc`, and `libm`. |
36 | | -//! By disabling `std`, you can use `tinywasm` in `no_std` environments. This requires |
37 | | -//! a custom allocator and removes support for parsing from files and streams, but otherwise the API is the same. |
38 | 16 |
|
39 | 17 | #![cfg_attr(docsrs, feature(doc_cfg))] |
40 | 18 | //! |
41 | | -//! ## Getting Started |
42 | | -//! The easiest way to get started is to use the [`crate::parse_bytes`] function to load a |
| 19 | +//! ## Getting started |
| 20 | +//! |
| 21 | +//! The easiest way to get started is to use the `parse_bytes` function to load a |
43 | 22 | //! WebAssembly module from bytes. This will parse the module and validate it, returning |
44 | 23 | //! a [`Module`] that can be used to instantiate the module. |
45 | 24 | //! |
46 | | -//! |
47 | 25 | //! ```rust |
| 26 | +//! # #[cfg(feature = "parser")] |
| 27 | +//! # fn main() -> tinywasm::Result<()> { |
48 | 28 | //! use tinywasm::{ModuleInstance, Store}; |
49 | 29 | //! |
50 | 30 | //! // Load a module from bytes |
|
62 | 42 | //! |
63 | 43 | //! // # Get a typed handle to the exported "add" function |
64 | 44 | //! // Alternatively, you can use `instance.func_untyped` to get an untyped handle |
65 | | -//! // that takes and returns [`WasmValue`]s |
66 | | -//! let func = instance.func::<(i32, i32), i32>(&mut store, "add")?; |
| 45 | +//! // that takes and returns [`types::WasmValue`]s |
| 46 | +//! let func = instance.func::<(i32, i32), i32>(&store, "add")?; |
67 | 47 | //! let res = func.call(&mut store, (1, 2))?; |
68 | 48 | //! |
69 | 49 | //! assert_eq!(res, 3); |
70 | | -//! # Ok::<(), tinywasm::Error>(()) |
| 50 | +//! # Ok(()) |
| 51 | +//! # } |
| 52 | +//! # #[cfg(not(feature = "parser"))] |
| 53 | +//! # fn main() {} |
71 | 54 | //! ``` |
72 | 55 | //! |
73 | 56 | //! For non-default runtime behavior, construct a [`Store`] with a custom [`Engine`] |
|
76 | 59 | //! |
77 | 60 | //! For more examples, see the [`examples`](https://github.com/explodingcamera/tinywasm/tree/main/examples) directory. |
78 | 61 | //! |
| 62 | +//! ## Cargo features |
| 63 | +//! |
| 64 | +//! - **`std`:** Enables `std` and parsing from files and streams. Enabled by default. |
| 65 | +//! - **`log`:** Enables integration with the `log` crate. Enabled by default. |
| 66 | +//! - **`parser`:** Enables `tinywasm-parser` and top-level parse helpers. Enabled by default. |
| 67 | +//! - **`archive`:** Enables serialization and deserialization of the internal `twasm` format. Enabled by default. |
| 68 | +//! - **`canonicalize-nans`:** Canonicalizes NaN values. Enabled by default. |
| 69 | +//! - **`debug`:** Derives `Debug` for runtime types. Enabled by default. |
| 70 | +//! - **`parallel-parser`:** Parallelizes function parsing and validation when `std` is enabled. Enabled by default. |
| 71 | +//! - **`guest-debug`:** Exposes module-internal by-index inspection APIs (`*_by_index`). |
| 72 | +//! - **`simd-x86`:** Enables x86-specific SIMD intrinsics and uses `unsafe` internally. |
| 73 | +//! |
| 74 | +//! With default features disabled, `tinywasm` depends only on `core`, `alloc`, and `libm`, |
| 75 | +//! making it usable in `no_std + alloc` environments with a custom allocator. |
| 76 | +//! |
79 | 77 | //! ## Imports |
80 | 78 | //! |
81 | 79 | //! To provide imports to a module, you can use the [`Imports`] struct. |
|
0 commit comments