@@ -14,7 +14,7 @@ use std::{collections::VecDeque, ffi::OsStr, path::Path};
14
14
use wasmparser:: {
15
15
component_types:: { ComponentEntityType , ComponentInstanceTypeId } ,
16
16
types:: TypesRef ,
17
- ComponentExternalKind , ComponentTypeRef ,
17
+ ComponentExternalKind , ComponentTypeRef , Validator , WasmFeatures ,
18
18
} ;
19
19
20
20
/// The root component name used in configuration.
@@ -69,12 +69,19 @@ struct CompositionGraphBuilder<'a> {
69
69
instances : IndexMap < String , InstanceId > ,
70
70
/// The definition components in the graph.
71
71
definitions : Vec < ( ComponentId , Option < InstanceId > ) > ,
72
+ /// Wasm validator and shared type arenas.
73
+ validator : Validator ,
72
74
}
73
75
74
76
impl < ' a > CompositionGraphBuilder < ' a > {
75
77
fn new ( root_path : & Path , config : & ' a Config ) -> Result < Self > {
76
78
let mut graph = CompositionGraph :: new ( ) ;
77
- graph. add_component ( Component :: from_file ( ROOT_COMPONENT_NAME , root_path) ?) ?;
79
+ let mut validator = Validator :: new_with_features ( WasmFeatures :: all ( ) ) ;
80
+ graph. add_component ( Component :: from_file (
81
+ & mut validator,
82
+ ROOT_COMPONENT_NAME ,
83
+ root_path,
84
+ ) ?) ?;
78
85
79
86
let definitions = config
80
87
. definitions
@@ -87,7 +94,7 @@ impl<'a> CompositionGraphBuilder<'a> {
87
94
)
88
95
} ) ?;
89
96
90
- let component = Component :: from_file ( name, config. dir . join ( path) ) ?;
97
+ let component = Component :: from_file ( & mut validator , name, config. dir . join ( path) ) ?;
91
98
92
99
Ok ( ( graph. add_component ( component) ?, None ) )
93
100
} )
@@ -98,6 +105,7 @@ impl<'a> CompositionGraphBuilder<'a> {
98
105
graph,
99
106
instances : Default :: default ( ) ,
100
107
definitions,
108
+ validator,
101
109
} )
102
110
}
103
111
@@ -117,14 +125,15 @@ impl<'a> CompositionGraphBuilder<'a> {
117
125
}
118
126
119
127
/// Finds the component with the given name on disk.
120
- fn find_component ( & self , name : & str ) -> Result < Option < Component < ' a > > > {
128
+ fn find_component ( & mut self , name : & str ) -> Result < Option < Component < ' a > > > {
121
129
// Check the config for an explicit path (must be a valid component)
122
130
if let Some ( dep) = self . config . dependencies . get ( name) {
123
131
log:: debug!(
124
132
"component with name `{name}` has an explicit path of `{path}`" ,
125
133
path = dep. path. display( )
126
134
) ;
127
135
return Ok ( Some ( Component :: from_file (
136
+ & mut self . validator ,
128
137
name,
129
138
self . config . dir . join ( & dep. path ) ,
130
139
) ?) ) ;
@@ -133,7 +142,7 @@ impl<'a> CompositionGraphBuilder<'a> {
133
142
// Otherwise, search the paths for a valid component with the same name
134
143
log:: info!( "searching for a component with name `{name}`" ) ;
135
144
for dir in std:: iter:: once ( & self . config . dir ) . chain ( self . config . search_paths . iter ( ) ) {
136
- if let Some ( component) = Self :: parse_component ( dir, name) ? {
145
+ if let Some ( component) = Self :: parse_component ( & mut self . validator , dir, name) ? {
137
146
return Ok ( Some ( component) ) ;
138
147
}
139
148
}
@@ -144,7 +153,11 @@ impl<'a> CompositionGraphBuilder<'a> {
144
153
/// Parses a component from the given directory, if it exists.
145
154
///
146
155
/// Returns `Ok(None)` if the component does not exist.
147
- fn parse_component ( dir : & Path , name : & str ) -> Result < Option < Component < ' a > > > {
156
+ fn parse_component (
157
+ validator : & mut Validator ,
158
+ dir : & Path ,
159
+ name : & str ,
160
+ ) -> Result < Option < Component < ' a > > > {
148
161
let mut path = dir. join ( name) ;
149
162
150
163
for ext in [ "wasm" , "wat" ] {
@@ -154,7 +167,7 @@ impl<'a> CompositionGraphBuilder<'a> {
154
167
continue ;
155
168
}
156
169
157
- return Ok ( Some ( Component :: from_file ( name, & path) ?) ) ;
170
+ return Ok ( Some ( Component :: from_file ( validator , name, & path) ?) ) ;
158
171
}
159
172
160
173
Ok ( None )
0 commit comments