Guyutongxue / clangd-in-browser

Port clangd language server to WASM, and run it in your browser.
https://clangd.guyutongxue.site/
MIT License
26 stars 5 forks source link

Why does the demo use compiler explorer? #6

Open EdHeller opened 1 week ago

EdHeller commented 1 week ago

Wouldn't it be better to compile to a wasm target and run that output in the browser? Similar to binji/wasm-clang just with nice syntax highlighting for Monaco.

Guyutongxue commented 1 week ago

There are lots of more things to do to run the compiled executable in browser. We are now using Emscripten for compiling llvm but those C++ code will be compiled to wasm32-wasi. So we also needs a browser-based WASI implementation. As a result, we will ship clangd/clang/lld in Emscripten-packaged environment (and filesystems), and also a WASI environment (and filesystem). This is too complicate (in my opinion).

There might be a solution to this, that is, just use WASI to compile and run everything, including LLVM and user-compiled programs. But I'd tried that LLVM on WASI cannot run inside browser (may be due to memory size limit?). And also, clangd -- a multi-threaded program -- is not available under wasi-preview2.

That's why I decided to use Compiler Explorer API for compiling stuff. If you have a better solution, you are welcomed to give a PR 😄