Fix tree-sitter-ruby crate failing to build to Wasm #283
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes tree-sitter-ruby crate compile to Wasm.
See reproduction repo for detailed steps and more details about the described issues. The repo branch
fix-envcontains fully resolved problem using both tree-sitter and tree-sitter-ruby forks.This is 2/2 PRs required to address the problem:
Build Issues
Missing
#include <stdlib.h>The problem starts when trying to build simple Rust code using tree-sitter-ruby to Wasm:
To demonstrate the problem, I used
wasm-pack build --target nodejs:It fails with missing
#include <stdlib.h>error:Duplicate symbol
__assert_failAfter fixing the problem in tree-sitter-ruby tree-sitter-ruby/tree-sitter-ruby@c9b9144a046be3232512e2155c86dcdbd4d97597) by adding required
std::env::var("TARGET").unwrap() == "wasm32-unknown-unknown"block, the build starts failing with:This is addressed by making
__assert_failstatic inlinein tree-sitter tree-sitter/tree-sitter@d046c97.Missing Shims Issue
After the build is fixed, an attempt to run
wasm-pack build --target nodejsfails with the missingenverror indicating missing included symbols:To find the missing symbols, I used the
find_wasm_importscript:The missing symbols are
iswlower,memchr, andiswupper.After fixing the missing symbols issue, the tests still fail with the same error, although
import "env"does not show in the wat file anymore.After inspecting the test wasm file, we see that now
strchris missing:The code is being optimized away, so to make sure we don't miss any new symbols, we should use the dev profile:
Since nothing new shows up, we can be sure that tree-sitter-ruby and tree-sitter fixes are sufficient to build successfully to Wasm.
The fix adds all required functions and includes. Making the tests (
wasm-pack test --node) finally pass: