From 061e8985daae7e74f4915cb3efdd06ad89fff59d Mon Sep 17 00:00:00 2001 From: xitska Date: Mon, 15 Jun 2026 16:33:03 +0100 Subject: [PATCH 1/4] [BNTL] Implement compiler flags field for Create From Directory --- plugins/bntl_utils/src/command/create.rs | 42 +++++++++++++++++++++++- plugins/bntl_utils/src/process.rs | 10 +++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/plugins/bntl_utils/src/command/create.rs b/plugins/bntl_utils/src/command/create.rs index 8fc37159e6..dda61f1f50 100644 --- a/plugins/bntl_utils/src/command/create.rs +++ b/plugins/bntl_utils/src/command/create.rs @@ -124,6 +124,23 @@ impl PlatformField { } } +pub struct FlagsField; + +impl FlagsField { + pub fn field() -> FormInputField { + FormInputField::MultilineText { + prompt: "Compiler flags".to_string(), + default: None, + value: None, + } + } + + pub fn from_form(form: &Form) -> Option { + let field = form.get_field_with_name("Compiler flags")?; + field.try_value_string() + } +} + pub struct CreateFromDirectory; impl CreateFromDirectory { @@ -134,6 +151,8 @@ impl CreateFromDirectory { form.add_field(PlatformField::field()); form.add_field(NameField::field()); form.add_field(OutputDirectoryField::field()); + form.add_field(FlagsField::field()); + if !form.prompt() { return; } @@ -141,13 +160,15 @@ impl CreateFromDirectory { let platform_name = PlatformField::from_form(&form).unwrap(); let default_name = NameField::from_form(&form).unwrap(); let output_dir = OutputDirectoryField::from_form(&form).unwrap(); + let flags = FlagsField::from_form(&form).unwrap(); let Some(default_platform) = Platform::by_name(&platform_name) else { tracing::error!("Invalid platform name: {}", platform_name); return; }; - let processor = TypeLibProcessor::new(&default_name, &default_platform.name()); + let processor = TypeLibProcessor::new(&default_name, &default_platform.name()) + .with_options(split_args(flags.as_str())); let background_task = BackgroundTask::new("Processing started...", true); new_processing_state_background_thread(background_task.clone(), processor.state()); @@ -274,3 +295,22 @@ impl ProjectCommand for CreateFromProject { true } } + +fn split_args(input: &str) -> Vec { + let mut args = Vec::new(); + let mut cur = String::new(); + let mut in_quote = false; + let mut has_token = false; + + for c in input.chars() { + match c { + '"' => { in_quote = !in_quote; has_token = true; } + c if c.is_whitespace() && !in_quote => { + if has_token { args.push(std::mem::take(&mut cur)); has_token = false; } + } + c => { cur.push(c); has_token = true; } + } + } + if has_token { args.push(cur); } + args +} diff --git a/plugins/bntl_utils/src/process.rs b/plugins/bntl_utils/src/process.rs index 5c9651a473..cbd7990d4b 100644 --- a/plugins/bntl_utils/src/process.rs +++ b/plugins/bntl_utils/src/process.rs @@ -434,6 +434,8 @@ pub struct TypeLibProcessor { include_directories: Vec, /// Whether to process existing type libraries when processing a binary file. process_existing_type_libraries: bool, + /// The compiler flags to use when processing header files. + options: Vec, } impl TypeLibProcessor { @@ -448,6 +450,7 @@ impl TypeLibProcessor { default_platform_name: default_platform_name.to_owned(), include_directories: Vec::new(), process_existing_type_libraries: false, + options: Vec::new(), } } @@ -461,6 +464,11 @@ impl TypeLibProcessor { self } + pub fn with_options(mut self, options: Vec) -> Self { + self.options = options; + self + } + /// Whether to process existing type libraries when processing a binary file. /// /// If you open `mymodule.dll` and it imports functions from `kernel32.dll`, any import found @@ -988,7 +996,7 @@ impl TypeLibProcessor { &file_name, &platform, &platform_type_container, - &[], + &self.options, &include_dirs, "", ) From fd2b9191e5cdb602b9667b0915de36e2218e8475 Mon Sep 17 00:00:00 2001 From: xitska Date: Mon, 15 Jun 2026 16:45:47 +0100 Subject: [PATCH 2/4] [BNTL] Implement compiler flags for BNTL CLI --- plugins/bntl_utils/cli/src/create.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/bntl_utils/cli/src/create.rs b/plugins/bntl_utils/cli/src/create.rs index c83f4f8f66..e0bdcaa0dd 100644 --- a/plugins/bntl_utils/cli/src/create.rs +++ b/plugins/bntl_utils/cli/src/create.rs @@ -19,6 +19,9 @@ pub struct CreateArgs { pub include_directories: Vec, #[clap(long)] pub dry_run: bool, + + #[arg(last = true, allow_hyphen_values = true, num_args = 0..)] + compiler_flags: Vec, } impl CreateArgs { @@ -41,7 +44,8 @@ impl CreateArgs { std::fs::create_dir_all(&output_path).expect("Failed to create output directory"); let processor = TypeLibProcessor::new(&self.name, &self.platform) - .with_include_directories(self.include_directories.clone()); + .with_include_directories(self.include_directories.clone()) + .with_options(self.compiler_flags.clone()); // TODO: Need progress indicator here, when downloading files. let resolved_input = self.input.resolve().expect("Failed to resolve input"); From 95d235d09b81a5d541d4c1ecd2e05b9aa6a92b15 Mon Sep 17 00:00:00 2001 From: xitska Date: Tue, 16 Jun 2026 01:19:14 +0100 Subject: [PATCH 3/4] [BNTL] General rename to compile options with bntl_utils --- plugins/bntl_utils/src/command/create.rs | 14 +++++++------- plugins/bntl_utils/src/process.rs | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/bntl_utils/src/command/create.rs b/plugins/bntl_utils/src/command/create.rs index dda61f1f50..01a4adb563 100644 --- a/plugins/bntl_utils/src/command/create.rs +++ b/plugins/bntl_utils/src/command/create.rs @@ -124,19 +124,19 @@ impl PlatformField { } } -pub struct FlagsField; +pub struct CompilerOptionsField; -impl FlagsField { +impl CompilerOptionsField { pub fn field() -> FormInputField { FormInputField::MultilineText { - prompt: "Compiler flags".to_string(), + prompt: "Compiler options".to_string(), default: None, value: None, } } pub fn from_form(form: &Form) -> Option { - let field = form.get_field_with_name("Compiler flags")?; + let field = form.get_field_with_name("Compiler options")?; field.try_value_string() } } @@ -151,7 +151,7 @@ impl CreateFromDirectory { form.add_field(PlatformField::field()); form.add_field(NameField::field()); form.add_field(OutputDirectoryField::field()); - form.add_field(FlagsField::field()); + form.add_field(CompilerOptionsField::field()); if !form.prompt() { return; @@ -160,7 +160,7 @@ impl CreateFromDirectory { let platform_name = PlatformField::from_form(&form).unwrap(); let default_name = NameField::from_form(&form).unwrap(); let output_dir = OutputDirectoryField::from_form(&form).unwrap(); - let flags = FlagsField::from_form(&form).unwrap(); + let flags = CompilerOptionsField::from_form(&form).unwrap(); let Some(default_platform) = Platform::by_name(&platform_name) else { tracing::error!("Invalid platform name: {}", platform_name); @@ -168,7 +168,7 @@ impl CreateFromDirectory { }; let processor = TypeLibProcessor::new(&default_name, &default_platform.name()) - .with_options(split_args(flags.as_str())); + .with_compiler_options(split_args(flags.as_str())); let background_task = BackgroundTask::new("Processing started...", true); new_processing_state_background_thread(background_task.clone(), processor.state()); diff --git a/plugins/bntl_utils/src/process.rs b/plugins/bntl_utils/src/process.rs index cbd7990d4b..7c9d962566 100644 --- a/plugins/bntl_utils/src/process.rs +++ b/plugins/bntl_utils/src/process.rs @@ -435,7 +435,7 @@ pub struct TypeLibProcessor { /// Whether to process existing type libraries when processing a binary file. process_existing_type_libraries: bool, /// The compiler flags to use when processing header files. - options: Vec, + compiler_options: Vec, } impl TypeLibProcessor { @@ -450,7 +450,7 @@ impl TypeLibProcessor { default_platform_name: default_platform_name.to_owned(), include_directories: Vec::new(), process_existing_type_libraries: false, - options: Vec::new(), + compiler_options: Vec::new(), } } @@ -464,8 +464,8 @@ impl TypeLibProcessor { self } - pub fn with_options(mut self, options: Vec) -> Self { - self.options = options; + pub fn with_compiler_options(mut self, options: Vec) -> Self { + self.compiler_options = options; self } @@ -996,7 +996,7 @@ impl TypeLibProcessor { &file_name, &platform, &platform_type_container, - &self.options, + &self.compiler_options, &include_dirs, "", ) From 093bba2907d77735a8b0d00e646e0f2f61764059 Mon Sep 17 00:00:00 2001 From: xitska Date: Tue, 16 Jun 2026 01:23:43 +0100 Subject: [PATCH 4/4] [BNTL] Document compiler_options CLI argument --- plugins/bntl_utils/cli/src/create.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/bntl_utils/cli/src/create.rs b/plugins/bntl_utils/cli/src/create.rs index e0bdcaa0dd..c6d9332f12 100644 --- a/plugins/bntl_utils/cli/src/create.rs +++ b/plugins/bntl_utils/cli/src/create.rs @@ -19,9 +19,9 @@ pub struct CreateArgs { pub include_directories: Vec, #[clap(long)] pub dry_run: bool, - + /// A list of additional compiler options to pass to the compiler when parsing C header files. #[arg(last = true, allow_hyphen_values = true, num_args = 0..)] - compiler_flags: Vec, + compiler_options: Vec, } impl CreateArgs { @@ -45,7 +45,7 @@ impl CreateArgs { let processor = TypeLibProcessor::new(&self.name, &self.platform) .with_include_directories(self.include_directories.clone()) - .with_options(self.compiler_flags.clone()); + .with_compiler_options(self.compiler_options.clone()); // TODO: Need progress indicator here, when downloading files. let resolved_input = self.input.resolve().expect("Failed to resolve input");