Skip to content

Commit

Permalink
Merge pull request #210 from trobanga/master
Browse files Browse the repository at this point in the history
Add llvm-compiler-opts as command-line argument
  • Loading branch information
fzyzcjy authored Nov 25, 2021
2 parents e1a5aec + 564dd44 commit b9f85cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.7.0

* Add llvm-compiler-opts as command-line argument #210 (thanks @trobanga)

## 1.6.1

* Remove extra newline on empty comment #203 (thanks @Desdaemon)
Expand Down
19 changes: 18 additions & 1 deletion frb_codegen/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ pub fn bindgen_rust_to_dart(
dart_class_name: &str,
c_struct_names: Vec<String>,
llvm_install_path: &str,
llvm_compiler_opts: &str,
) {
cbindgen(rust_crate_dir, c_output_path, c_struct_names);
ffigen(
c_output_path,
dart_output_path,
dart_class_name,
llvm_install_path,
llvm_compiler_opts,
);
}

Expand Down Expand Up @@ -129,7 +131,13 @@ include = [{}]
);
}

fn ffigen(c_path: &str, dart_path: &str, dart_class_name: &str, llvm_path: &str) {
fn ffigen(
c_path: &str,
dart_path: &str,
dart_class_name: &str,
llvm_path: &str,
llvm_compiler_opts: &str,
) {
debug!(
"execute ffigen c_path={} dart_path={} llvm_path={:?}",
c_path, dart_path, llvm_path
Expand Down Expand Up @@ -159,6 +167,15 @@ fn ffigen(c_path: &str, dart_path: &str, dart_class_name: &str, llvm_path: &str)
);
}

if !llvm_compiler_opts.is_empty() {
config = format!(
"{}
compiler-opts:
- '{}'",
config, llvm_compiler_opts
);
}

debug!("ffigen config: {}", config);

let mut config_file = tempfile::NamedTempFile::new().unwrap();
Expand Down
5 changes: 5 additions & 0 deletions frb_codegen/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct RawOpts {
/// Path to the installed LLVM
#[structopt(long)]
pub llvm_path: Option<String>,
/// LLVM compiler opts
#[structopt(long)]
pub llvm_compiler_opts: Option<String>,
}

#[derive(Debug)]
Expand All @@ -53,6 +56,7 @@ pub struct Opts {
pub dart_format_line_length: i32,
pub skip_add_mod_to_lib: bool,
pub llvm_path: String,
pub llvm_compiler_opts: String,
}

pub fn parse(raw: RawOpts) -> Opts {
Expand Down Expand Up @@ -85,6 +89,7 @@ pub fn parse(raw: RawOpts) -> Opts {
dart_format_line_length: raw.dart_format_line_length.unwrap_or(80),
skip_add_mod_to_lib: raw.skip_add_mod_to_lib,
llvm_path: raw.llvm_path.unwrap_or_else(|| "".to_string()),
llvm_compiler_opts: raw.llvm_compiler_opts.unwrap_or_else(|| "".to_string()),
}
}

Expand Down
1 change: 1 addition & 0 deletions frb_codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn main() {
&config.dart_wire_class_name(),
c_struct_names,
&config.llvm_path,
&config.llvm_compiler_opts,
);
},
);
Expand Down

0 comments on commit b9f85cb

Please sign in to comment.