cloudpeers / ffi-gen

Call rust from any language.
20 stars 5 forks source link

Multiple .rsh file support #70

Open canewsin opened 2 years ago

canewsin commented 2 years ago

Screenshot 2022-02-23 215433

build.rs


fn main() {
    let dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
    let bind_path = dir.join("bindings");
    let bindings = [
        bind_path.join("cryptography.rsh"),
        bind_path.join("discovery.rsh"),
        bind_path.join("protocol.rsh"),
    ];

    for path in bindings.iter() {
        let path_str = path.as_path().to_str().unwrap();
        let name = path
            .file_name()
            .unwrap()
            .to_str()
            .unwrap()
            .replacen(".rsh", "", 1);
        print!("{path_str}");
        println!("cargo:rerun-if-changed={}", path_str);
        let ffigen = FfiGen::new(&path).unwrap();
        let dart = dir
            .join("bindings")
            .join("dart")
            .join(format!("bindings_{name}.g.dart"));
        ffigen.generate_dart(dart, "zn", "zn_ffi").unwrap();
    }
}

Error Log on

cargo build


error: symbol `allocate` is already defined
--> src\discovery\mod.rs:7:1
|
7 | ffi_gen_macro::ffi_gen!("bindings/discovery.rsh");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `ffi_gen_macro::ffi_gen_native_64` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: zn_ffi (lib) generated 6 warnings error: could not compile zn_ffi due to previous error; 6 warnings emitted