@@ -182,7 +182,7 @@ impl Invoker for MyInvoker {
182182
183183#[ allow( clippy:: too_many_arguments) ]
184184pub fn generate_bindings (
185- wit_path : & Path ,
185+ wit_path : & [ impl AsRef < Path > ] ,
186186 world : Option < & str > ,
187187 features : & [ String ] ,
188188 all_features : bool ,
@@ -217,7 +217,7 @@ pub fn generate_bindings(
217217
218218#[ allow( clippy:: type_complexity, clippy:: too_many_arguments) ]
219219pub async fn componentize (
220- wit_path : Option < & Path > ,
220+ wit_path : & [ impl AsRef < Path > ] ,
221221 world : Option < & str > ,
222222 features : & [ String ] ,
223223 all_features : bool ,
@@ -245,11 +245,12 @@ pub async fn componentize(
245245
246246 // Next, iterate over all the WIT directories, merging them into a single `Resolve`, and matching Python
247247 // packages to `WorldId`s.
248- let ( mut resolve, mut main_world) = if let Some ( path) = wit_path {
249- let ( resolve, world) = parse_wit ( path, world, features, all_features) ?;
250- ( Some ( resolve) , Some ( world) )
251- } else {
252- ( None , None )
248+ let ( mut resolve, mut main_world) = match wit_path {
249+ [ ] => ( None , None ) ,
250+ paths => {
251+ let ( resolve, world) = parse_wit ( paths, world, features, all_features) ?;
252+ ( Some ( resolve) , Some ( world) )
253+ }
253254 } ;
254255
255256 let import_interface_names = import_interface_names
@@ -281,7 +282,8 @@ pub async fn componentize(
281282 . map ( |( module, ( config, world) ) | {
282283 Ok ( ( module, match ( world, config. config . wit_directory . as_deref ( ) ) {
283284 ( _, Some ( wit_path) ) => {
284- let ( my_resolve, mut world) = parse_wit ( & config. path . join ( wit_path) , * world, features, all_features) ?;
285+ let paths = & [ config. path . join ( wit_path) ] ;
286+ let ( my_resolve, mut world) = parse_wit ( paths, * world, features, all_features) ?;
285287
286288 if let Some ( resolve) = & mut resolve {
287289 let remap = resolve. merge ( my_resolve) ?;
@@ -303,13 +305,13 @@ pub async fn componentize(
303305 let resolve = if let Some ( resolve) = resolve {
304306 resolve
305307 } else {
306- // If no WIT directory was provided as a parameter and none were referenced by Python packages, use ./wit
307- // by default.
308- let ( my_resolve , world ) = parse_wit ( Path :: new ( "wit" ) , world , features , all_features )
309- . context (
310- "no WIT files found; please specify the directory or file \
308+ // If no WIT directory was provided as a parameter and none were referenced by Python packages, use
309+ // the default values .
310+ let paths : & [ & Path ] = & [ ] ;
311+ let ( my_resolve , world ) = parse_wit ( paths , world , features , all_features ) . context (
312+ "no WIT files found; please specify the directory or file \
311313 containing the WIT world you wish to target",
312- ) ?;
314+ ) ?;
313315 main_world = Some ( world) ;
314316 my_resolve
315317 } ;
@@ -556,11 +558,19 @@ pub async fn componentize(
556558}
557559
558560fn parse_wit (
559- path : & Path ,
561+ paths : & [ impl AsRef < Path > ] ,
560562 world : Option < & str > ,
561563 features : & [ String ] ,
562564 all_features : bool ,
563565) -> Result < ( Resolve , WorldId ) > {
566+ // If no WIT directory was provided as a parameter and none were referenced by Python packages, use ./wit
567+ // by default.
568+ if paths. is_empty ( ) {
569+ let paths = & [ Path :: new ( "wit" ) ] ;
570+ return parse_wit ( paths, world, features, all_features) ;
571+ }
572+ debug_assert ! ( !paths. is_empty( ) , "The paths should not be empty" ) ;
573+
564574 let mut resolve = Resolve {
565575 all_features,
566576 ..Default :: default ( )
@@ -574,12 +584,19 @@ fn parse_wit(
574584 resolve. features . insert ( feature. to_string ( ) ) ;
575585 }
576586 }
577- let pkg = if path. is_dir ( ) {
578- resolve. push_dir ( path) ?. 0
579- } else {
580- let pkg = UnresolvedPackageGroup :: parse_file ( path) ?;
581- resolve. push_group ( pkg) ?
582- } ;
587+
588+ let mut last_pkg = None ;
589+ for path in paths. iter ( ) . map ( AsRef :: as_ref) {
590+ let pkg = if path. is_dir ( ) {
591+ resolve. push_dir ( path) ?. 0
592+ } else {
593+ let pkg = UnresolvedPackageGroup :: parse_file ( path) ?;
594+ resolve. push_group ( pkg) ?
595+ } ;
596+ last_pkg = Some ( pkg) ;
597+ }
598+
599+ let pkg = last_pkg. unwrap ( ) ; // The paths should not be empty
583600 let world = resolve. select_world ( pkg, world) ?;
584601 Ok ( ( resolve, world) )
585602}
0 commit comments