Added a separate bindgen building crate and pre-generated bindings
This commit is contained in:
parent
c1ccb4eb6f
commit
0f11df5989
7 changed files with 10072 additions and 24 deletions
12
implot-sys-bindgen/Cargo.toml
Normal file
12
implot-sys-bindgen/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "implot-sys-bindgen"
|
||||
version = "0.1.0"
|
||||
authors = ["Sandro Merkli"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bindgen = "0.53.1"
|
||||
imgui-sys = { git = "https://github.com/Gekkio/imgui-rs/", branch = "master" }
|
||||
imgui = { git = "https://github.com/Gekkio/imgui-rs/", branch = "master" }
|
16
implot-sys-bindgen/build.rs
Normal file
16
implot-sys-bindgen/build.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// We just forward the DEP_IMGUI_THIRD_PARTY variable here because the
|
||||
// main function outside the build script does not actually see it
|
||||
let cimgui_include_path =
|
||||
env::var_os("DEP_IMGUI_THIRD_PARTY").expect("DEP_IMGUI_THIRD_PARTY not defined");
|
||||
println!(
|
||||
"cargo:rustc-env=DEP_IMGUI_THIRD_PARTY={}",
|
||||
cimgui_include_path
|
||||
.to_str()
|
||||
.expect("Could not turn cimgui include path to string")
|
||||
);
|
||||
}
|
44
implot-sys-bindgen/src/main.rs
Normal file
44
implot-sys-bindgen/src/main.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use bindgen::{Builder, CargoCallbacks};
|
||||
use std::{env, 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
|
||||
// to git so people don't have to install clang just to use implot-rs.
|
||||
|
||||
fn main() {
|
||||
let cwd = env::current_dir().expect("Could not read current directory");
|
||||
let sys_crate_path = cwd
|
||||
.join("..")
|
||||
.join("implot-sys")
|
||||
.canonicalize()
|
||||
.expect("Could not find sys crate directory");
|
||||
|
||||
let cimgui_include_path = PathBuf::from(
|
||||
env::var_os("DEP_IMGUI_THIRD_PARTY").expect("DEP_IMGUI_THIRD_PARTY not defined"),
|
||||
);
|
||||
|
||||
let bindings = Builder::default()
|
||||
.header(
|
||||
cimgui_include_path
|
||||
.join("cimgui.h")
|
||||
.to_str()
|
||||
.expect("Could not convert cimgui.h path to string"),
|
||||
)
|
||||
.header(
|
||||
sys_crate_path
|
||||
.join("third-party")
|
||||
.join("cimplot")
|
||||
.join("cimplot.h")
|
||||
.to_str()
|
||||
.expect("Could not turn cimplot.h path into string"),
|
||||
)
|
||||
.parse_callbacks(Box::new(CargoCallbacks))
|
||||
.clang_arg("-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1")
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
let out_path = sys_crate_path.join("src");
|
||||
bindings
|
||||
.write_to_file(&out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue