@@ -4,9 +4,7 @@ use heck::*;
44use indexmap:: IndexSet ;
55use std:: collections:: { BTreeMap , HashMap , HashSet } ;
66use std:: fmt:: { self , Write as _} ;
7- use std:: io:: { Read , Write } ;
87use std:: mem;
9- use std:: process:: { Command , Stdio } ;
108use std:: str:: FromStr ;
119use wit_bindgen_core:: abi:: { Bitcast , WasmType } ;
1210use wit_bindgen_core:: {
@@ -86,9 +84,9 @@ fn parse_with(s: &str) -> Result<(String, String), String> {
8684#[ derive( Default , Debug , Clone ) ]
8785#[ cfg_attr( feature = "clap" , derive( clap:: Args ) ) ]
8886pub struct Opts {
89- /// Whether or not `rustfmt` is executed to format generated code.
87+ /// Whether or not a formatter is executed to format generated code.
9088 #[ cfg_attr( feature = "clap" , arg( long) ) ]
91- pub rustfmt : bool ,
89+ pub format : bool ,
9290
9391 /// If true, code generation should qualify any features that depend on
9492 /// `std` with `cfg(feature = "std")`.
@@ -1022,28 +1020,9 @@ impl WorldGenerator for RustWasm {
10221020 }
10231021
10241022 let mut src = mem:: take ( & mut self . src ) ;
1025- if self . opts . rustfmt {
1026- let mut child = Command :: new ( "rustfmt" )
1027- . arg ( "--edition=2018" )
1028- . stdin ( Stdio :: piped ( ) )
1029- . stdout ( Stdio :: piped ( ) )
1030- . spawn ( )
1031- . expect ( "failed to spawn `rustfmt`" ) ;
1032- child
1033- . stdin
1034- . take ( )
1035- . unwrap ( )
1036- . write_all ( src. as_bytes ( ) )
1037- . unwrap ( ) ;
1038- src. as_mut_string ( ) . truncate ( 0 ) ;
1039- child
1040- . stdout
1041- . take ( )
1042- . unwrap ( )
1043- . read_to_string ( src. as_mut_string ( ) )
1044- . unwrap ( ) ;
1045- let status = child. wait ( ) . unwrap ( ) ;
1046- assert ! ( status. success( ) ) ;
1023+ if self . opts . format {
1024+ let syntax_tree = syn:: parse_file ( src. as_str ( ) ) . unwrap ( ) ;
1025+ * src. as_mut_string ( ) = prettyplease:: unparse ( & syntax_tree) ;
10471026 }
10481027
10491028 let module_name = name. to_snake_case ( ) ;
0 commit comments