-
Notifications
You must be signed in to change notification settings - Fork 139
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
Wasm support #135
Comments
Yah this isn't viable yet, but maybe soon. There's a few dependencies that rely on C. The only one that's difficult to get out is fancy-regex, and that's being worked on in #34. Once fancy-regex works though, then it shouldn't be too hard to wrangle the rest of the dependencies to work in WASM. |
@trishume It looks like a big part would be the use of maybe something like |
@FreeMasen I could when fancy-regex arrives, but right now it wouldn't do much good since then you'll just hit a different error about Oniguruma that won't have an easy fix. |
Now that fancy-regex is implemented according to #270, is this issue still on the radar? |
Dunno, it might just work™ now with wasm. If someone tries it and confirms that it works I can close this issue, but hopefully it does as long as you use the fancy-regex cargo feature and maybe disable some other cargo features that might load C things but aren't necessary if using internal dumps, like yaml and theme loading. |
It seems it does compile indeed 👍 . For reference I just cloned the repo, ran: rustup target add wasm32-unknown-unknown Changed the [lib]
crate-type = ["cdylib", "rlib"] and then ran: cargo build --target wasm32-unknown-unknown which runs with no errors. The next steps I'd like to play around with would be to start adding WASM bindings and create a minimal example of highlighting in the browser. |
Update: I got a little end-to-end demo of syntect highlighting running in the browser: https://syntect-wasm-demo.alexpeattie.com/ The source is here. Everything worked great, it was all very easy to set up 👏 ! I think this issue can be closed probably. @trishume - would you be interested in adding Wasm bindings to syntect at all? Or would you prefer to have some 3rd party bindings implemented elsewhere? |
@alexpeattie Nice demo! I think given that there's a bunch of different ways you might want to use syntect in wasm, and it should be doable as a separate crate, it probably makes more sense for it to be a different repo/library. However if anyone makes bindings I'm happy to link to them in the syntect Readme! |
That works but currently this library, when theme set and syntax set are loaded (with |
Without the |
@keith-hall, From what I can tell, the themes and syntax set are inside a single binary. It doesn't seem like individually load syntax sets and themes. Can you link me any documentation/example(s) for this? |
https://docs.rs/syntect/4.4.0/syntect/parsing/struct.SyntaxSetBuilder.html#impl |
Yah I think the way to go for WASM is to build a custom syntax pack file with only the syntaxes you need. You may also want to experiment with both compressing and not compressing it to save the size of the decompression in the WASM. Or depending on your app making multiple pack files and loading the required ones on demand. Then the build for WASM can also disable the cargo features for parsing the text formats to save binary size. |
That defiantly helps with the size of the built output but the performance is slow when using I have not tested if these changes solves the compilation error that occurs when compiling |
Update: updating to |
Using fancy_regex is terribly terribly slow, it takes about 100ms to highlight around 80 lines of Rust split over 6 code blocks. For each code block I'm creating a new ParseState, but I see that they can cached. How does that work? Can I keep the regex's compiled instead of rebuilding them for each block? In its current state is pretty much unusably slow in the browser. Either some serious caching would need to kick in, some sort of pre-rendering, or just switching to something like prism or highlighter.js which have a simpler less-robust take on highlighting. |
That was a super cool demo! I'm sure there are opportunities for more improvements in this area, but since the original "Wasm support" problem is not around any more, I think it makes perfect sense to close this issue now, as discussed in #135 (comment) and #135 (comment) Any follow-up problems are better handled in individual issues with to-the-point descriptions. |
Hi,
I'm trying to build a pure wasm version of UnicornConsole (https://github.com/Gigoteur/UnicornConsole) which use syntect for code editing. But right now I'm getting an error with same-file crate dependency:
--> /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/same-file-0.1.3/src/lib.rs:90:9
|
90 | imp::Handle::from_path(p).map(Handle)
| ^^^ Use of undeclared type or module
imp
error[E0433]: failed to resolve. Use of undeclared type or module
imp
--> /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/same-file-0.1.3/src/lib.rs:95:9
I'm opening the issue here to understand if you need this dependency or not, because it seems not really needed ?
Thank you
The text was updated successfully, but these errors were encountered: