LSP.js: Using Wasm and JavaScript to support OCaml on Windows
Blog post from Semgrep
Semgrep, a static analysis security testing (SAST) tool, has faced challenges in providing native support for Windows, primarily due to difficulties with compiling OCaml on Windows and the limitations of the Windows Subsystem for Linux (WSL). To address this, Semgrep has leveraged a previous hack project that transpiled OCaml to JavaScript, allowing the tool to run on Windows using the Node JavaScript engine. This approach required mapping Unix-specific system calls to Node's OS-agnostic primitives and addressing various Windows-specific issues, such as handling file line endings and adapting file system paths. Additionally, compiling parsers to WebAssembly (Wasm) was initially slow due to a specific LLVM optimization pass, which was eventually mitigated by contributing a patch to disable unnecessary optimizations. The result is a JavaScript-based Semgrep Language Server that supports Windows, enabling developers to receive security feedback during the coding process across different environments.