diff --git a/implot-sys/build.rs b/implot-sys/build.rs index c0bfb24..593df07 100644 --- a/implot-sys/build.rs +++ b/implot-sys/build.rs @@ -3,9 +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::{env, fs, io, path::PathBuf}; +use std::{env, fs, io, path::Path}; -use bindgen; +//use bindgen; // Not used anymore, TODO(4bb4) remove const CPP_FILES: [&str; 2] = [ "third-party/cimplot/cimplot.cpp", @@ -29,36 +29,47 @@ fn main() -> io::Result<()> { // --- Compile cimgui let mut build = cc::Build::new(); build.cpp(true); - // Disabled due to linking issues - build - .define("CIMGUI_NO_EXPORT", None) - .define("IMGUI_DISABLE_WIN32_FUNCTIONS", None) - .define("IMGUI_DISABLE_OSX_FUNCTIONS", None); - let imgui_third_party = - 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.clone().into_string().unwrap() + "/imgui/"); + // Take over imgui preprocessor defines from the imgui-sys crate. + // Taken from https://github.com/aloucks/imguizmo-rs/blob/master/imguizmo-sys/build.rs + for (key, val) in env::vars().filter(|(key, _)| key.starts_with("DEP_IMGUI_DEFINE_")) { + let key = key.trim_start_matches("DEP_IMGUI_DEFINE_"); + let val = if !val.is_empty() { + Some(val.as_str()) + } else { + None + }; + build.define(key, val); + } + let cimgui_include_path = + env::var_os("DEP_IMGUI_THIRD_PARTY").expect("DEP_IMGUI_THIRD_PARTY not defined"); + let imgui_include_path = Path::new(&cimgui_include_path).join("imgui"); + build.include(cimgui_include_path); + build.include(imgui_include_path); + + // Taken from the imgui-sys build as well build.flag_if_supported("-Wno-return-type-c-linkage"); for path in &CPP_FILES { assert_file_exists(path)?; build.file(path); } - build.compile("libcimplot.a"); + + build.compile("cimplot"); // --- Create bindgen bindings + // TODO(4bb4) move this out to separate shell script (see #1) // 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)); + //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()); + //let out_path = std::path::PathBuf::from(env::var("OUT_DIR").unwrap()); //bindings //.write_to_file(out_path.join("bindings.rs")) //.expect("Couldn't write bindings!");