From 0d7146cb391b0faa5a8107729ad29f7292d81081 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 7 Mar 2024 10:56:24 +0100 Subject: [PATCH] feat: nix-c-raw: Generate value api bindings (cherry picked from commit 3c75dea63233670863f30547f90dd71498d547b0) --- flake.nix | 2 ++ rust/nix-c-raw/build.rs | 7 +++++++ rust/nix-c-raw/include/nix-c-raw.h | 1 + 3 files changed, 10 insertions(+) diff --git a/flake.nix b/flake.nix index 35d15f4..3b14cd2 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,8 @@ buildInputs = [ config.packages.nix ]; + # Workaround: the gcc in the devshell doesn't find libc headers + RUST_NIX_C_RAW_EXTRA_CFLAGS = "-I${pkgs.stdenv.cc.libc.dev}/include"; nativeBuildInputs = [ pkgs.rust-analyzer pkgs.nixpkgs-fmt diff --git a/rust/nix-c-raw/build.rs b/rust/nix-c-raw/build.rs index d8c6679..ae37b02 100644 --- a/rust/nix-c-raw/build.rs +++ b/rust/nix-c-raw/build.rs @@ -36,6 +36,13 @@ fn c_headers() -> Vec { { args.push(format!("-I{}", path.to_str().unwrap())); } + + if let Ok(cflags) = std::env::var("RUST_NIX_C_RAW_EXTRA_CFLAGS") { + for flag in cflags.split_whitespace() { + args.push(flag.to_string()); + } + } + // write to stderr for debugging eprintln!("c_headers: {:?}", args); args diff --git a/rust/nix-c-raw/include/nix-c-raw.h b/rust/nix-c-raw/include/nix-c-raw.h index 81883f6..129181e 100644 --- a/rust/nix-c-raw/include/nix-c-raw.h +++ b/rust/nix-c-raw/include/nix-c-raw.h @@ -1,3 +1,4 @@ #include #include #include +#include