From 06033f7f630fa49f1a9556a05038460f80338105 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sat, 27 Jun 2020 00:56:47 -0400 Subject: [PATCH 1/2] Export include path and native defines --- imgui-sys/Cargo.toml | 1 + imgui-sys/build.rs | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/imgui-sys/Cargo.toml b/imgui-sys/Cargo.toml index eae1f82..c341f30 100644 --- a/imgui-sys/Cargo.toml +++ b/imgui-sys/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/Gekkio/imgui-rs" license = "MIT/Apache-2.0" categories = ["gui", "external-ffi-bindings"] build = "build.rs" +links = "imgui" [build-dependencies] cc = "1.0" diff --git a/imgui-sys/build.rs b/imgui-sys/build.rs index 2d5c70d..710c476 100644 --- a/imgui-sys/build.rs +++ b/imgui-sys/build.rs @@ -2,6 +2,7 @@ use std::fs; use std::io; +use std::path::Path; const CPP_FILES: [&str; 5] = [ "third-party/cimgui.cpp", @@ -11,6 +12,13 @@ const CPP_FILES: [&str; 5] = [ "third-party/imgui/imgui_widgets.cpp", ]; +const DEFINES: &[(&str, Option<&str>)] = &[ + // Disabled due to linking issues + ("CIMGUI_NO_EXPORT", None), + ("IMGUI_DISABLE_WIN32_FUNCTIONS", None), + ("IMGUI_DISABLE_OSX_FUNCTIONS", None), +]; + fn assert_file_exists(path: &str) -> io::Result<()> { match fs::metadata(path) { Ok(_) => Ok(()), @@ -25,15 +33,18 @@ fn assert_file_exists(path: &str) -> io::Result<()> { } fn main() -> io::Result<()> { + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + println!("cargo:THIRD_PARTY={}", manifest_dir.join("third-party").display()); + for (key, value) in DEFINES.iter() { + println!("cargo:DEFINE_{}={}", key, value.unwrap_or("")); + } #[cfg(not(feature = "wasm"))] { 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); + for (key, value) in DEFINES.iter() { + build.define(key, *value); + } build.flag_if_supported("-Wno-return-type-c-linkage"); for path in &CPP_FILES { From c0ba921a0d14311c35cc22a67c3ddeeb73d86ce3 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sat, 27 Jun 2020 13:09:53 -0400 Subject: [PATCH 2/2] Run cargo fmt --- imgui-sys/build.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/imgui-sys/build.rs b/imgui-sys/build.rs index 710c476..a449e76 100644 --- a/imgui-sys/build.rs +++ b/imgui-sys/build.rs @@ -34,7 +34,10 @@ fn assert_file_exists(path: &str) -> io::Result<()> { fn main() -> io::Result<()> { let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); - println!("cargo:THIRD_PARTY={}", manifest_dir.join("third-party").display()); + println!( + "cargo:THIRD_PARTY={}", + manifest_dir.join("third-party").display() + ); for (key, value) in DEFINES.iter() { println!("cargo:DEFINE_{}={}", key, value.unwrap_or("")); }