Cheerp C++ To Webassembly Compiler Now Open Source
Written by Nikos Vaggalis   
Tuesday, 11 April 2023

Cheerp is a C/C++ compiler for Web applications that lets you compile virtually any C/C++ code to WebAssembly and JavaScript. Its latest version 3.0 has been open sourced.

Cheerp is used primarily to port existing C/C++ libraries and applications to HTML5, but can also be used to write high-performance Web applications and WebAssembly components from scratch. Using Cheerp, C/C++ code gets compiled into JavaScript/WebAssembly as well as becoming optimised with the right JavaScript interfaces being exposed, and can be easily integrated in a web application.

Version 3 was recently released, comes packed with new features. At the same time it was open sourced under the “Apache 2.0 License with LLVM exceptions” license.This is big news for everyone one wanting to use it under more permissive terms since previously it was licensed under the GPLv2 / dual commercial licensing model.

Cheerp is part of a family of Webassembly compiling tools alongside CheerpJ, CheerpX for Flash and WebVM. Back in February 2020 we looked at CheerpJ, the Java equivalent, which  could be used in the following scenarios :

  • The conversion of legacy Java applications and Java Applets to HTML5 with minimal or no effort, to extend their life until deprecation, or until a replacement native HTML application has been developed.
  • The migration of an existing Java client to a browser-based web application, usually by converting the business logic from Java to WebAssembly/JavaScript with CheerpJ, and rewriting the UI in native HTML.
  • Using (converted) Java libraries as part of a native web application.

Behind the scenes CheerpJ requires a full Java SE runtime in WebAssembly and JavaScript which lives inside the browser, plus sporting a JavaScript/DOM interoperability API that allows accessing and manipulating the DOM from Java.

In contrast Cheerp for C++ doesn't require such a runtime and directly uses the LLVM bytecode format as the intermediate representation for both object files and libraries. It works its magic as follows:

  • Code is parsed, eventual warnings and errors are emitted, and then a equivalent IR (=Internal Representation) encoding the input program is generated.
  • The IR is optimised by a series of transformations into more compact & more performant IR.
  • The optimised IR is finally code-generated as a combination of JavaScript and WebAssembly functions and variables.

Or in simple terms:  

  C++ codebase   ->    
        Cheerp (with LLVM’s optimizations)    -> 
                                                                  JS + Wasm

Once the .js and .wasm files are generated, it’s a matter of serving those two static files, embedding them into the relevant HTML pages, building functionality on top of the library’s API, and testing whether all is in order.The main file to be invoked is still a .js file, but a .wasm file is also loaded and run from the .js one.

While CheerpJ is not an open source product, Cheerp now is.

At this point it is important to note that tools from languageX-to-WebAssembly could now prove to be much more useful since WebAssembly has recently broken loose from the browser's constraints and can now be used for running Microservices and Serveless functions or even run Wasm binaries on the command line so that even cross-platform CLI applications can be developed.

As such, a permissive license further reinforces the trend towards WebAssembly's wider adoption. cheeprlogo

More Information

Cheerp: A C++ compiler for the Web

Related Articles

CheerpJ Revitalizes Legacy Java Applications

Spin Brings WebAssembly To The Cloud

Running PostgreSQL Inside Your Browser

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


RAG from Scratch
10/12/2024

The "RAG from Scratch" tutorial by Langchain coupled with the "RAG playground" are two great educational resources that will help you kickstart your journey with RAG.



OpenSilver Adds XAML Designer For Visual Studio Code
12/12/2024

OpenSilver 3.1 has been released. This version adds a drag-and-drop XAML designer for Visual Studio Code (VS Code), a new modern UI theme, and expanded support for WPF features. The open-source altern [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Tuesday, 11 April 2023 )