make build.rs prettier
This commit is contained in:
parent
f96f1cf95e
commit
599c783d01
2 changed files with 43 additions and 58 deletions
|
|
@ -24,6 +24,7 @@
|
||||||
allowUnfree = false;
|
allowUnfree = false;
|
||||||
allowBroken = false;
|
allowBroken = false;
|
||||||
overlays = builtins.attrValues self.overlays or {};
|
overlays = builtins.attrValues self.overlays or {};
|
||||||
|
# config.replaceStdenv = {pkgs}: with pkgs; llvmPackages_21.stdenv;
|
||||||
};
|
};
|
||||||
|
|
||||||
forAllSystems = f:
|
forAllSystems = f:
|
||||||
|
|
@ -60,13 +61,19 @@
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
rustc
|
rustc
|
||||||
llvmPackages.lld
|
llvmPackages.lld
|
||||||
lldb
|
llvmPackages.lldb
|
||||||
|
# lldb
|
||||||
|
|
||||||
cargo
|
cargo
|
||||||
cargo-c
|
cargo-c
|
||||||
cargo-llvm-cov
|
cargo-llvm-cov
|
||||||
cargo-nextest
|
cargo-nextest
|
||||||
|
|
||||||
|
clang # DEBUG
|
||||||
|
clang-tools # DEBUG
|
||||||
|
|
||||||
|
libcxx
|
||||||
|
|
||||||
rust-analyzer-unwrapped
|
rust-analyzer-unwrapped
|
||||||
(rustfmt.override {asNightly = true;})
|
(rustfmt.override {asNightly = true;})
|
||||||
clippy
|
clippy
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::{env, fs};
|
||||||
|
|
||||||
use bindgen::callbacks::ParseCallbacks;
|
use bindgen::callbacks::ParseCallbacks;
|
||||||
|
|
||||||
|
|
@ -18,31 +18,26 @@ impl ParseCallbacks for DoxygenCallbacks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LIBS: &[&'static str] = &[
|
||||||
|
#[cfg(feature = "nix-util-c")]
|
||||||
|
"nix-util-c",
|
||||||
|
#[cfg(feature = "nix-store-c")]
|
||||||
|
"nix-store-c",
|
||||||
|
#[cfg(feature = "nix-expr-c")]
|
||||||
|
"nix-expr-c",
|
||||||
|
#[cfg(feature = "nix-fetchers-c")]
|
||||||
|
"nix-fetchers-c",
|
||||||
|
#[cfg(feature = "nix-flake-c")]
|
||||||
|
"nix-flake-c",
|
||||||
|
#[cfg(feature = "nix-main-c")]
|
||||||
|
"nix-main-c",
|
||||||
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Invalidate the built crate whenever the wrapper changes
|
// Invalidate the built crate if the binding headers change
|
||||||
println!("cargo::rerun-if-changed=include/nix-util.h");
|
// println!("cargo::rerun-if-changed=include");
|
||||||
println!("cargo::rerun-if-changed=include/nix-store.h");
|
|
||||||
println!("cargo::rerun-if-changed=include/nix-expr.h");
|
|
||||||
println!("cargo::rerun-if-changed=include/nix-fetchers.h");
|
|
||||||
println!("cargo::rerun-if-changed=include/nix-flake.h");
|
|
||||||
println!("cargo::rerun-if-changed=include/nix-main.h");
|
|
||||||
|
|
||||||
let libs = [
|
let lib_args: Vec<String> = LIBS
|
||||||
#[cfg(feature = "nix-util-c")]
|
|
||||||
"nix-util-c",
|
|
||||||
#[cfg(feature = "nix-store-c")]
|
|
||||||
"nix-store-c",
|
|
||||||
#[cfg(feature = "nix-expr-c")]
|
|
||||||
"nix-expr-c",
|
|
||||||
#[cfg(feature = "nix-fetchers-c")]
|
|
||||||
"nix-fetchers-c",
|
|
||||||
#[cfg(feature = "nix-flake-c")]
|
|
||||||
"nix-flake-c",
|
|
||||||
#[cfg(feature = "nix-main-c")]
|
|
||||||
"nix-main-c",
|
|
||||||
];
|
|
||||||
|
|
||||||
let lib_args: Vec<String> = libs
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&name| {
|
.map(|&name| {
|
||||||
let lib = pkg_config::probe_library(name)
|
let lib = pkg_config::probe_library(name)
|
||||||
|
|
@ -57,52 +52,35 @@ fn main() {
|
||||||
.map(|p| format!("-I{}", p.display()))
|
.map(|p| format!("-I{}", p.display()))
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
|
.chain(vec!["-Wall".to_owned(), "-xc++".to_owned()])
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut builder = bindgen::Builder::default()
|
let mut builder = bindgen::Builder::default()
|
||||||
|
// .clang_arg("") // libnix uses c++23
|
||||||
.clang_args(lib_args)
|
.clang_args(lib_args)
|
||||||
// Invalidate the built crate when an included header file changes
|
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||||
// Add `doxygen_bindgen` callbacks
|
// Add `doxygen_bindgen` callbacks
|
||||||
.parse_callbacks(Box::new(DoxygenCallbacks))
|
.parse_callbacks(Box::new(DoxygenCallbacks))
|
||||||
// Format generated bindings with rustfmt
|
// Format generated bindings with rustfmt
|
||||||
.formatter(bindgen::Formatter::Rustfmt)
|
.formatter(bindgen::Formatter::Rustfmt)
|
||||||
.rustfmt_configuration_file(std::fs::canonicalize(".rustfmt.toml").ok());
|
.rustfmt_configuration_file(std::fs::canonicalize("rustfmt.toml").ok());
|
||||||
|
|
||||||
// The input headers we would like to generate bindings for
|
// Register the input headers we would like to generate bindings for
|
||||||
#[cfg(feature = "nix-util-c")]
|
builder = LIBS
|
||||||
{
|
.iter()
|
||||||
builder = builder.header("include/nix-util.h")
|
.map(|lib| {
|
||||||
}
|
let path = format!("include/{}.h", lib.strip_suffix("-c").unwrap());
|
||||||
#[cfg(feature = "nix-store-c")]
|
assert!(fs::exists(&path).unwrap());
|
||||||
{
|
// Invalidate the built crate if the binding headers change
|
||||||
builder = builder.header("include/nix-store.h")
|
// println!("cargo::rerun-if-changed={path}");
|
||||||
}
|
path
|
||||||
#[cfg(feature = "nix-expr-c")]
|
})
|
||||||
{
|
.fold(builder, |builder, path| builder.header(path));
|
||||||
builder = builder.header("include/nix-expr.h")
|
|
||||||
}
|
|
||||||
#[cfg(feature = "nix-fetchers-c")]
|
|
||||||
{
|
|
||||||
builder = builder.header("include/nix-fetchers.h")
|
|
||||||
}
|
|
||||||
#[cfg(feature = "nix-flake-c")]
|
|
||||||
{
|
|
||||||
builder = builder.header("include/nix-flake.h")
|
|
||||||
}
|
|
||||||
#[cfg(feature = "nix-main-c")]
|
|
||||||
{
|
|
||||||
builder = builder.header("include/nix-main.h")
|
|
||||||
}
|
|
||||||
|
|
||||||
let bindings = builder
|
|
||||||
// Finish the builder and generate the bindings
|
|
||||||
.generate()
|
|
||||||
// Unwrap the Result and panic on failure
|
|
||||||
.expect("Unable to generate bindings");
|
|
||||||
|
|
||||||
// Write the bindings to the $OUT_DIR/bindings.rs file
|
// Write the bindings to the $OUT_DIR/bindings.rs file
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
|
|
||||||
|
let bindings = builder.generate().expect("Unable to generate bindings");
|
||||||
bindings
|
bindings
|
||||||
.write_to_file(out_path.join("bindings.rs"))
|
.write_to_file(out_path.join("bindings.rs"))
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue