50 lines
1.6 KiB
Nix
50 lines
1.6 KiB
Nix
{
|
|
description = "Tree sitter collection";
|
|
|
|
inputs = {
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils }:
|
|
flake-utils.lib.eachDefaultSystem (sys:
|
|
let pkgs = nixpkgs.legacyPackages.${sys};
|
|
deps = [ pkgs.tree-sitter pkgs.nodejs pkgs.gcc ];
|
|
|
|
compile-tree-sitter = { src, name }: pkgs.stdenv.mkDerivation {
|
|
# inherit src name;
|
|
src = src;
|
|
name = name;
|
|
|
|
nativeBuildInputs = deps;
|
|
|
|
buildPhase = ''
|
|
tree-sitter generate
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir -p "$out/lib"
|
|
cp -r src "$out/src"
|
|
touch src/scanner.c
|
|
|
|
gcc -c src/parser.c -o parser.o
|
|
gcc -c src/scanner.c -o scanner.o
|
|
ar rcs "$out/lib/libtree-sitter-$name.a" parser.o scanner.o
|
|
|
|
gcc -shared src/scanner.c src/parser.c -o "$out/lib/libtree-sitter-$name.so"
|
|
'';
|
|
|
|
# TODO: Get tests working
|
|
# For some reason, just doing tree-sitter test fails with "read-only file system"
|
|
};
|
|
|
|
in rec {
|
|
packages.agda = compile-tree-sitter { src = ./agda; name = "agda"; };
|
|
packages.bash = compile-tree-sitter { src = ./bash; name = "bash"; };
|
|
packages.c = compile-tree-sitter { src = ./c; name = "c"; };
|
|
packages.nix = compile-tree-sitter { src = ./nix; name = "nix"; };
|
|
packages.python = compile-tree-sitter { src = ./python; name = "python"; };
|
|
packages.rust = compile-tree-sitter { src = ./rust; name = "rust"; };
|
|
}
|
|
);
|
|
}
|