working sys level bindings :yippie:
This commit is contained in:
parent
4508aeab76
commit
e9022e675b
12 changed files with 3091 additions and 45 deletions
|
|
@ -1,6 +1,5 @@
|
|||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use bindgen::callbacks::ParseCallbacks;
|
||||
|
||||
|
|
@ -24,7 +23,7 @@ fn main() {
|
|||
println!("cargo:rerun-if-changed=include/wrapper.h");
|
||||
|
||||
// Tell cargo to tell rustc to link the system shared library
|
||||
println!("cargo:rustc-link-lib=bz2");
|
||||
// println!("cargo:rustc-link-lib=bz2");
|
||||
|
||||
// Use pkg-config to find nix-store include and link paths
|
||||
// This NEEDS to be included, or otherwise `nix_api_store.h` cannot
|
||||
|
|
@ -37,32 +36,23 @@ fn main() {
|
|||
"nix-flake-c",
|
||||
];
|
||||
|
||||
// Add all pkg-config include paths and GCC's include path to bindgen
|
||||
let mut args = Vec::new();
|
||||
for nix_lib in libs {
|
||||
let lib = pkg_config::probe_library(nix_lib)
|
||||
.expect(&format!("Unable to find .pc file for {}", nix_lib));
|
||||
|
||||
for include_path in lib.include_paths {
|
||||
args.push(format!("-I{}", incloude_path.display()));
|
||||
// builder = builder.clang_arg(format!("-I{}", include_path.display()));
|
||||
}
|
||||
for link_file in lib.link_files {
|
||||
println!("cargo:rustc-link-lib={}", link_file.display());
|
||||
}
|
||||
}
|
||||
let lib_args: Vec<String> = libs
|
||||
.iter()
|
||||
.map(|&name| {
|
||||
let lib = pkg_config::probe_library(name)
|
||||
.expect(&format!("Unable to find .pc file for {}", name));
|
||||
|
||||
let lib_args = libs.map(|name| {
|
||||
let lib = pkg_config::probe_library(name)
|
||||
.expect(&format!("Unable to find .pc file for {}", nix_lib));
|
||||
for p in lib.link_files {
|
||||
println!("cargo:rustc-link-lib={}", p.display());
|
||||
}
|
||||
|
||||
lib.include_paths
|
||||
.into_iter()
|
||||
.map(|p| format!("-I{}", p.display()))
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
for p in lib.link_files {
|
||||
println!("cargo:rustc-link-lib={}", p.display());
|
||||
}
|
||||
|
||||
lib.include_paths.map(|p| format!("-I{}", p.display()))
|
||||
}).flatten();
|
||||
|
||||
let bindings = bindgen::Builder::default()
|
||||
.clang_args(lib_args)
|
||||
// The input header we would like to generate bindings for
|
||||
|
|
@ -73,7 +63,7 @@ fn main() {
|
|||
.parse_callbacks(Box::new(DoxygenCallbacks))
|
||||
// Format generated bindings with rustfmt
|
||||
.formatter(bindgen::Formatter::Rustfmt)
|
||||
.rustfmt_configuration_file(std::fs::canonicalize(".rustfmt.toml").ok());
|
||||
.rustfmt_configuration_file(std::fs::canonicalize(".rustfmt.toml").ok())
|
||||
// Finish the builder and generate the bindings
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue