Automated the work from #16
This commit is contained in:
parent
3c30e3f919
commit
5779f7e6d6
6 changed files with 69 additions and 958 deletions
|
@ -5,5 +5,5 @@ authors = ["Sandro Merkli"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bindgen = "0.55.1"
|
||||
bindgen = "0.57"
|
||||
imgui-sys = { version = "=0.6.0" }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bindgen::{Builder, CargoCallbacks};
|
||||
use std::{env, path::PathBuf};
|
||||
use std::{env, io::Write, path::PathBuf};
|
||||
|
||||
// All this crate does is run bindgen on cimplot and store the result
|
||||
// in the src folder of the implot-sys crate. We add those bindings
|
||||
|
@ -34,13 +34,39 @@ fn main() {
|
|||
)
|
||||
.parse_callbacks(Box::new(CargoCallbacks))
|
||||
.clang_arg("-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1")
|
||||
// Reuse the imgui types that implot requires from imgui_sys so we don't define
|
||||
// our own new types.
|
||||
.raw_line("pub use imgui_sys::{ImVec2, ImVec4, ImGuiCond, ImTextureID};")
|
||||
.raw_line("pub use imgui_sys::{ImGuiContext, ImGuiKeyModFlags, ImDrawList};")
|
||||
.raw_line("pub use imgui_sys::{ImGuiMouseButton, ImGuiDragDropFlags};")
|
||||
.whitelist_recursively(false)
|
||||
.whitelist_function("ImPlot.*")
|
||||
.whitelist_type("ImPlot.*")
|
||||
// We do want to create bindings for the scalar typedefs
|
||||
.whitelist_type("Im[U|S][0-9]{1,2}")
|
||||
// Remove some functions that would take a variable-argument list
|
||||
.blacklist_function("ImPlot_AnnotateVVec4")
|
||||
.blacklist_function("ImPlot_AnnotateVStr")
|
||||
.blacklist_function("ImPlot_AnnotateClampedVVec4")
|
||||
.blacklist_function("ImPlot_AnnotateClampedVStr")
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
// The above type re-export shenanigans make bindgen unable to derive Copy, Clone and Debug on
|
||||
// some types, but they would work - we hence manually re-add them here.
|
||||
let mut bindings_string = bindings.to_string();
|
||||
["ImPlotInputMap", "ImPlotStyle"].iter().for_each(|name| {
|
||||
bindings_string = bindings_string.replace(
|
||||
&format!("pub struct {}", name),
|
||||
&format!("#[derive(Clone, Copy, Debug)]\npub struct {}", name),
|
||||
);
|
||||
});
|
||||
|
||||
// Finally we write the bindings to a file.
|
||||
let out_path = sys_crate_path.join("src");
|
||||
bindings
|
||||
.write_to_file(&out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
let mut out_file =
|
||||
std::fs::File::create(&out_path.join("bindings.rs")).expect("Could not open bindings file");
|
||||
out_file
|
||||
.write_all(&bindings_string.into_bytes()[..])
|
||||
.expect("Couldn't write bindings");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue