// Copyright (C) 2020 Éloïs SANCHEZ. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . use dart_bindgen::{config::*, Codegen}; fn main() { let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let config = cbindgen::Config { language: cbindgen::Language::C, braces: cbindgen::Braces::SameLine, cpp_compat: true, style: cbindgen::Style::Both, ..Default::default() }; cbindgen::Builder::new() .with_crate(crate_dir) .with_config(config) .generate() .expect("Unable to generate bindings") .write_to_file("binding.h"); let config = DynamicLibraryConfig { ios: DynamicLibraryCreationMode::Executable.into(), android: DynamicLibraryCreationMode::open("libdubp_rs.so").into(), ..Default::default() }; // load the c header file, with config and lib name let codegen = Codegen::builder() .with_src_header("binding.h") .with_lib_name("libdubp") .with_config(config) .with_allo_isolate() .build() .unwrap(); // generate the dart code and get the bindings back let bindings = codegen.generate().unwrap(); // write the bindings to your dart package // and start using it to write your own high level abstraction. bindings .write_to_file("../../packages/dubp_rs/lib/ffi.dart") .unwrap(); }