Remove duplicate specification of stdlib symbols for web tree-sitter
This commit is contained in:
parent
e21d9e7f93
commit
d2900510f6
4 changed files with 123 additions and 156 deletions
|
|
@ -1,22 +1,19 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const inputFiles = [
|
||||
'binding.c',
|
||||
'binding.js',
|
||||
'exports.json',
|
||||
'imports.js',
|
||||
'prefix.js',
|
||||
...list('../include/tree_sitter'),
|
||||
...list('../src')
|
||||
]
|
||||
"binding.c",
|
||||
"binding.js",
|
||||
"exports.txt",
|
||||
"imports.js",
|
||||
"prefix.js",
|
||||
...list("../include/tree_sitter"),
|
||||
...list("../src"),
|
||||
];
|
||||
|
||||
const outputFiles = [
|
||||
'tree-sitter.js',
|
||||
'tree-sitter.wasm',
|
||||
]
|
||||
const outputFiles = ["tree-sitter.js", "tree-sitter.wasm"];
|
||||
|
||||
const outputMtime = Math.min(...outputFiles.map(mtime));
|
||||
|
||||
|
|
@ -28,9 +25,10 @@ for (const inputFile of inputFiles) {
|
|||
}
|
||||
|
||||
function list(dir) {
|
||||
return fs.readdirSync(path.join(__dirname, dir), 'utf8')
|
||||
.filter(p => !p.startsWith('.'))
|
||||
.map(p => path.join(dir, p));
|
||||
return fs
|
||||
.readdirSync(path.join(__dirname, dir), "utf8")
|
||||
.filter((p) => !p.startsWith("."))
|
||||
.map((p) => path.join(dir, p));
|
||||
}
|
||||
|
||||
function mtime(p) {
|
||||
|
|
|
|||
|
|
@ -1,134 +0,0 @@
|
|||
[
|
||||
"_calloc",
|
||||
"_free",
|
||||
"_malloc",
|
||||
"_realloc",
|
||||
|
||||
"__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm",
|
||||
"__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc",
|
||||
"__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw",
|
||||
"__ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm",
|
||||
"__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm",
|
||||
"__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6resizeEmw",
|
||||
"__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev",
|
||||
"__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev",
|
||||
"__ZdlPv",
|
||||
"__Znwm",
|
||||
"___cxa_atexit",
|
||||
"_abort",
|
||||
"_isalpha",
|
||||
"_isspace",
|
||||
"_iswalnum",
|
||||
"_iswalpha",
|
||||
"_iswblank",
|
||||
"_iswdigit",
|
||||
"_iswlower",
|
||||
"_iswupper",
|
||||
"_iswspace",
|
||||
"_memchr",
|
||||
"_memcmp",
|
||||
"_memcpy",
|
||||
"_memmove",
|
||||
"_memset",
|
||||
"_strlen",
|
||||
"_strcmp",
|
||||
"_strncpy",
|
||||
"_tolower",
|
||||
"_towlower",
|
||||
"_towupper",
|
||||
"_stderr",
|
||||
|
||||
"_ts_init",
|
||||
"_ts_language_field_count",
|
||||
"_ts_language_field_name_for_id",
|
||||
"_ts_language_type_is_named_wasm",
|
||||
"_ts_language_type_is_visible_wasm",
|
||||
"_ts_language_symbol_count",
|
||||
"_ts_language_state_count",
|
||||
"_ts_language_symbol_for_name",
|
||||
"_ts_language_symbol_name",
|
||||
"_ts_language_symbol_type",
|
||||
"_ts_language_version",
|
||||
"_ts_language_next_state",
|
||||
"_ts_node_field_name_for_child_wasm",
|
||||
"_ts_node_child_by_field_id_wasm",
|
||||
"_ts_node_child_count_wasm",
|
||||
"_ts_node_child_wasm",
|
||||
"_ts_node_children_wasm",
|
||||
"_ts_node_descendant_for_index_wasm",
|
||||
"_ts_node_descendant_for_position_wasm",
|
||||
"_ts_node_descendants_of_type_wasm",
|
||||
"_ts_node_end_index_wasm",
|
||||
"_ts_node_end_point_wasm",
|
||||
"_ts_node_has_changes_wasm",
|
||||
"_ts_node_has_error_wasm",
|
||||
"_ts_node_is_error_wasm",
|
||||
"_ts_node_is_missing_wasm",
|
||||
"_ts_node_is_named_wasm",
|
||||
"_ts_node_parse_state_wasm",
|
||||
"_ts_node_next_parse_state_wasm",
|
||||
"_ts_node_named_child_count_wasm",
|
||||
"_ts_node_named_child_wasm",
|
||||
"_ts_node_named_children_wasm",
|
||||
"_ts_node_named_descendant_for_index_wasm",
|
||||
"_ts_node_named_descendant_for_position_wasm",
|
||||
"_ts_node_next_named_sibling_wasm",
|
||||
"_ts_node_next_sibling_wasm",
|
||||
"_ts_node_parent_wasm",
|
||||
"_ts_node_prev_named_sibling_wasm",
|
||||
"_ts_node_prev_sibling_wasm",
|
||||
"_ts_node_start_index_wasm",
|
||||
"_ts_node_start_point_wasm",
|
||||
"_ts_node_symbol_wasm",
|
||||
"_ts_node_grammar_symbol_wasm",
|
||||
"_ts_node_to_string_wasm",
|
||||
"_ts_parser_delete",
|
||||
"_ts_parser_enable_logger_wasm",
|
||||
"_ts_parser_new_wasm",
|
||||
"_ts_parser_parse_wasm",
|
||||
"_ts_parser_reset",
|
||||
"_ts_parser_set_language",
|
||||
"_ts_parser_set_timeout_micros",
|
||||
"_ts_parser_timeout_micros",
|
||||
"_ts_query_capture_count",
|
||||
"_ts_query_capture_name_for_id",
|
||||
"_ts_query_captures_wasm",
|
||||
"_ts_query_delete",
|
||||
"_ts_query_matches_wasm",
|
||||
"_ts_query_new",
|
||||
"_ts_query_pattern_count",
|
||||
"_ts_query_predicates_for_pattern",
|
||||
"_ts_query_string_count",
|
||||
"_ts_query_string_value_for_id",
|
||||
"_ts_tree_copy",
|
||||
"_ts_tree_cursor_current_field_id_wasm",
|
||||
"_ts_tree_cursor_current_node_id_wasm",
|
||||
"_ts_tree_cursor_current_node_is_missing_wasm",
|
||||
"_ts_tree_cursor_current_node_is_named_wasm",
|
||||
"_ts_tree_cursor_current_node_type_id_wasm",
|
||||
"_ts_tree_cursor_current_node_state_id_wasm",
|
||||
"_ts_tree_cursor_current_node_wasm",
|
||||
"_ts_tree_cursor_delete_wasm",
|
||||
"_ts_tree_cursor_end_index_wasm",
|
||||
"_ts_tree_cursor_end_position_wasm",
|
||||
"_ts_tree_cursor_goto_first_child_wasm",
|
||||
"_ts_tree_cursor_goto_last_child_wasm",
|
||||
"_ts_tree_cursor_goto_next_sibling_wasm",
|
||||
"_ts_tree_cursor_goto_previous_sibling_wasm",
|
||||
"_ts_tree_cursor_goto_parent_wasm",
|
||||
"_ts_tree_cursor_new_wasm",
|
||||
"_ts_tree_cursor_reset_wasm",
|
||||
"_ts_tree_cursor_reset_to_wasm",
|
||||
"_ts_tree_cursor_start_index_wasm",
|
||||
"_ts_tree_cursor_start_position_wasm",
|
||||
"_ts_tree_delete",
|
||||
"_ts_tree_edit_wasm",
|
||||
"_ts_tree_get_changed_ranges_wasm",
|
||||
"_ts_tree_root_node_wasm",
|
||||
"_ts_lookahead_iterator_new",
|
||||
"_ts_lookahead_iterator_delete",
|
||||
"_ts_lookahead_iterator_reset_state",
|
||||
"_ts_lookahead_iterator_reset",
|
||||
"_ts_lookahead_iterator_next",
|
||||
"_ts_lookahead_iterator_current_symbol"
|
||||
]
|
||||
93
lib/binding_web/exports.txt
Normal file
93
lib/binding_web/exports.txt
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
"ts_init",
|
||||
"ts_language_field_count",
|
||||
"ts_language_field_name_for_id",
|
||||
"ts_language_type_is_named_wasm",
|
||||
"ts_language_type_is_visible_wasm",
|
||||
"ts_language_symbol_count",
|
||||
"ts_language_state_count",
|
||||
"ts_language_symbol_for_name",
|
||||
"ts_language_symbol_name",
|
||||
"ts_language_symbol_type",
|
||||
"ts_language_version",
|
||||
"ts_language_next_state",
|
||||
"ts_node_field_name_for_child_wasm",
|
||||
"ts_node_child_by_field_id_wasm",
|
||||
"ts_node_child_count_wasm",
|
||||
"ts_node_child_wasm",
|
||||
"ts_node_children_wasm",
|
||||
"ts_node_descendant_for_index_wasm",
|
||||
"ts_node_descendant_for_position_wasm",
|
||||
"ts_node_descendants_of_type_wasm",
|
||||
"ts_node_end_index_wasm",
|
||||
"ts_node_end_point_wasm",
|
||||
"ts_node_has_changes_wasm",
|
||||
"ts_node_has_error_wasm",
|
||||
"ts_node_is_error_wasm",
|
||||
"ts_node_is_missing_wasm",
|
||||
"ts_node_is_named_wasm",
|
||||
"ts_node_parse_state_wasm",
|
||||
"ts_node_next_parse_state_wasm",
|
||||
"ts_node_named_child_count_wasm",
|
||||
"ts_node_named_child_wasm",
|
||||
"ts_node_named_children_wasm",
|
||||
"ts_node_named_descendant_for_index_wasm",
|
||||
"ts_node_named_descendant_for_position_wasm",
|
||||
"ts_node_next_named_sibling_wasm",
|
||||
"ts_node_next_sibling_wasm",
|
||||
"ts_node_parent_wasm",
|
||||
"ts_node_prev_named_sibling_wasm",
|
||||
"ts_node_prev_sibling_wasm",
|
||||
"ts_node_start_index_wasm",
|
||||
"ts_node_start_point_wasm",
|
||||
"ts_node_symbol_wasm",
|
||||
"ts_node_grammar_symbol_wasm",
|
||||
"ts_node_to_string_wasm",
|
||||
"ts_parser_delete",
|
||||
"ts_parser_enable_logger_wasm",
|
||||
"ts_parser_new_wasm",
|
||||
"ts_parser_parse_wasm",
|
||||
"ts_parser_reset",
|
||||
"ts_parser_set_language",
|
||||
"ts_parser_set_timeout_micros",
|
||||
"ts_parser_timeout_micros",
|
||||
"ts_query_capture_count",
|
||||
"ts_query_capture_name_for_id",
|
||||
"ts_query_captures_wasm",
|
||||
"ts_query_delete",
|
||||
"ts_query_matches_wasm",
|
||||
"ts_query_new",
|
||||
"ts_query_pattern_count",
|
||||
"ts_query_predicates_for_pattern",
|
||||
"ts_query_string_count",
|
||||
"ts_query_string_value_for_id",
|
||||
"ts_tree_copy",
|
||||
"ts_tree_cursor_current_field_id_wasm",
|
||||
"ts_tree_cursor_current_node_id_wasm",
|
||||
"ts_tree_cursor_current_node_is_missing_wasm",
|
||||
"ts_tree_cursor_current_node_is_named_wasm",
|
||||
"ts_tree_cursor_current_node_type_id_wasm",
|
||||
"ts_tree_cursor_current_node_state_id_wasm",
|
||||
"ts_tree_cursor_current_node_wasm",
|
||||
"ts_tree_cursor_delete_wasm",
|
||||
"ts_tree_cursor_end_index_wasm",
|
||||
"ts_tree_cursor_end_position_wasm",
|
||||
"ts_tree_cursor_goto_first_child_wasm",
|
||||
"ts_tree_cursor_goto_last_child_wasm",
|
||||
"ts_tree_cursor_goto_next_sibling_wasm",
|
||||
"ts_tree_cursor_goto_previous_sibling_wasm",
|
||||
"ts_tree_cursor_goto_parent_wasm",
|
||||
"ts_tree_cursor_new_wasm",
|
||||
"ts_tree_cursor_reset_wasm",
|
||||
"ts_tree_cursor_reset_to_wasm",
|
||||
"ts_tree_cursor_start_index_wasm",
|
||||
"ts_tree_cursor_start_position_wasm",
|
||||
"ts_tree_delete",
|
||||
"ts_tree_edit_wasm",
|
||||
"ts_tree_get_changed_ranges_wasm",
|
||||
"ts_tree_root_node_wasm",
|
||||
"ts_lookahead_iterator_new",
|
||||
"ts_lookahead_iterator_delete",
|
||||
"ts_lookahead_iterator_reset_state",
|
||||
"ts_lookahead_iterator_reset",
|
||||
"ts_lookahead_iterator_next",
|
||||
"ts_lookahead_iterator_current_symbol",
|
||||
|
|
@ -30,6 +30,7 @@ EOF
|
|||
set -e
|
||||
|
||||
web_dir=lib/binding_web
|
||||
src_dir=lib/src
|
||||
emscripten_flags="-O3"
|
||||
minify_js=1
|
||||
force_docker=0
|
||||
|
|
@ -98,6 +99,15 @@ mkdir -p target/scratch
|
|||
|
||||
runtime_methods='stringToUTF16','AsciiToString'
|
||||
|
||||
# Remove quotes, add leading underscores, remove newlines, remove trailing comma.
|
||||
EXPORTED_FUNCTIONS=$( \
|
||||
cat ${src_dir}/wasm/stdlib-symbols.txt ${web_dir}/exports.txt | \
|
||||
sed -e 's/"//g' | \
|
||||
sed -e 's/^/_/g' | \
|
||||
tr -d '\n"' | \
|
||||
sed -e 's/,$//' \
|
||||
)
|
||||
|
||||
# Use emscripten to generate `tree-sitter.js` and `tree-sitter.wasm`
|
||||
# in the `target/scratch` directory
|
||||
$emcc \
|
||||
|
|
@ -108,14 +118,14 @@ $emcc \
|
|||
-s FILESYSTEM=0 \
|
||||
-s NODEJS_CATCH_EXIT=0 \
|
||||
-s NODEJS_CATCH_REJECTION=0 \
|
||||
-s EXPORTED_FUNCTIONS=@${web_dir}/exports.json \
|
||||
-s EXPORTED_FUNCTIONS=${EXPORTED_FUNCTIONS} \
|
||||
-s EXPORTED_RUNTIME_METHODS=$runtime_methods \
|
||||
$emscripten_flags \
|
||||
-fno-exceptions \
|
||||
-std=c99 \
|
||||
-D 'fprintf(...)=' \
|
||||
-D NDEBUG= \
|
||||
-I lib/src \
|
||||
-I ${src_dir} \
|
||||
-I lib/include \
|
||||
--js-library ${web_dir}/imports.js \
|
||||
--pre-js ${web_dir}/prefix.js \
|
||||
|
|
@ -139,9 +149,9 @@ if [[ "$minify_js" == "1" ]]; then
|
|||
--mangle \
|
||||
--keep-classnames \
|
||||
-- target/scratch/tree-sitter.js \
|
||||
> $web_dir/tree-sitter.js
|
||||
> ${web_dir}/tree-sitter.js
|
||||
else
|
||||
cp target/scratch/tree-sitter.js $web_dir/tree-sitter.js
|
||||
cp target/scratch/tree-sitter.js ${web_dir}/tree-sitter.js
|
||||
fi
|
||||
|
||||
mv target/scratch/tree-sitter.wasm $web_dir/tree-sitter.wasm
|
||||
mv target/scratch/tree-sitter.wasm ${web_dir}/tree-sitter.wasm
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue