mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-23 06:03:40 +00:00
fee2e23c00
Update the grammars and add `allGrammars` derivation. `nix-build "<nixpkgs>" -A tree-sitter.allGrammars` will create a derivation with symlinks to all the grammars
54 lines
959 B
Nix
54 lines
959 B
Nix
{ stdenv
|
|
, tree-sitter
|
|
}:
|
|
|
|
# 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}"
|
|
;
|
|
|
|
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
|
|
'';
|
|
}
|