-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-wasm.nix
executable file
·69 lines (59 loc) · 2.14 KB
/
build-wasm.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env nix-build
# Uses [niv](https://github.com/nmattia/niv) to manage sources.
# Add a new grammar from GitHub:
# niv add tree-sitter/tree-sitter-c
# Update a grammar:
# niv update tree-sitter-c
let
sources = import nix/sources.nix;
pkgs = import sources.nixpkgs { };
unstable = import sources.nixpkgs-unstable { };
mkTreeSitterGrammar = id: src: { preBuild ? "" }:
pkgs.runCommand "tree-sitter-${id}-wasm" { inherit src; } ''
mkdir $out
mkdir home
export HOME=$PWD/home
cp -r $src/* .
chmod -R 777 .
test -e LICENSE && cp LICENSE $out/tree-sitter-${id}.LICENSE
test -e LICENSE.md && cp LICENSE.md $out/tree-sitter-${id}.LICENSE.md
test -e COPYING.txt && cp COPYING.txt $out/tree-sitter-${id}.COPYING.txt
${preBuild}
PATH=$PATH:${unstable.emscripten}/bin
${pkgs.tree-sitter}/bin/tree-sitter build-wasm
cp *.wasm $out/
'';
grammar = id: src:
mkTreeSitterGrammar id src { };
in
pkgs.symlinkJoin {
name = "tree-sitter-wasm-builds-combined";
paths = with sources; [
(grammar "bash" tree-sitter-bash)
(grammar "c" tree-sitter-c)
(grammar "clojure" tree-sitter-clojure)
(grammar "css" tree-sitter-css)
(grammar "fennel" tree-sitter-fennel)
(grammar "go" tree-sitter-go)
(grammar "haskell" tree-sitter-haskell)
(grammar "html" tree-sitter-html)
(grammar "java" tree-sitter-java)
(grammar "javascript" tree-sitter-javascript)
(grammar "json" tree-sitter-json)
(grammar "kotlin" tree-sitter-kotlin)
(grammar "lua" tree-sitter-lua)
(grammar "markdown" tree-sitter-markdown)
(grammar "nix" tree-sitter-nix)
(mkTreeSitterGrammar "ocaml" tree-sitter-ocaml
# contains multiple grammars: ocaml (.ml) ; interface (.mli)
{ preBuild = "cd ocaml"; })
(grammar "php" tree-sitter-php)
(grammar "python" tree-sitter-python)
(grammar "scss" tree-sitter-scss)
(grammar "toml" tree-sitter-toml)
(mkTreeSitterGrammar "typescript" tree-sitter-typescript
# contains multiple grammars: TypeScript and JSX
{ preBuild = "cd typescript"; })
(grammar "yaml" tree-sitter-yaml)
];
}