From 40f62bf808879ca5a0b63c0e5a8d736b0003e67b Mon Sep 17 00:00:00 2001 From: George Thomas Date: Mon, 13 Apr 2026 23:22:46 +0100 Subject: [PATCH] Specify include directories via environment variable --- flake.nix | 6 ++++++ lib/GarnetRs/Raw.hs | 10 +--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index 97a8fe7..bb59f53 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,10 @@ targets = [ "x86_64-unknown-linux-gnu" ]; } )); + addLibcIncludeDir = + '' + export C_INCLUDE_PATH="${pkgs.stdenv.cc.libc.dev}/include''${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}" + ''; haskell = (import inputs.nix-haskell { inherit system inputs; } { name = "garnet"; src = ./.; @@ -44,6 +48,7 @@ libs = [ pkgs.llvmPackages.libclang ]; }; packages.garnet.components.library = { + preBuild = addLibcIncludeDir; preConfigure = '' mkdir -p rust/target/debug ln -s ${garnet-rs}/include/garnet_rs.h rust/target/debug/garnet_rs.h @@ -70,6 +75,7 @@ }; withHoogle = false; withHaddock = true; + shellHook = addLibcIncludeDir; }; }); garnet-rs = crane.buildPackage { diff --git a/lib/GarnetRs/Raw.hs b/lib/GarnetRs/Raw.hs index 61312fa..9a4c69d 100644 --- a/lib/GarnetRs/Raw.hs +++ b/lib/GarnetRs/Raw.hs @@ -30,17 +30,9 @@ import Language.Haskell.TH import System.Process do - systemDirs <- -- TODO bit of a hack - map (Dir . T.unpack . T.strip) - . concatMap (takeWhile (maybe False ((== ' ') . fst) . T.uncons) . dropWhile T.null . T.lines) - . drop 1 - . T.splitOn "search starts here:" - . T.pack - . thd3 - <$> runIO (readProcessWithExitCode "cpp" ["-v"] "") withHsBindgen def - { clang = def{extraIncludeDirs = Pkg "rust/target/debug" : systemDirs} + { clang = def{extraIncludeDirs = [Pkg "rust/target/debug"]} , fieldNamingStrategy = OmitFieldPrefixes } def