@@ -7,7 +7,7 @@ use syn::parse::{Error, Parse, ParseStream, Result};
7
7
use syn:: punctuated:: Punctuated ;
8
8
use syn:: { braced, token, Token } ;
9
9
use wit_bindgen_core:: wit_parser:: { PackageId , Resolve , UnresolvedPackage , WorldId } ;
10
- use wit_bindgen_rust:: { Opts , Ownership } ;
10
+ use wit_bindgen_rust:: { Opts , Ownership , WithOption } ;
11
11
12
12
#[ proc_macro]
13
13
pub fn generate ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
@@ -99,6 +99,9 @@ impl Parse for Config {
99
99
. collect ( )
100
100
}
101
101
Opt :: With ( with) => opts. with . extend ( with) ,
102
+ Opt :: GenerateAll => {
103
+ opts. with . generate_by_default = true ;
104
+ }
102
105
Opt :: TypeSectionSuffix ( suffix) => {
103
106
opts. type_section_suffix = Some ( suffix. value ( ) ) ;
104
107
}
@@ -234,6 +237,7 @@ mod kw {
234
237
syn:: custom_keyword!( export_prefix) ;
235
238
syn:: custom_keyword!( additional_derives) ;
236
239
syn:: custom_keyword!( with) ;
240
+ syn:: custom_keyword!( generate_all) ;
237
241
syn:: custom_keyword!( type_section_suffix) ;
238
242
syn:: custom_keyword!( disable_run_ctors_once_workaround) ;
239
243
syn:: custom_keyword!( default_bindings_module) ;
@@ -284,7 +288,8 @@ enum Opt {
284
288
ExportPrefix ( syn:: LitStr ) ,
285
289
// Parse as paths so we can take the concrete types/macro names rather than raw strings
286
290
AdditionalDerives ( Vec < syn:: Path > ) ,
287
- With ( HashMap < String , String > ) ,
291
+ With ( HashMap < String , WithOption > ) ,
292
+ GenerateAll ,
288
293
TypeSectionSuffix ( syn:: LitStr ) ,
289
294
DisableRunCtorsOnceWorkaround ( syn:: LitBool ) ,
290
295
DefaultBindingsModule ( syn:: LitStr ) ,
@@ -390,6 +395,9 @@ impl Parse for Opt {
390
395
let fields: Punctuated < _ , Token ! [ , ] > =
391
396
contents. parse_terminated ( with_field_parse, Token ! [ , ] ) ?;
392
397
Ok ( Opt :: With ( HashMap :: from_iter ( fields. into_iter ( ) ) ) )
398
+ } else if l. peek ( kw:: generate_all) {
399
+ input. parse :: < kw:: generate_all > ( ) ?;
400
+ Ok ( Opt :: GenerateAll )
393
401
} else if l. peek ( kw:: type_section_suffix) {
394
402
input. parse :: < kw:: type_section_suffix > ( ) ?;
395
403
input. parse :: < Token ! [ : ] > ( ) ?;
@@ -427,7 +435,7 @@ impl Parse for Opt {
427
435
}
428
436
}
429
437
430
- fn with_field_parse ( input : ParseStream < ' _ > ) -> Result < ( String , String ) > {
438
+ fn with_field_parse ( input : ParseStream < ' _ > ) -> Result < ( String , WithOption ) > {
431
439
let interface = input. parse :: < syn:: LitStr > ( ) ?. value ( ) ;
432
440
input. parse :: < Token ! [ : ] > ( ) ?;
433
441
let start = input. span ( ) ;
@@ -438,6 +446,10 @@ fn with_field_parse(input: ParseStream<'_>) -> Result<(String, String)> {
438
446
. join ( path. segments . last ( ) . unwrap ( ) . ident . span ( ) )
439
447
. unwrap_or ( start) ;
440
448
449
+ if path. is_ident ( "generate" ) {
450
+ return Ok ( ( interface, WithOption :: Generate ) ) ;
451
+ }
452
+
441
453
let mut buf = String :: new ( ) ;
442
454
let append = |buf : & mut String , segment : syn:: PathSegment | -> Result < ( ) > {
443
455
if !segment. arguments . is_none ( ) {
@@ -467,7 +479,7 @@ fn with_field_parse(input: ParseStream<'_>) -> Result<(String, String)> {
467
479
append ( & mut buf, segment) ?;
468
480
}
469
481
470
- Ok ( ( interface, buf) )
482
+ Ok ( ( interface, WithOption :: Path ( buf) ) )
471
483
}
472
484
473
485
/// Format a valid Rust string
0 commit comments