From 53ae5f76a20257a61e231f250196066a7d0667bc Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 1 Mar 2020 00:21:36 +0100 Subject: [PATCH] tree-sitter.builtGrammars: build parser libraries except for typescript that provokes an error. These libraries can be used on neovim 0.5 for instance. --- .../tools/parsing/tree-sitter/default.nix | 18 ++++++++--- .../tools/parsing/tree-sitter/library.nix | 30 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/tools/parsing/tree-sitter/library.nix diff --git a/pkgs/development/tools/parsing/tree-sitter/default.nix b/pkgs/development/tools/parsing/tree-sitter/default.nix index 0e69fa3259f8..e77b338a20a5 100644 --- a/pkgs/development/tools/parsing/tree-sitter/default.nix +++ b/pkgs/development/tools/parsing/tree-sitter/default.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 = { diff --git a/pkgs/development/tools/parsing/tree-sitter/library.nix b/pkgs/development/tools/parsing/tree-sitter/library.nix new file mode 100644 index 000000000000..2d5d3e7d0b4d --- /dev/null +++ b/pkgs/development/tools/parsing/tree-sitter/library.nix @@ -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 + ''; +}