Replies: 1 comment 17 replies
-
So I refactored to workaround this problem (a couple more FFI calls) but it seems that the generated C code also has lots of duplicate symbols which appears to make it impossible to use multiple modules as per the example. I tried following the information here: https://cjycode.com/flutter_rust_bridge/article/generate_multiple_files.html but I don't think there is anything in there that will help. My use lib_flutter_rust_bridge_codegen::{
config_parse, frb_codegen_multi, get_symbols_if_no_duplicates,
init_logger, RawOpts,
};
/// Path of input Rust code
const RUST_INPUT_API: &str = "src/api.rs";
const RUST_INPUT_NET: &str = "src/network/api.rs";
/// Path of output generated Dart code
const DART_OUTPUT_API: &str = "../lib/ffi/api_generated.dart";
const DART_OUTPUT_NET: &str = "../lib/ffi/net_generated.dart";
/// Path of output Rust code
const RUST_OUTPUT_API: &str = "src/api_generated.rs";
const RUST_OUTPUT_NET: &str = "src/net_generated.rs";
/// Class name to use in dart, corresponding to each Rust block
const CLASS_NAME_API: &str = "SosNativeBindings";
const CLASS_NAME_NET: &str = "SosNetworkBindings";
fn main() {
init_logger("./logs/", true).unwrap();
// Tell Cargo that if the input Rust code changes,
// to rerun this build script.
println!("cargo:rerun-if-changed={RUST_INPUT_API}");
println!("cargo:rerun-if-changed={RUST_INPUT_NET}");
// Options for frb_codegen
let raw_opts = RawOpts {
// Path of input Rust code
rust_input: vec![
RUST_INPUT_API.to_string(),
RUST_INPUT_NET.to_string(),
],
// Path of output generated Dart code
dart_output: vec![
DART_OUTPUT_API.to_string(),
DART_OUTPUT_NET.to_string(),
],
// Path of output Rust code
rust_output: Some(vec![
RUST_OUTPUT_API.to_string(),
RUST_OUTPUT_NET.to_string(),
]),
//dart_decl_output: Some("../lib/def_generated.dart".to_string()),
wasm: false,
// Class name of each Rust block of api
class_name: Some(vec![
CLASS_NAME_API.to_string(),
CLASS_NAME_NET.to_string(),
]),
c_output: Some(vec![
"../macos/Runner/api_generated.h".into(),
"../macos/Runner/net_generated.h".into(),
]),
extra_c_output_path: Some(vec![
"../ios/Runner/".into(),
"../ios/Runner/".into(),
]),
dart_format_line_length: 80,
..Default::default()
};
// get opts from raw opts
let configs = config_parse(raw_opts);
// generation of rust api for ffi (multi-blocks)
let all_symbols = get_symbols_if_no_duplicates(&configs).unwrap();
for config_index in 0..configs.len() {
frb_codegen_multi(&configs, config_index, &all_symbols).unwrap()
}
} And there are many errors compiling with the duplicate symbols, for example:
Any help would be really appreciated, thanks 🙏 |
Beta Was this translation helpful? Give feedback.
17 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
My project was getting quite large so I refactored to use multiple APIs and classes starting from the
build.rs
in the example. Thanks!However, I need to share some types between the modules (they are called
api
andnet
) but if I reference a type in both modules theIntoDart
implementations are declared twice:Is there a strategy I can use to resolve this?
Thanks for any help or advice 🙏
Beta Was this translation helpful? Give feedback.
All reactions