Emscripten 4.0 is now available, a compiler from C/C++ to WebAssembly

The release of Emscripten 4.0 has been published, allowing the compilation of code in C/C++ and other languages that have frontends based on LLVM into a universal low-level intermediate WebAssembly code. The resulting output can be used for integration with JavaScript projects, running in web browsers, utilizing Node.js, or creating standalone cross-platform applications executed via a wasm runtime. The project code is licensed under the MIT license. The compiler uses developments from the LLVM project, and the Binaryen library is used for generating WebAssembly and optimization.

The primary goal of Emscripten is to create a tool that allows code to run on the Web regardless of the programming language in which it was originally written. The compiled applications can use calls to standard C and C++ libraries (libc, libcxx), C++ extensions, multithreading based on pthreads, POSIX APIs, and many multimedia libraries. API support is separately provided for integration with Web APIs and JavaScript code.

Emscripten supports the translation of SDL2 library output through Canvas and implements support for OpenGL and EGL via the WebGL API, enabling the conversion of graphical applications and games to WebAssembly (for example, there is a port of the Qt toolkit, and game engines such as Unreal Engine and Unity are supported, as well as the Bullet physics simulation engine).

In addition to compiling code in C/C++, projects for running interpreters in browsers are being developed separately, of virtual machines for languages such as Lua, C#, Python, Ruby, and Perl. Moreover, it is possible to apply frontends to LLVM that are different from Clang, such as frontends for languages like Swift, Rust, D, and Fortran.

The assignment of version number 4.0 is related to changes that break compatibility at the ABI level (rebuilding a project in Emscripten 4.0 will require rebuilding object files and libraries compiled with previous versions of Emscripten). The main changes in Emscripten 4.0 are:

  • An option "-sWASM_LEAGCY_EXCEPTIONS" has been added to choose between the old and new exception handling mechanisms. By default, the old mechanism is still used, as not all browsers have implemented the capabilities of WebAssembly for handling the new exception handlers.
  • The components compiler-rt, libcxx, libcxxabi, and libunwind have been updated to LLVM branch 19.
  • The minimum supported version of the Safari browser in builds (setting MIN_SAFARI_VERSION) has been raised from 14.1 to 15.0, enabling several advanced WebAssembly features by default.
    • The use of new instructions for converting float to int (nontrapping-fptoint) is enabled, which instead of generating an exception on overflow returns the minimum or maximum possible value (necessary for SIMD).
    • The WASM_BIGINT option is enabled, where the BigInt type is used for exchanging 64-bit integer values between WebAssembly and JavaScript code.
    • The BULK_MEMORY option is enabled, implementing C functions memcpy and memset using the WebAssembly instructions memory.copy and memory.fill.
  • Path normalization (PATH.normalize()) is disabled in the PATH.basename() function, meaning that calling ‘PATH.basename(«a/.»)’ will now return «.» instead of «a», and ‘PATH.basename(«a/b/..»)’ will return «..» instead of «a».
  • When using the ‘-sMODULARIZE’ option, factory functions that create and return instances of WebAssembly modules and objects for JavaScript are now marked as ‘async’ when compiled with the WASM_ASYNC_COMPILATION mode, which is applied by default.
  • Added the ability to specify JavaScript libraries using the ‘-lfoo.js’ option. Unlike the ‘—js-library’ option, the library search is performed in all paths specified via the ‘-L’ option.
  • When compiling in debug mode (-O0 or -sASSERTIONS), a debug variant of the malloc function with enabled assert checks is used by default, detecting errors such as double calls to the free() function.

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster