11use {
2+ crate :: { BindingsGenerator , ComponentGenerator } ,
23 anyhow:: { Context , Result } ,
34 clap:: Parser as _,
45 std:: {
@@ -82,6 +83,16 @@ pub struct Common {
8283 /// If this is not specified, the module name will default to "wit_world".
8384 #[ arg( long) ]
8485 pub world_module : Option < String > ,
86+
87+ /// When generating Python module names, include the WIT package name and
88+ /// version even if only one version of that package is referenced by the
89+ /// specified world or only one package uses that name.
90+ ///
91+ /// By default, the package name and version will only be included in the
92+ /// name if the world references more than one version of the WIT package or
93+ /// the name is used by more than one package.
94+ #[ arg( long) ]
95+ pub full_names : bool ,
8596}
8697
8798#[ derive( clap:: Subcommand , Debug ) ]
@@ -171,28 +182,34 @@ pub fn run<T: Into<OsString> + Clone, I: IntoIterator<Item = T>>(args: I) -> Res
171182}
172183
173184fn generate_bindings ( common : Common , bindings : Bindings ) -> Result < ( ) > {
174- crate :: generate_bindings (
175- & common. wit_path ,
176- & common. world . iter ( ) . map ( |v| v. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
177- & common
185+ BindingsGenerator {
186+ wit_path : & common
187+ . wit_path
188+ . iter ( )
189+ . map ( |v| v. as_path ( ) )
190+ . collect :: < Vec < _ > > ( ) ,
191+ worlds : & common. world . iter ( ) . map ( |v| v. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
192+ features : & common
178193 . features
179194 . iter ( )
180195 . map ( |v| v. as_str ( ) )
181196 . collect :: < Vec < _ > > ( ) ,
182- common. all_features ,
183- common. world_module . as_deref ( ) ,
184- & bindings. output_dir ,
185- & common
197+ all_features : common. all_features ,
198+ world_module : common. world_module . as_deref ( ) ,
199+ output_dir : & bindings. output_dir ,
200+ import_interface_names : & common
186201 . import_interface_name
187202 . iter ( )
188203 . map ( |( a, b) | ( a. as_str ( ) , b. as_str ( ) ) )
189204 . collect ( ) ,
190- & common
205+ export_interface_names : & common
191206 . export_interface_name
192207 . iter ( )
193208 . map ( |( a, b) | ( a. as_str ( ) , b. as_str ( ) ) )
194209 . collect ( ) ,
195- )
210+ full_names : common. full_names ,
211+ }
212+ . generate ( )
196213}
197214
198215fn componentize ( common : Common , componentize : Componentize ) -> Result < ( ) > {
@@ -207,40 +224,48 @@ fn componentize(common: Common, componentize: Componentize) -> Result<()> {
207224 ) ;
208225 }
209226
210- Runtime :: new ( ) ?. block_on ( crate :: componentize (
211- & common. wit_path ,
212- & common. world . iter ( ) . map ( |v| v. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
213- & common
214- . features
215- . iter ( )
216- . map ( |v| v. as_str ( ) )
217- . collect :: < Vec < _ > > ( ) ,
218- common. all_features ,
219- common. world_module . as_deref ( ) ,
220- & python_path. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
221- & componentize
222- . module_worlds
223- . iter ( )
224- . map ( |( k, v) | ( k. as_str ( ) , [ v. as_str ( ) ] ) )
225- . collect :: < Vec < _ > > ( )
226- . iter ( )
227- . map ( |( k, v) | ( * k, v as & [ _ ] ) )
228- . collect :: < Vec < _ > > ( ) ,
229- & componentize. app_name ,
230- & componentize. output ,
231- None ,
232- componentize. stub_wasi ,
233- & common
234- . import_interface_name
235- . iter ( )
236- . map ( |( a, b) | ( a. as_str ( ) , b. as_str ( ) ) )
237- . collect ( ) ,
238- & common
239- . export_interface_name
240- . iter ( )
241- . map ( |( a, b) | ( a. as_str ( ) , b. as_str ( ) ) )
242- . collect ( ) ,
243- ) ) ?;
227+ Runtime :: new ( ) ?. block_on (
228+ ComponentGenerator {
229+ wit_path : & common
230+ . wit_path
231+ . iter ( )
232+ . map ( |v| v. as_path ( ) )
233+ . collect :: < Vec < _ > > ( ) ,
234+ worlds : & common. world . iter ( ) . map ( |v| v. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
235+ features : & common
236+ . features
237+ . iter ( )
238+ . map ( |v| v. as_str ( ) )
239+ . collect :: < Vec < _ > > ( ) ,
240+ all_features : common. all_features ,
241+ world_module : common. world_module . as_deref ( ) ,
242+ python_path : & python_path. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) ,
243+ module_worlds : & componentize
244+ . module_worlds
245+ . iter ( )
246+ . map ( |( k, v) | ( k. as_str ( ) , [ v. as_str ( ) ] ) )
247+ . collect :: < Vec < _ > > ( )
248+ . iter ( )
249+ . map ( |( k, v) | ( * k, v as & [ _ ] ) )
250+ . collect :: < Vec < _ > > ( ) ,
251+ app_name : & componentize. app_name ,
252+ output_path : & componentize. output ,
253+ add_to_linker : None ,
254+ stub_wasi : componentize. stub_wasi ,
255+ import_interface_names : & common
256+ . import_interface_name
257+ . iter ( )
258+ . map ( |( a, b) | ( a. as_str ( ) , b. as_str ( ) ) )
259+ . collect ( ) ,
260+ export_interface_names : & common
261+ . export_interface_name
262+ . iter ( )
263+ . map ( |( a, b) | ( a. as_str ( ) , b. as_str ( ) ) )
264+ . collect ( ) ,
265+ full_names : common. full_names ,
266+ }
267+ . generate ( ) ,
268+ ) ?;
244269
245270 if !common. quiet {
246271 println ! ( "Component built successfully" ) ;
@@ -376,6 +401,7 @@ mod tests {
376401 all_features : false ,
377402 import_interface_name : Vec :: new ( ) ,
378403 export_interface_name : Vec :: new ( ) ,
404+ full_names : false ,
379405 } ;
380406 let bindings = Bindings {
381407 output_dir : out_dir. path ( ) . into ( ) ,
@@ -406,6 +432,7 @@ mod tests {
406432 all_features : false ,
407433 import_interface_name : Vec :: new ( ) ,
408434 export_interface_name : Vec :: new ( ) ,
435+ full_names : false ,
409436 } ;
410437 let bindings = Bindings {
411438 output_dir : out_dir. path ( ) . into ( ) ,
@@ -436,6 +463,7 @@ mod tests {
436463 all_features : true ,
437464 import_interface_name : Vec :: new ( ) ,
438465 export_interface_name : Vec :: new ( ) ,
466+ full_names : false ,
439467 } ;
440468 let bindings = Bindings {
441469 output_dir : out_dir. path ( ) . into ( ) ,
@@ -465,6 +493,7 @@ mod tests {
465493 all_features : false ,
466494 import_interface_name : Vec :: new ( ) ,
467495 export_interface_name : Vec :: new ( ) ,
496+ full_names : false ,
468497 } ;
469498 let bindings = Bindings {
470499 output_dir : out_dir. path ( ) . into ( ) ,
0 commit comments