New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow web-tree-sitter to work with Emscripten 3 #1913
Conversation
@@ -83,6 +83,8 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu | |||
"-s", | |||
"NODEJS_CATCH_EXIT=0", | |||
"-s", | |||
"NODEJS_CATCH_REJECTION=0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After enabling assertions, my first error was the generated tree-sitter grammar's WASM catching a Promise rejection. Sadly, I have not been able to recreate this for a screenshot.
@@ -77,6 +77,8 @@ fi | |||
|
|||
mkdir -p target/scratch | |||
|
|||
runtime_methods='stringToUTF16','AsciiToString' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next, I encountered this error:
After some googling I discovered that stringToUTF16
is from emscripten's preamble and just needed exporting.
Next, the line console.log(tree.rootNode.toString());
threw this error:
I quickly determined that the cause is the same and added it as well.
I tried to check your changes. I took the repro that I posted in #1560, here: https://gist.github.com/verhovsky/a04c7256da13797e312acd0a8afd9023 and changed its "web-tree-sitter": "../tree-sitter/lib/binding_web/",
"tree-sitter-cli": "../tree-sitter/cli" I made the same changes as you made in this PR to my local copy of tree-sitter and then I ran cd ../tree-sitter
cargo build --release
./script/build-wasm then in the repro directory I ran rm -rf node_modules
npm install
npm run build
npm start But I see this error in the browser:
If I change
then everything works, because the Docker has Emscripten 2, instead of Emscripten 3 which made the breaking changes it seems like you're trying to fix here. |
@verhovsky I was able to replicate this issue. Building This isn't something that can be exported like |
@@ -24,6 +24,7 @@ | |||
"_memcmp", | |||
"_memcpy", | |||
"_memmove", | |||
"_memset", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the issue from running tree-sitter-python
, see my comment
I tried a few more languages (tree-sitter-bash, -c, -cpp, -java, -javascript, -php and -python) and I can confirm this works. Great work |
I updated my repro gist so now it tries to |
@verhovsky I don't have a good setup for testing this right now, but I just pushed a change that I believe will fix the issue you encountered with |
@J3RN that works. I did try this but I didn't realize I needed to keep adding underscores until it starts working lol |
Please change cli/emscripten-version to " It's currently set to "
I did a (quasi-)binary search changing that file to various versions and running |
bd19fc4
to
1f36bf0
Compare
Thanks for the PR @J3RN, and for helping out with it @verhovsky. It looks like the issues that were blocking us from upgrading to Emscripten 3 are fixed now. It'll be great to be on the latest version. |
Changes are explained in-line.
Originally I tried implementing the "Basic Usage" from inside a React application, and encountered this error message:
Per its advice, I changed the emscripten flags in both
script/build-wasm
(for tree-sitter's WASM) andcli/src/wasm.rs
(for the grammar's WASM) to include-s ASSERTIONS=1
and made the following changes based on the issues surfaced.Fixes #1560