nixpkgs-suyu/pkgs/development/tools/parsing/tree-sitter/grammar.nix
Carlos Hernandez 99b351b4bd tree-sitter: explicitly incl CXX headers on Darwin
clang needs to find headers + libraries for compiling with libc++.
On Darwin we will include CXX headers when compiling C.

This closes #124396
2021-06-04 11:31:42 -06:00

56 lines
1 KiB
Nix

{ stdenv
, tree-sitter
, libcxx
, lib
}:
# Build a parser grammar and put the resulting shared object in `$out/parser`
{
# language name
language
# version of tree-sitter
, version
# source for the language grammar
, source
, location ? null
}:
stdenv.mkDerivation {
pname = "${language}-grammar";
inherit version;
src =
if location == null
then
source
else
"${source}/${location}"
;
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
buildInputs = [ tree-sitter ];
dontUnpack = true;
configurePhase = ":";
buildPhase = ''
runHook preBuild
scanner_cc="$src/src/scanner.cc"
if [ ! -f "$scanner_cc" ]; then
scanner_cc=""
fi
scanner_c="$src/src/scanner.c"
if [ ! -f "$scanner_c" ]; then
scanner_c=""
fi
$CC -I$src/src/ -shared -o parser -Os $src/src/parser.c $scanner_cc $scanner_c -lstdc++
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
mv parser $out/
runHook postInstall
'';
}