tree-sitter.builtGrammars: build parser libraries

except for typescript that provokes an error.
These libraries can be used on neovim 0.5 for instance.
wip/yesman
Matthieu Coudron 4 years ago committed by Profpatsch
parent 2d2a5a9b63
commit 53ae5f76a2
  1. 18
      pkgs/development/tools/parsing/tree-sitter/default.nix
  2. 30
      pkgs/development/tools/parsing/tree-sitter/library.nix

@ -2,6 +2,7 @@
, fetchgit, fetchFromGitHub, fetchurl
, writeShellScript, runCommand, which
, rustPlatform, jq, nix-prefetch-git, xe, curl, emscripten
, callPackage
}:
# TODO: move to carnix or https://github.com/kolloch/crate2nix
@ -26,15 +27,23 @@ let
inherit writeShellScript nix-prefetch-git curl jq xe src;
};
fetchGrammar = (v: fetchgit {inherit (v) url rev sha256 fetchSubmodules; });
grammars =
let fetch =
(v: fetchgit {inherit (v) url rev sha256 fetchSubmodules; });
in runCommand "grammars" {} (''
runCommand "grammars" {} (''
mkdir $out
'' + (lib.concatStrings (lib.mapAttrsToList
(name: grammar: "ln -s ${fetch grammar} $out/${name}\n")
(name: grammar: "ln -s ${fetchGrammar grammar} $out/${name}\n")
(import ./grammars))));
builtGrammars = let
change = name: grammar:
callPackage ./library.nix {
language = name; inherit version; source = fetchGrammar grammar;
};
in
# typescript doesn't have parser.c in the same place as others
lib.mapAttrs change (removeAttrs (import ./grammars) ["typescript"]);
in rustPlatform.buildRustPackage {
pname = "tree-sitter";
@ -64,6 +73,7 @@ in rustPlatform.buildRustPackage {
inherit update-all-grammars;
};
inherit grammars;
inherit builtGrammars;
};
meta = {

@ -0,0 +1,30 @@
{ stdenv
, language
, tree-sitter
, version
, source
}:
stdenv.mkDerivation {
pname = "tree-sitter-${language}-library";
inherit version;
src = source;
buildInputs = [ tree-sitter ];
dontUnpack = true;
configurePhase= ":";
buildPhase = ''
runHook preBuild
$CC -I$src/src/ -shared -o parser -Os $src/src/parser.c
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
mv parser $out/
runHook postInstall
'';
}
Loading…
Cancel
Save