@@ -4,9 +4,7 @@ use heck::*;
4
4
use indexmap:: IndexSet ;
5
5
use std:: collections:: { BTreeMap , HashMap , HashSet } ;
6
6
use std:: fmt:: { self , Write as _} ;
7
- use std:: io:: { Read , Write } ;
8
7
use std:: mem;
9
- use std:: process:: { Command , Stdio } ;
10
8
use std:: str:: FromStr ;
11
9
use wit_bindgen_core:: abi:: { Bitcast , WasmType } ;
12
10
use wit_bindgen_core:: {
@@ -86,9 +84,9 @@ fn parse_with(s: &str) -> Result<(String, String), String> {
86
84
#[ derive( Default , Debug , Clone ) ]
87
85
#[ cfg_attr( feature = "clap" , derive( clap:: Args ) ) ]
88
86
pub 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.
90
88
#[ cfg_attr( feature = "clap" , arg( long) ) ]
91
- pub rustfmt : bool ,
89
+ pub format : bool ,
92
90
93
91
/// If true, code generation should qualify any features that depend on
94
92
/// `std` with `cfg(feature = "std")`.
@@ -1022,28 +1020,9 @@ impl WorldGenerator for RustWasm {
1022
1020
}
1023
1021
1024
1022
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) ;
1047
1026
}
1048
1027
1049
1028
let module_name = name. to_snake_case ( ) ;
0 commit comments