4
4
<strong >A <a href =" https://bytecodealliance.org/ " >Bytecode Alliance</a > project</strong >
5
5
6
6
<p >
7
- <strong>Rust tooling for low-level manipulation of WebAssembly modules</strong>
7
+ <strong>CLI and Rust libraries for low-level manipulation of WebAssembly modules</strong>
8
8
</p >
9
9
</div >
10
10
11
11
# Installation
12
12
13
- This project can be installed and compiled from source with this Cargo command:
13
+ [ Precompiled artifacts built on CI] [ artifacts ] are available for download for
14
+ each release.
15
+
16
+ If you'd prefer to build from source then first [ install Rust for your
17
+ platform] ( https://www.rust-lang.org/tools/install ) and then use the included
18
+ Cargo package manager to install:
14
19
15
20
```
16
21
$ cargo install wasm-tools
17
22
```
18
23
19
- Additionally there are [ precompiled artifacts built on CI] [ artifacts ] which are
20
- available for download as well.
21
-
22
24
[ artifacts ] : https://github.com/bytecodealliance/wasm-tools/releases
23
25
24
26
Installation can be confirmed with:
@@ -33,18 +35,99 @@ Subcommands can be explored with:
33
35
$ wasm-tools help
34
36
```
35
37
38
+ # Examples
39
+
40
+ Basic validation/printing:
41
+
42
+ ``` sh
43
+ # Validate a WebAssembly file
44
+ $ wasm-tools validate foo.wasm
45
+
46
+ # Validate a WebAssembly module in the text format, automatically converting to
47
+ # binary.
48
+ $ wasm-tools validate foo.wat
49
+
50
+ # Validate a WebAssembly file enabling an off-by-default feature
51
+ $ wasm-tools validate foo.wasm --features=exception-handling
52
+
53
+ # Validate a WebAssembly file with a default-enabled feature disabled
54
+ $ wasm-tools validate foo.wasm --features=-simd
55
+
56
+ # Print the text format of a module to stdout
57
+ $ wasm-tools print foo.wasm
58
+
59
+ # Convert a binary module to text
60
+ $ wasm-tools print foo.wasm -o foo.wat
61
+ ```
62
+
63
+ Simple mutation as well as piping commands together:
64
+
65
+ ``` sh
66
+ # Mutate a WebAssembly module and print its text representation to stdout
67
+ $ wasm-tools mutate foo.wasm -t
68
+
69
+ # Mutate a WebAssembly module with a non-default seed and validate that the
70
+ # output is a valid module.
71
+ $ wasm-tools mutate foo.wasm --seed 192 | wasm-tools validate
72
+
73
+ # Demangle Rust/C++ symbol names in the `name` section, strip all other custom
74
+ # sections, and then print out what binary sections remain.
75
+ $ wasm-tools demangle foo.wasm | wasm-tools strip | wasm-tools objdump
76
+ ```
77
+
78
+ Working with components:
79
+
80
+ ``` sh
81
+ # Print the WIT interface of a component
82
+ $ wasm-tools component wit component.wasm
83
+
84
+ # Convert WIT text files to a binary-encoded WIT package, printing the result to
85
+ # stdout
86
+ $ wasm-tools component wit ./wit -t
87
+
88
+ # Convert a WIT document to JSON
89
+ $ wasm-tools component wit ./wit --json
90
+
91
+ # Round trip WIT through the binary-encoded format to stdout.
92
+ $ wasm-tools component wit ./wit --wasm | wasm-tools component wit
93
+
94
+ # Convert a core WebAssembly binary into a component. Note that this requires
95
+ # WIT metadata having previously been embedded in the core wasm module.
96
+ $ wasm-tools component new my-core.wasm -o my-component.wasm
97
+
98
+ # Convert a core WebAssembly binary which uses WASI to a component.
99
+ $ wasm-tools component new my-core.wasm -o my-component.wasm --adapt wasi_snapshot_preview1.reactor.wasm
100
+ ```
101
+
102
+ ### CLI Conventions
103
+
104
+ There are a few conventions that all CLI commands adhere to:
105
+
106
+ * All subcommands print "short help" with ` -h ` and "long help" with ` --help ` .
107
+ * Input is by default read from stdin if no file input is specified (when
108
+ applicable).
109
+ * Output is by default sent to stdout if a ` -o ` or ` --output ` flag is not
110
+ provided. Binary WebAssembly is not printed to a tty by default, however.
111
+ * Commands which output WebAssembly binaries all support a ` -t ` or ` --wat ` flag
112
+ to generate the WebAssembly text format instead.
113
+ * A ` -v ` or ` --verbose ` flag can be passed to enable log messages throughout the
114
+ tooling. Verbosity can be turned up by passing the flag multiple times such as
115
+ ` -vvv ` .
116
+ * Color in error messages and console output is enabled by default for TTY based
117
+ outputs and can be configured with a ` --color ` argument.
118
+
36
119
# Tools included
37
120
38
121
The ` wasm-tools ` binary internally contains a number of subcommands for working
39
- with wasm modules. Many subcommands also come with Rust crates that can be use
40
- programmatically as well:
122
+ with wasm modules and component . Many subcommands also come with Rust crates
123
+ that can be use programmatically as well:
41
124
42
- | Tool | Crate | Description |
125
+ | CLI | Rust Crate | Description |
43
126
| ------| ------| ------------|
44
127
| ` wasm-tools validate ` | [ wasmparser] | Validate a WebAssembly file |
45
128
| ` wasm-tools parse ` | [ wat] and [ wast] | Translate the WebAssembly text format to binary |
46
129
| ` wasm-tools print ` | [ wasmprinter] | Translate the WebAssembly binary format to text |
47
- | ` wasm-tools smith ` | [ wasm-smith] | Generate a "random" valid WebAssembly module |
130
+ | ` wasm-tools smith ` | [ wasm-smith] | Generate a valid WebAssembly module from an input seed |
48
131
| ` wasm-tools mutate ` | [ wasm-mutate] | Mutate an input wasm file into a new valid wasm file |
49
132
| ` wasm-tools shrink ` | [ wasm-shrink] | Shrink a wasm file while preserving a predicate |
50
133
| ` wasm-tools dump ` | | Print debugging information about the binary format |
@@ -58,6 +141,7 @@ programmatically as well:
58
141
| ` wasm-tools metadata show ` | [ wasm-metadata] | Show name and producer metadata in a component or module |
59
142
| ` wasm-tools metadata add ` | | Add name or producer metadata to a component or module |
60
143
| ` wasm-tools addr2line ` | | Translate wasm offsets to filename/line numbers with DWARF |
144
+ | ` wasm-tools completion ` | | Generate shell completion scripts for ` wasm-tools ` |
61
145
62
146
[ wasmparser ] : https://crates.io/crates/wasmparser
63
147
[ wat ] : https://crates.io/crates/wat
@@ -70,9 +154,9 @@ programmatically as well:
70
154
[ wasm-compose ] : https://crates.io/crates/wasm-compose
71
155
[ wasm-metadata ] : https://crates.io/crates/wasm-metadata
72
156
73
- The ` wasm-tools ` CLI is primarily intended to be a debugging aid. The various
74
- subcommands all have ` --help ` explainer texts to describe more about their
75
- functionality as well.
157
+ The ` wasm-tools ` CLI contains useful tools for debugging WebAssembly modules and
158
+ components. The various subcommands all have ` --help ` explainer texts to
159
+ describe more about their functionality as well.
76
160
77
161
# Libraries
78
162
@@ -101,7 +185,16 @@ embedding into a separate project.
101
185
102
186
# C/C++ bindings
103
187
104
- Using the ` CMakeLists.txt ` in ` crates/c-api ` , ` wasm-tools ` can be used from the [ ` wasm-tools.h ` header] ( crates/c-api/include/wasm-tools.h ) .
188
+ Using the ` CMakeLists.txt ` in ` crates/c-api ` , ` wasm-tools ` can be used from the
189
+ [ ` wasm-tools.h ` header] ( crates/c-api/include/wasm-tools.h ) . Note that these
190
+ bindings do not comprehensively cover all the functionality of this repository
191
+ at this time, but please feel free to contribute more if you find functions
192
+ useful!
193
+
194
+ # Contributing
195
+
196
+ See [ CONTRIBUTING.md] ( ./CONTRIBUTING.md ) for more information about contributing
197
+ to this repository.
105
198
106
199
# License
107
200
0 commit comments