Specify include directories via environment variable

This commit is contained in:
George Thomas 2026-04-13 23:22:46 +01:00
parent 351640dc7a
commit b2eaaf6b88
2 changed files with 7 additions and 9 deletions

View File

@ -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}"
'';
project = (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;
};
}).project.haskell-nix;
garnet-rs = crane.buildPackage {

View File

@ -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