changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra / scripts/ts-install-langs.sh

changeset 38: 197d061b1f2e
parent: 4e73da2d9c63
child: 9211d38aca7e
author: ellis <ellis@rwest.io>
date: Sat, 30 Dec 2023 23:45:41 -0500
permissions: -rwxr-xr-x
description: 2
1 #!/usr/bin/env bash
2 
3 # based on https://github.com/GrammaTech/sel/blob/master/tools/tree-sitter-install.sh
4 set -eux
5 
6 declare -ar default_langs=(
7  commonlisp bash c cpp css go html java javascript jsdoc json python regex rust
8  typescript/tsx typescript/typescript yaml
9 ) # more langs: agda c-sharp julia ocaml/interface ocaml/ocaml php ql ruby scala
10 
11 TARGETDIR=${1:-build/src/ts-langs}
12 PREFIX=${PREFIX:-/usr/local}
13 CC=${CC:-clang}
14 CXX=${CXX:-clang++}
15 if [ $(uname) == "Darwin" ];then
16  EXT=dylib;
17 else
18  EXT=so
19 fi
20 # Declared repositories.
21 declare -A repos
22 repos[commonlisp]=https://github.com/theHamsta/tree-sitter-commonlisp.git
23 repos[yaml]=https://github.com/ikatyang/tree-sitter-yaml.git
24 repos[cpp]=https://github.com/ruricolist/tree-sitter-cpp.git
25 
26 declare -a langs
27 if [ -z "${2:-}" ]; then
28  langs=(${default_langs[@]})
29 else
30  langs=($@)
31 fi
32 
33 mkdir -pv $TARGETDIR
34 pushd $TARGETDIR
35 for lang in "${langs[@]}";do
36  [ -d "tree-sitter-${lang%/*}" ] || git clone ${repos[$lang]:-https://github.com/tree-sitter/tree-sitter-${lang%/*}};
37  # subshell
38  (
39  cd "tree-sitter-${lang}/src";
40  if test -f "scanner.cc"; then
41  ${CXX} -I. -fPIC scanner.cc -c -lstdc++;
42  ${CC} -I. -std=c99 -fPIC parser.c -c;
43  ${CXX} -shared scanner.o parser.o -o ${PREFIX}/lib/libtree-sitter-"${lang//\//-}.${EXT}";
44  elif test -f "scanner.c"; then
45  ${CC} -I. -std=c99 -fPIC scanner.c -c;
46  ${CC} -I. -std=c99 -fPIC parser.c -c;
47  ${CC} -shared scanner.o parser.o -o ${PREFIX}/lib/libtree-sitter-"${lang//\//-}.${EXT}";
48  else
49  ${CC} -I. -std=c99 -fPIC parser.c -c;
50  ${CC} -shared parser.o -o ${PREFIX}/lib/libtree-sitter-"${lang//\//-}.${EXT}";
51  fi;
52  mkdir -p "${PREFIX}/share/tree-sitter/${lang}/";
53  cp grammar.json node-types.json "${PREFIX}/share/tree-sitter/${lang}";
54  )
55 done