All Projects → s0l0ist → bazel-emscripten

s0l0ist / bazel-emscripten

Licence: MIT license
C++ to WASM or JS using Bazel and Emscripten

Programming Languages

Starlark
911 projects
javascript
184084 projects - #8 most used programming language
C++
36643 projects - #6 most used programming language
shell
77523 projects
HTML
75241 projects

Projects that are alternatives of or similar to bazel-emscripten

Xrtl
Cross-platform Real-Time Rendering Library
Stars: ✭ 108 (+170%)
Mutual labels:  bazel, emscripten
bazel-boost
A bazel workspace for using boost
Stars: ✭ 12 (-70%)
Mutual labels:  bazel
Rules haskell
Haskell rules for Bazel.
Stars: ✭ 196 (+390%)
Mutual labels:  bazel
Index Import
Tool to import swiftc and clang index-store files into Xcode
Stars: ✭ 240 (+500%)
Mutual labels:  bazel
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+415%)
Mutual labels:  bazel
Bazel Watcher
Tools for building Bazel targets when source files change.
Stars: ✭ 245 (+512.5%)
Mutual labels:  bazel
Podtobuild
An easy way to integrate CocoaPods into Bazel
Stars: ✭ 193 (+382.5%)
Mutual labels:  bazel
bazel-maven-proxy
A local (read-only) proxy for Bazel to access Maven resources behind a secure repository or from the local Maven repository
Stars: ✭ 22 (-45%)
Mutual labels:  bazel
rules openapi
🍃 bazel rules for generating code from openapi specifications
Stars: ✭ 49 (+22.5%)
Mutual labels:  bazel
Bazel Compilation Database
Tool to generate compile_commands.json from the Bazel build system
Stars: ✭ 236 (+490%)
Mutual labels:  bazel
Rules kotlin
Bazel rules for Kotlin
Stars: ✭ 235 (+487.5%)
Mutual labels:  bazel
Rules apple
Bazel rules to build apps for Apple platforms.
Stars: ✭ 217 (+442.5%)
Mutual labels:  bazel
roswasm suite
Libraries for compiling C++ ROS nodes to Webassembly using Emscripten
Stars: ✭ 62 (+55%)
Mutual labels:  emscripten
Trunk
Make bazel an out of box solution for C++/Java developers
Stars: ✭ 203 (+407.5%)
Mutual labels:  bazel
bazel-stack-vscode
VSCode Extension for Bazel
Stars: ✭ 50 (+25%)
Mutual labels:  bazel
Xchammer
XCHammer generates Xcode projects from a Bazel Workspace.
Stars: ✭ 195 (+387.5%)
Mutual labels:  bazel
Rules python
Experimental Bazel Python Rules
Stars: ✭ 233 (+482.5%)
Mutual labels:  bazel
Rules rust
Rust rules for Bazel
Stars: ✭ 241 (+502.5%)
Mutual labels:  bazel
perl.js
emscripten build settings for perl
Stars: ✭ 31 (-22.5%)
Mutual labels:  emscripten
helloworld-sdl2-opengl-emscripten
Basic program that uses SDL2+OpenGL, compiling both locally and via emscripten
Stars: ✭ 71 (+77.5%)
Mutual labels:  emscripten

Hello World (C++ to WASM) using Bazel with Emscritpen

This repository demonstrates compiling C++ code with Bazel to WebAssembly. This repo no longer shows the build to pure JS as this led to very large libraries that were no where near as fast as their WASM counterparts.

Works with the following versions (as of 12/10/2022):

  • bazel 5.3.2
  • emscripten 3.1.23

Link to blog post

This repository has changed since the time of the article. This approach uses the official bazel + emscripten configuration which simplifies the codebase significantly (and it keeps everything in the bazel ecosystem).

We illustrate how to integrate multiple cc_library targets from different cpp packages to build a JavaScript file containing WASM.

The generated outputs have been configured in 'single file' mode. This means instead of handling a separate .wasm file, the wasm binary is encoded as a base64 string and is embedded into a JS file along with emscripten's glue code. The result is a single file that works in almost any environment provided it supports WebAssembly without the need to host, serve, or initialize a .wasm binary directly. The caveat is that the file size is 33% larger due to the encoding.

Requirements

This project assumes you have bazel. You should install bazelisk.

Code structure

Compiling

First, clone the repository

git clone https://github.com/s0l0ist/bazel-emscripten.git

Now, you can simply run a script to build the WASM version:

npm run build

To bundle:

npm run rollup

To clean the repository:

npm run clean

Example

After you have built and bundled the code, you can run the demo:

  • npm run demo will execut the WASM code
npm run demo

> [email protected] demo
> RUN_DEMO=wasm node ./hello-world/javascript/examples/demo.js

Sat Dec 10 18:56:47 2022
Hello, World!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].