@@ -124,6 +124,23 @@ impl PlatformField {
124124 }
125125}
126126
127+ pub struct FlagsField ;
128+
129+ impl FlagsField {
130+ pub fn field ( ) -> FormInputField {
131+ FormInputField :: MultilineText {
132+ prompt : "Compiler flags" . to_string ( ) ,
133+ default : None ,
134+ value : None ,
135+ }
136+ }
137+
138+ pub fn from_form ( form : & Form ) -> Option < String > {
139+ let field = form. get_field_with_name ( "Compiler flags" ) ?;
140+ field. try_value_string ( )
141+ }
142+ }
143+
127144pub struct CreateFromDirectory ;
128145
129146impl CreateFromDirectory {
@@ -134,20 +151,24 @@ impl CreateFromDirectory {
134151 form. add_field ( PlatformField :: field ( ) ) ;
135152 form. add_field ( NameField :: field ( ) ) ;
136153 form. add_field ( OutputDirectoryField :: field ( ) ) ;
154+ form. add_field ( FlagsField :: field ( ) ) ;
155+
137156 if !form. prompt ( ) {
138157 return ;
139158 }
140159 let input_dir = InputDirectoryField :: from_form ( & form) . unwrap ( ) ;
141160 let platform_name = PlatformField :: from_form ( & form) . unwrap ( ) ;
142161 let default_name = NameField :: from_form ( & form) . unwrap ( ) ;
143162 let output_dir = OutputDirectoryField :: from_form ( & form) . unwrap ( ) ;
163+ let flags = FlagsField :: from_form ( & form) . unwrap ( ) ;
144164
145165 let Some ( default_platform) = Platform :: by_name ( & platform_name) else {
146166 tracing:: error!( "Invalid platform name: {}" , platform_name) ;
147167 return ;
148168 } ;
149169
150- let processor = TypeLibProcessor :: new ( & default_name, & default_platform. name ( ) ) ;
170+ let processor = TypeLibProcessor :: new ( & default_name, & default_platform. name ( ) )
171+ . with_options ( split_args ( flags. as_str ( ) ) ) ;
151172
152173 let background_task = BackgroundTask :: new ( "Processing started..." , true ) ;
153174 new_processing_state_background_thread ( background_task. clone ( ) , processor. state ( ) ) ;
@@ -274,3 +295,22 @@ impl ProjectCommand for CreateFromProject {
274295 true
275296 }
276297}
298+
299+ fn split_args ( input : & str ) -> Vec < String > {
300+ let mut args = Vec :: new ( ) ;
301+ let mut cur = String :: new ( ) ;
302+ let mut in_quote = false ;
303+ let mut has_token = false ;
304+
305+ for c in input. chars ( ) {
306+ match c {
307+ '"' => { in_quote = !in_quote; has_token = true ; }
308+ c if c. is_whitespace ( ) && !in_quote => {
309+ if has_token { args. push ( std:: mem:: take ( & mut cur) ) ; has_token = false ; }
310+ }
311+ c => { cur. push ( c) ; has_token = true ; }
312+ }
313+ }
314+ if has_token { args. push ( cur) ; }
315+ args
316+ }
0 commit comments