Menu

How I run Clang and the real Go compiler entirely in the browser
πŸ“°

How I run Clang and the real Go compiler entirely in the browser

DEV Community: goΒ·Avinash KoriΒ·20 days ago
#uUD0mZTB
#devtogo#devto#dev#include#worker
Reading 0:00
15s threshold

Most online compilers work the same way: your code is sent to a server, compiled inside a container, and the output comes back. That works, but it means running a fleet of sandboxes, paying for them, rate-limiting them and trusting them with other people's code.

For the online compilers on Devtoolry I went the other way: the compiler itself runs in your browser . C and C++ are compiled by Clang 21 and Go by the official Go 1.27 compiler and linker, all as WebAssembly inside a Web Worker. Nothing is uploaded, and the server only serves static files.

This post covers how it works and the problems I ran into.

The architecture in one picture

page ──{ code, stdin }──▢ Web Worker β”œβ”€ download toolchain once (cached by the browser) β”œβ”€ compile + link in an in-memory file system β”œβ”€ WebAssembly.compile(main.wasm) └─ run it with a tiny WASI host (stdin/stdout/stderr, clocks) page ◀──{ output, exitCode }β”€β”˜

Enter fullscreen mode

Exit fullscreen mode

Each language has its own worker.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.