forked from tree-sitter/tree-sitter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-bindings
executable file
·43 lines (39 loc) · 1.33 KB
/
generate-bindings
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
#!/bin/bash
output_path=lib/binding_rust/bindings.rs
header_path='lib/include/tree_sitter/api.h'
no_derive_copy=(
TSInput
TSLanguage
TSLogger
TSLookaheadIterator
TSParser
TSTree
TSQuery
TSQueryCursor
TSQueryCapture
TSQueryMatch
TSQueryPredicateStep
)
no_copy=$(IFS='|'; echo "${no_derive_copy[*]}")
file_version=$(head -n1 "$output_path" | cut -d' ' -f6)
tool_version=$(bindgen --version | cut -d' ' -f2)
higher_version=$(echo -e "${file_version}\n${tool_version}" | sort -V | tail -n1)
if [ "$higher_version" != "$tool_version" ]; then
echo "Latest used bindgen version was $file_version" >&2
echo "Currently installed bindgen CLI version is $tool_version" >&2
echo >&2
echo "It's needed to upgrade bindgen CLI first with \`cargo install bindgen-cli\`" >&2
exit 1
fi
bindgen \
--no-layout-tests \
--allowlist-type '^TS.*' \
--allowlist-function '^ts_.*' \
--allowlist-var "^TREE_SITTER.*" \
--blocklist-type '^__.*' \
--no-prepend-enum-name \
--no-copy "$no_copy" \
$header_path \
-- \
-D TREE_SITTER_FEATURE_WASM \
> $output_path