Debian Codegraph @

crates/wasm-compose/CONFIG.md

raw
1 # Configuring `wasm-compose`
2
3 `wasm-compose` can be configured using a YAML configuration file.
4
5 To specify the configuration file to use, pass the `--config` option to
6 `wasm-tools compose`.
7
8 The configuration file has the following top-level fields:
9
10 - `search-paths` : `list<string>` (optional) - a list of paths to search for
11 dependencies.
12 - `skip-validation` : `bool` (optional) - a boolean indicating whether to skip
13 validation of the resulting composed component.
14 - `dependencies` : `map<string, dependency>` (optional) - a map specifying the
15 explicit locations of transitive dependencies.
16 - `instantiations` : `map<string, instantiation>` (optional) - a map specifying
17 the explicit instantiations of transitive dependencies.
18 - `definitions` : `list<string>` (optional) - a list of paths to _definition_
19 components.
20
21 ## Dependencies
22
23 Each `dependency` specifies a path where `wasm-compose` may locate a
24 dependency, rather than searching the configured search paths.
25
26 A dependency has the following fields:
27
28 - `path` : `string` - the path to the WebAssembly component file; the path is
29 relative to the configuration file.
30
31 - `import` : `string` (optional) - the name to use for importing the component.
32 If not present, the component at the given path will be defined directly in
33 the composed component.
34
35 Dependencies may be specified as a `string` rather than a `map`, in which case
36 it is treated as having a `path` field with the value of the string.
37
38 ### Dependencies example
39
40 An example of specifying dependencies:
41
42 ```yaml
43 dependencies:
44 a: a.wasm
45 b:
46 path: b.wasm
47 import: b
48 ```
49
50 In the above example, two dependencies are defined in the configuration:
51
52 - `a` - the contents of `a.wasm` will be defined directly in the composed
53 component.
54 - `b` - a component of the same type as `b.wasm` will be imported in the
55 composed component with name `b`; the original file will not be embedded in the
56 composed component.
57
58 _Note: importing components from a composed component is not currently
59 supported in [Wasmtime](https://github.com/bytecodealliance/wasmtime)._
60
61 Dependency names should match the expected name of imports from components in
62 the component graph.
63
64 ## Instantiations
65
66 Each `instantiation` specifies how a particular dependency is to be
67 instantiated, even allowing a dependency to be instantiated multiple times.
68
69 An instantiation has the following fields:
70
71 - `dependency` : `string` (optional) - the name of the dependency to
72 instantiate.
73
74 If unspecified, the instantiation will be for a dependency of the same name
75 as the instantiation itself.
76
77 - `arguments` : `map<string, argument>` (optional) - a mapping of argument
78 names to arguments.
79
80 Argument names match the names of the imports of the dependency being
81 instantiated.
82
83 Note that the instantiation name `root` is special and signifies how the input
84 component is to be instantiated.
85
86 ### Instantiation arguments
87
88 Each `argument` specifies exactly which instance should be provided as argument
89 to the instantiation of a dependency.
90
91 An argument has the following fields:
92
93 - `instance` : `string` - the name of the instance to pass as the argument.
94
95 - `export` : `string` (optional) - the name of the exported instance on
96 `instance` to use as the argument.
97
98 If not present, the instance specified by `instance` will be passed directly.
99
100 Arguments may be specified as a `string` rather than a `map`, in which case
101 it is treated as having an `instance` field with the value of the string.
102
103 ## Instantiations example
104
105 A slightly complex example of configuring instantiations:
106
107 ```yaml
108 instantiations:
109 root:
110 arguments:
111 a: b
112 b:
113 arguments:
114 c:
115 instance: d
116 export: e
117 d:
118 dependency: f
119 ```
120
121 In the above example, the `root` instantiation (i.e. the root instantiation)
122 has explicitly specified that the argument named `a` is to be provided instance
123 `b`.
124
125 It also defines an instantiation named `b` which is to be passed an instance
126 export named `e` from instance `d` (of a dependency named `f`) for the
127 instantiation argument named `c`.
128
129 By default, `wasm-compose` will minimize the number of instantiations and
130 dependencies which share an import of the same name will share the same
131 instance of that dependency, provided that the instance is compatible with
132 every import.
133
134 Configuring instantiations for `wasm-compose` allows for a custom instantiation
135 graph to be constructed in the composed component.
136
137 ## Definition components
138
139 A _definition_ component is a component that exports instances that are
140 automatically used to satisfy any instance import in the composition with a
141 matching name.
142
143 A typical use case for definition components is to provide a _virtualized_
144 implementation of common interfaces.
145
146 For example, a definition component might export a virtualized implementation
147 of the `wasi:filesystem/types` interface that serves files via inline data
148 segments instead of by accessing the host filesystem.
149
150 By providing such a definition component to the composition, any use of the
151 WASI filesystem interface by the root component (or its dependencies) will
152 automatically use the implementation provided by the definition component
153 instead of importing it from the host environment.