From 42adfb57fb994539026abaaa614489dc5ade81b2 Mon Sep 17 00:00:00 2001 From: 4bb4 <67376761+4bb4@users.noreply.github.com> Date: Thu, 2 Jul 2020 21:15:22 +0200 Subject: [PATCH] Added submodule for cimplot and some build code This points to aloucks' fork instead of imgui-rs directly so I can try out the PR. Doesn't seem to work as expected yet though, trying to read the env var doesn't show anything. I'm probably doing it wrong. --- .gitmodules | 3 +++ implot-sys/Cargo.toml | 1 + implot-sys/build.rs | 45 +++++++++++++++++++++++++++++++++- implot-sys/third-party/cimplot | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 implot-sys/third-party/cimplot diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c209daf --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "implot-sys/third-party/cimplot"] + path = implot-sys/third-party/cimplot + url = https://github.com/cimgui/cimplot diff --git a/implot-sys/Cargo.toml b/implot-sys/Cargo.toml index 2892dee..a880864 100644 --- a/implot-sys/Cargo.toml +++ b/implot-sys/Cargo.toml @@ -10,3 +10,4 @@ build = "build.rs" [build-dependencies] cc = "1.0" +imgui = { git = "https://github.com/aloucks/imgui-rs/", branch = "export_include" } diff --git a/implot-sys/build.rs b/implot-sys/build.rs index a1967b0..c6f3bc9 100644 --- a/implot-sys/build.rs +++ b/implot-sys/build.rs @@ -1,6 +1,49 @@ +#![allow(dead_code)] + +// 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; +const CPP_FILES: [&str; 2] = [ + "third-party/cimplot/cimplot.cpp", + "third-party/cimplot/implot/implot.cpp", +]; + +fn assert_file_exists(path: &str) -> io::Result<()> { + match fs::metadata(path) { + Ok(_) => Ok(()), + Err(ref e) if e.kind() == io::ErrorKind::NotFound => { + panic!( + "Can't access {}. Did you forget to fetch git submodules?", + path + ); + } + Err(e) => Err(e), + } +} + fn main() -> io::Result<()> { - // Does nothing yet + 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); + + // 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"); + println!("third party is {:?}", imgui_third_party); + build.include(imgui_third_party); + + 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"); Ok(()) } diff --git a/implot-sys/third-party/cimplot b/implot-sys/third-party/cimplot new file mode 160000 index 0000000..929f61d --- /dev/null +++ b/implot-sys/third-party/cimplot @@ -0,0 +1 @@ +Subproject commit 929f61d27b8b4e3c899b2a386679a7f4a82826ce