-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathMakefile
68 lines (52 loc) · 2.58 KB
/
Makefile
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
# For generating .wasm files for parsers
# See https://www.npmjs.com/package/web-tree-sitter
LANGUAGES = agda bash c c-sharp clojure cpp css elisp elm go haskell html java javascript json kotlin latex markdown php python query ruby rust scala scss sparql talon tsx typescript yaml
# NOTE: Update the version number in the filepath for web-tree-sitter in package.json,
# when you change this version number.
TREE_SITTER_VERSION := 0.20.4
# Build web-tree-sitter parsers for $(LANGUAGES)
.PHONY: parsers
parsers: $(addprefix parsers/tree-sitter-,$(addsuffix .wasm,$(LANGUAGES)))
parsers/%.wasm: node_modules/%/package.json
mkdir -p $(dir $@)
npx tree-sitter build-wasm $(dir $^)
mv $(notdir $@) $@
parsers/tree-sitter-elm.wasm: node_modules/@elm-tooling/tree-sitter-elm/package.json
mkdir -p $(dir $@)
npx tree-sitter build-wasm $(dir $^)
mv $(notdir $@) $@
parsers/tree-sitter-typescript.wasm: node_modules/tree-sitter-typescript/typescript/package.json
mkdir -p $(dir $@)
npx tree-sitter build-wasm $(dir $^)
mv $(notdir $@) $@
parsers/tree-sitter-tsx.wasm: node_modules/tree-sitter-typescript/tsx/package.json
mkdir -p $(dir $@)
npx tree-sitter build-wasm $(dir $^)
mv $(notdir $@) $@
parsers/tree-sitter-c-sharp.wasm: node_modules/tree-sitter-c-sharp/package.json
mkdir -p $(dir $@)
npx tree-sitter build-wasm $(dir $^)
mv tree-sitter-c_sharp.wasm $@
# Build web-tree-sitter
WEB_TREE_SITTER_FILES := README.md package.json tree-sitter-web.d.ts tree-sitter.js tree-sitter.wasm
WEB_TREE_SITTER_DIR := vendor/web-tree-sitter/$(TREE_SITTER_VERSION)
WEB_TREE_SITTER_PATCH := patches/tree-sitter+$(TREE_SITTER_VERSION).patch
MAKE_CACHE_DIR := .make-work
.PHONY: web-tree-sitter
web-tree-sitter: $(addprefix $(WEB_TREE_SITTER_DIR)/,$(WEB_TREE_SITTER_FILES)) \
$(addprefix $(WEB_TREE_SITTER_DIR)/,$(WEB_TREE_SITTER_FILES)):
@rm -rf $(MAKE_CACHE_DIR)/tree-sitter
@git clone \
-c advice.detachedHead=false --quiet \
--depth=1 --branch=v$(TREE_SITTER_VERSION) \
https://github.com/tree-sitter/tree-sitter.git \
$(MAKE_CACHE_DIR)/tree-sitter
ifneq (,$(wildcard $(WEB_TREE_SITTER_PATCH)))
@(cp $(WEB_TREE_SITTER_PATCH) $(MAKE_CACHE_DIR)/tree-sitter)
@(cd $(MAKE_CACHE_DIR)/tree-sitter && git apply $(notdir $(WEB_TREE_SITTER_PATCH)))
endif
@(cd $(MAKE_CACHE_DIR)/tree-sitter && ./script/build-wasm)
@mkdir -p $(WEB_TREE_SITTER_DIR)
@cp $(MAKE_CACHE_DIR)/tree-sitter/LICENSE $(WEB_TREE_SITTER_DIR)
@cp $(addprefix $(MAKE_CACHE_DIR)/tree-sitter/lib/binding_web/,$(WEB_TREE_SITTER_FILES)) $(WEB_TREE_SITTER_DIR)
@rm -rf $(MAKE_CACHE_DIR)/tree-sitter