diff --git a/Cargo.toml b/Cargo.toml index a3cc9f2..075858b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ publish = false [lib] name = "physis" -crate-type = ["staticlib"] +crate-type = ["cdylib", "staticlib"] [profile.release] lto = true @@ -21,7 +21,8 @@ lto = true cbindgen = { version = "0.26.0", default-features = false } [features] -default = ["visual_data"] +default = ["visual_data", "logging"] +logging = [] game_install = ["physis/game_install"] visual_data = ["physis/visual_data"] diff --git a/build.rs b/build.rs index 6b0fdb0..d096a4c 100644 --- a/build.rs +++ b/build.rs @@ -4,6 +4,12 @@ extern crate cbindgen; use std::env; +use std::fs; +use std::io::BufWriter; +use std::io::BufReader; +use std::fs::File; +use std::io::Write; +use std::io::BufRead; use cbindgen::Language; @@ -15,6 +21,7 @@ fn main() { .with_parse_deps(true) .with_parse_include(&["physis"]) .with_language(Language::C) + .with_define("feature", "logging", "ENABLE_LOGGING") .generate() .expect("Unable to generate C bindings") .write_to_file("target/public/physis.h"); @@ -25,7 +32,26 @@ fn main() { .with_parse_include(&["physis"]) .with_language(Language::Cxx) .with_pragma_once(true) + .with_define("feature", "logging", "ENABLE_LOGGING") .generate() .expect("Unable to generate C++ bindings") .write_to_file("target/public/physis.hpp"); + + // cbindgen always includes and even if they aren't used + // some downstream projects like PhysisSharp need to have a cleaner file + { + let mut file: File = File::open("target/public/physis.hpp").unwrap(); + let mut out_file: File = File::create("target/public/physis.hpp.temp").unwrap(); + + let reader = BufReader::new(&file); + let mut writer = BufWriter::new(&out_file); + + for (index, line) in reader.lines().enumerate() { + let line = line.as_ref().unwrap(); + if !line.contains("#include ") && !line.contains("#include ") { + writeln!(writer, "{}", line); + } + } + } + fs::rename("target/public/physis.hpp.temp", "target/public/physis.hpp").unwrap(); } diff --git a/src/lib.rs b/src/lib.rs index aae0dd1..32aa267 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,4 +137,5 @@ mod dic; mod index; +#[cfg(feature = "logging")] mod logging;