@@ -124,6 +124,23 @@ impl PlatformField {
124124 }
125125}
126126
127+ pub struct CompilerOptionsField ;
128+
129+ impl CompilerOptionsField {
130+ pub fn field ( ) -> FormInputField {
131+ FormInputField :: MultilineText {
132+ prompt : "Compiler options" . 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 options" ) ?;
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 ( CompilerOptionsField :: 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 = CompilerOptionsField :: 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_compiler_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,33 @@ 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+ '"' => {
308+ in_quote = !in_quote;
309+ has_token = true ;
310+ }
311+ c if c. is_whitespace ( ) && !in_quote => {
312+ if has_token {
313+ args. push ( std:: mem:: take ( & mut cur) ) ;
314+ has_token = false ;
315+ }
316+ }
317+ c => {
318+ cur. push ( c) ;
319+ has_token = true ;
320+ }
321+ }
322+ }
323+ if has_token {
324+ args. push ( cur) ;
325+ }
326+ args
327+ }
0 commit comments