From d1ce31d8cf22b7ed7aa995b14d179fd546e8af8b Mon Sep 17 00:00:00 2001 From: 4bb4 <67376761+4bb4@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:29:02 +0200 Subject: [PATCH] Got include to work, but bindgen still errors out --- implot-sys/Cargo.toml | 6 +++++- implot-sys/build.rs | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/implot-sys/Cargo.toml b/implot-sys/Cargo.toml index a880864..41c1abe 100644 --- a/implot-sys/Cargo.toml +++ b/implot-sys/Cargo.toml @@ -8,6 +8,10 @@ license = "MIT/Apache-2.0" categories = ["gui", "external-ffi-bindings"] build = "build.rs" +[dependencies] +imgui-sys = { git = "https://github.com/Gekkio/imgui-rs/", branch = "master" } +imgui = { git = "https://github.com/Gekkio/imgui-rs/", branch = "master" } + [build-dependencies] cc = "1.0" -imgui = { git = "https://github.com/aloucks/imgui-rs/", branch = "export_include" } +bindgen = "0.53.1" diff --git a/implot-sys/build.rs b/implot-sys/build.rs index c6f3bc9..c0bfb24 100644 --- a/implot-sys/build.rs +++ b/implot-sys/build.rs @@ -3,8 +3,9 @@ // This is taken pretty vanilla from // https://github.com/Gekkio/imgui-rs/blob/master/imgui-sys/build.rs // for now, but expected to diverge from that over time. -use std::fs; -use std::io; +use std::{env, fs, io, path::PathBuf}; + +use bindgen; const CPP_FILES: [&str; 2] = [ "third-party/cimplot/cimplot.cpp", @@ -25,6 +26,7 @@ fn assert_file_exists(path: &str) -> io::Result<()> { } fn main() -> io::Result<()> { + // --- Compile cimgui let mut build = cc::Build::new(); build.cpp(true); // Disabled due to linking issues @@ -33,11 +35,10 @@ fn main() -> io::Result<()> { .define("IMGUI_DISABLE_WIN32_FUNCTIONS", None) .define("IMGUI_DISABLE_OSX_FUNCTIONS", None); - // This won't seem to work yet let imgui_third_party = - std::env::var_os("DEP_IMGUI_THIRD_PARTY").expect("No env var found for third_party folder"); + env::var_os("DEP_IMGUI_THIRD_PARTY").expect("No envvar found for third_party"); println!("third party is {:?}", imgui_third_party); - build.include(imgui_third_party); + build.include(imgui_third_party.clone().into_string().unwrap() + "/imgui/"); build.flag_if_supported("-Wno-return-type-c-linkage"); for path in &CPP_FILES { @@ -45,5 +46,22 @@ fn main() -> io::Result<()> { build.file(path); } build.compile("libcimplot.a"); + + // --- Create bindgen bindings + // The actual generate() errors out right now with parsing errors, + // will probably need to whiltelist things, fix preprocessor definitions, + // bindgen settings or some combination thereof. + let _bindings = bindgen::Builder::default() + .header(imgui_third_party.into_string().unwrap() + "/cimgui.h") + .header("wrapper.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks)); + //.generate() + //.expect("Unable to generate bindings"); + + //let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + //bindings + //.write_to_file(out_path.join("bindings.rs")) + //.expect("Couldn't write bindings!"); + Ok(()) }