-
Notifications
You must be signed in to change notification settings - Fork 2
Get wasm-pack supposedly working #16
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
Conversation
| #include <assert.h> | ||
| #include <ctype.h> | ||
| #include <string.h> | ||
| #include <wchar.h> |
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 one didn't seem used, and the shims didn't provide a shim for it, so I removed
| while (isdigit(lexer->lookahead)) { | ||
| while (iswdigit(lexer->lookahead)) { |
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.
Using tree-sitter blessed function https://github.com/tree-sitter/tree-sitter/blob/0be215e152d58351d2691484b4398ceff041f2fb/lib/src/wasm/stdlib-symbols.txt#L6
Which the shims also provided
| for (size_t i = 0; i < NUM_HTML_TAG_NAMES_RULE_1; i++) { | ||
| if (strcmp(name, HTML_TAG_NAMES_RULE_1[i]) == 0) { | ||
| // FIXME: I'm guessing on the size here | ||
| if (strncmp(name, HTML_TAG_NAMES_RULE_1[i], name_length) == 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.
Someone other than me should think about these strncmp calls
crates/wasm-qmd-parser/Cargo.toml
Outdated
| [dependencies] | ||
| quarto-markdown-pandoc = { workspace = true } | ||
| wasm-bindgen = "0.2.84" | ||
| wasm-bindgen = "0.2.89" |
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.
Supposedly this is when wasm-bindgen started working right with extern C
https://github.com/rust9x/rust/blob/19b01bd748a7829a5f42f32eb31b21d2e54d30b7/src/doc/rustc/src/platform-support/wasm32-unknown-unknown.md?plain=1#L293
| // Note: Not provided by https://github.com/cacticouncil/lilypad, but we needed | ||
| // this one too. We could contribute this back upstream? Note that | ||
| // `towlower()`'s C function docs say it is only guaranteed to work in 1:1 | ||
| // mapping cases, so that is what we reimplement here as well. | ||
| // https://en.cppreference.com/w/c/string/wide/towlower | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn towlower(c: c_int) -> c_int { | ||
| char::from_u32(c as u32).map_or(0, |c| { | ||
| c.to_lowercase().next().map(|c| c as i32).unwrap_or(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.
Nearly straight from https://github.com/cacticouncil/lilypad/blob/main/src/c_shim.rs but I did need this one, which is a blessed tree-sitter function and you use it in your scanner
| ``` | ||
| cd crates/wasm-qmd-parser | ||
| # To work around this error, because Apple Clang doesn't work with wasm32-unknown-unknown? | ||
| # I believe this is not required on a Linux machine. | ||
| # Requires `brew install llvm`. | ||
| # https://github.com/briansmith/ring/issues/1824 | ||
| # error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"' | ||
| export PATH="/opt/homebrew/opt/llvm/bin:$PATH" | ||
| # To tell rustc to include our C shims located in `wasm-sysroot`, which we eventually compile into the project | ||
| # with `c_shim.rs`. | ||
| # https://github.com/tree-sitter/tree-sitter/discussions/1550#discussioncomment-8445285 | ||
| # | ||
| # It also seems like we need to define HAVE_ENDIAN_H to tell tree-sitter we have `endian.h` | ||
| # as it doesn't seem to pick up on that automatically? | ||
| # https://github.com/tree-sitter/tree-sitter/blob/0be215e152d58351d2691484b4398ceff041f2fb/lib/src/portable/endian.h#L18 | ||
| export CFLAGS_wasm32_unknown_unknown="-I$(pwd)/wasm-sysroot -Wbad-function-cast -Wcast-function-type -fno-builtin -DHAVE_ENDIAN_H" | ||
| # To just build the wasm-qmd-parser crate | ||
| # cargo build --target wasm32-unknown-unknown | ||
| # To build the wasm-pack bundle | ||
| # Note that you'll need `opt-level = "s"` in your `profile.dev` cargo profile | ||
| # otherwise you can get a "too many locals" error. | ||
| wasm-pack build --target web --dev | ||
| ``` |
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.
Some bonkers instructions on how to build it, you should probably turn this into something more official
Merges into
feature/wasmbranch