|
| 1 | +Tool for working with the WIT text format for components |
| 2 | + |
| 3 | +Usage: wasm-tools component wit [OPTIONS] [INPUT] |
| 4 | + |
| 5 | +Arguments: |
| 6 | + [INPUT] Input file or directory to process |
| 7 | + |
| 8 | +Options: |
| 9 | + -v, --verbose... |
| 10 | + Use verbose output (-v info, -vv debug, -vvv trace) |
| 11 | + --color <COLOR> |
| 12 | + Configuration over whether terminal colors are used in output |
| 13 | + [default: auto] |
| 14 | + -o, --output <OUTPUT> |
| 15 | + Where to place output |
| 16 | + -w, --wasm |
| 17 | + Emit a WebAssembly binary representation instead of the WIT text |
| 18 | + format |
| 19 | + -t, --wat |
| 20 | + Emit a WebAssembly textual representation instead of the WIT text |
| 21 | + format |
| 22 | + --no-docs |
| 23 | + Do not include doc comments when emitting WIT text |
| 24 | + --out-dir <OUT_DIR> |
| 25 | + Emit the entire WIT resolution graph instead of just the "top level" |
| 26 | + package to the output directory specified |
| 27 | + --skip-validation |
| 28 | + Skips the validation performed when using the `--wasm` and `--wat` |
| 29 | + options |
| 30 | + -j, --json |
| 31 | + Emit the WIT document as JSON instead of text |
| 32 | + --importize |
| 33 | + Generates WIT to import the component specified to this command |
| 34 | + --importize-out-world-name <IMPORTIZE_OUT_WORLD_NAME> |
| 35 | + The name of the world to generate when using `--importize` or |
| 36 | + `importize-world` |
| 37 | + --importize-world <WORLD> |
| 38 | + Generates a WIT world to import a component which corresponds to the |
| 39 | + selected world |
| 40 | + --merge-world-imports-based-on-semver <WORLD> |
| 41 | + Updates the world specified to deduplicate all of its imports based on |
| 42 | + semver versions |
| 43 | + --features <FEATURES> |
| 44 | + Features to enable when parsing the `wit` option |
| 45 | + --all-features |
| 46 | + Enable all features when parsing the `wit` option |
| 47 | + -h, --help |
| 48 | + Print help (see more with '--help') |
| 49 | + |
| 50 | +Examples: |
| 51 | + |
| 52 | + # Parse the current directory as a WIT package and print the resulting |
| 53 | + # package, supposing a directory that contains three WIT files, |
| 54 | + # one defining an |
| 55 | + # `adder` world; one defining a `subtracter` world; and one defining a |
| 56 | + # `calculator` world. |
| 57 | + $ wasm-tools component wit . |
| 58 | + |
| 59 | + |
| 60 | +interface add { |
| 61 | + add: func(x: u32, y: u32) -> u32; |
| 62 | +} |
| 63 | + |
| 64 | +interface evaluate { |
| 65 | + evaluate: func(x: u32, y: u32) -> u32; |
| 66 | +} |
| 67 | + |
| 68 | +interface subtract { |
| 69 | + subtract: func(x: u32, y: u32) -> u32; |
| 70 | +} |
| 71 | + |
| 72 | +world adder { |
| 73 | + export add; |
| 74 | +} |
| 75 | +world calculator { |
| 76 | + import add; |
| 77 | + import subtract; |
| 78 | + |
| 79 | + export evaluate; |
| 80 | +} |
| 81 | +world subtracter { |
| 82 | + export subtract; |
| 83 | +} |
| 84 | + |
| 85 | + # Supposing the same directory contents as above, print the package to |
| 86 | + # a file in the `out` subdirectory. |
| 87 | + $ wasm-tools component wit . --out-dir out |
| 88 | + |
| 89 | + # Supposing the same directory contents above, print the WIT for a world |
| 90 | + # that imports the exports of the `calculator` world. |
| 91 | + # In the output, the `calculator` world is replaced with: |
| 92 | + # world calculator-importized { |
| 93 | + # import evaluate; |
| 94 | + # } |
| 95 | + $ wasm-tools component wit . --importize-world calculator |
| 96 | + |
| 97 | + # Supposing foo.wasm is a binary component, extract the interface |
| 98 | + # from the component and print it to stdout. |
| 99 | + $ wasm-tools component wit foo.wasm |
| 100 | + |
| 101 | + # Supposing foo.wasm is a binary component that depends on several |
| 102 | + # WASI interfaces, extract the interface from the component and save it |
| 103 | + # as WIT, along with WIT files containing all the dependencies, to |
| 104 | + # the `out` subdirectory. |
| 105 | + $ wasm-tools component wit foo.wasm --out-dir out |
| 106 | +Writing: out/deps/io.wit |
| 107 | +Writing: out/deps/cli.wit |
| 108 | +Writing: out/deps/clocks.wit |
| 109 | +Writing: out/deps/filesystem.wit |
| 110 | +Writing: out/deps/adder.wit |
| 111 | +Writing: out/component.wit |
| 112 | + |
| 113 | + # With the same foo.wasm file, print a textual WAT representation |
| 114 | + # of the interface to stdout, skipping validation of the WAT code. |
| 115 | + $ wasm-tools component wit foo.wasm -t --skip-validation |
| 116 | + |
| 117 | + # With the same foo.wasm file, print a JSON representation |
| 118 | + # of the interface to stdout. |
| 119 | + $ wasm-tools component wit foo.wasm --json |
| 120 | + |
| 121 | + # With the same foo.wasm file, print the WIT for a world that |
| 122 | + # imports the component's exports to stdout. |
| 123 | + $ wasm-tools component wit foo.wasm --importize |
| 124 | + |
| 125 | +Supposing feature.wit is as follows: |
| 126 | +package a:b; |
| 127 | + |
| 128 | +@unstable(feature = foo) |
| 129 | +interface foo { |
| 130 | + @unstable(feature = foo) |
| 131 | + type t = u32; |
| 132 | +} |
| 133 | + |
| 134 | + # Print the WIT for feature.wit without hiding the unstable |
| 135 | + # "foo" feature. |
| 136 | + $ wasm-tools component wit feature.wit --features foo |
| 137 | +package a:b; |
| 138 | + |
| 139 | +@unstable(feature = foo) |
| 140 | +interface foo { |
| 141 | + @unstable(feature = foo) |
| 142 | + type t = u32; |
| 143 | +} |
| 144 | + |
| 145 | + # Print the WIT for feature.wit, hiding the unstable |
| 146 | + # "foo" feature. |
| 147 | + $ wasm-tools component wit feature.wit |
| 148 | +package a:b; |
0 commit comments