Show HN: Cppbolt – A lightweight C++ to WebAssembly compiler written in Rust

Posted by ajtimepyro 2 days ago

Counter3Comment4OpenOriginal

Hey HN! I've been working on cppbolt, a lightweight C++ to WebAssembly compiler written in Rust.

The idea was to build something that can compile and run C++ directly in the browser without downloading a massive LLVM/Clang toolchain.

Unlike projects that bundle LLVM/Clang and can require 100+ MB of compiler assets, cppbolt's compiler payload is around 1 MB. It compiles a supported subset of C++17 directly to standard WebAssembly binaries.

Some things it supports: - Classes, inheritance, virtual functions and operator overloading - Templates and a subset of the C++ standard library - Pointers, references, arrays and dynamic memory - Lambdas, structured bindings and range-based loops

It comes with a browser playground, CLI and npm package.

A few caveats: this is still a work in progress, it doesn't implement the full C++17 standard, and it might not work as expected with certain C++ programs. I'm particularly interested in feedback on the compiler architecture, language support and potential use cases and also interested in connecting with someone who might want to use it in their application.

Try it out: - Playground: https://ajtimepyro.is-a.dev/cppbolt/ - Docs: https://ajtimepyro.is-a.dev/cppbolt/book/ - GitHub: https://github.com/AJTimePyro/cppbolt - npm: https://www.npmjs.com/package/cppbolt

Would love to hear what you think, especially from people who've worked on compilers or WebAssembly.

Comments

Comment by adamkumpf 2 days ago

WebAssembly really is the future of cross-platform apps. With so many existing C++ projects and optimized code, being able to convert them is highly useful.

Just curious, have you tried to open a cpp project and use a tool like Claude to just convert it to WebAssembly and compare? That would make a great data point if you can show that cppbolt can do it much better/faster.

Comment by ajtimepyro 1 day ago

Not yet, I think it will be worth testing if claude or other AI can convert to web assembly, I will try with some non-Gui Open-source C++ projects.(GUI applications will be harder since they require platform-dependent API layers)

Comment by Panzerschrek 1 day ago

A C++ compiler in three weeks? Is it vibe-coded?

Comment by ajtimepyro 1 day ago

In my Linkedin post https://lnkd.in/p/dSuXMv2h, I have mentioned that AI assisted me during development of this project, but it's not like a blind vibe coding, I always review the end code before committing them. Also it's a subset of C++ 17, so it still misses a lots of thing(But I will cover them as well).