Skip to content

saus-app/wasm-cf-boilerplate

Repository files navigation

wasm-cf-boilerplate

Boilerplate for deploying C++ via WASM to a Cloudflare Worker.

Usage

  1. It is assumed you have Emscripten (and NodeJS) installed. If not, you can use the EmSDK, or if you're on a Mac with Homebrew, simply brew install emscripten.
  2. Ensure the toolchainFile path in CMakePresets.json points to your Emscripten install (edit if necessary).
  3. From the repo root, install the Cloudflare tooling (i.e. wrangler) with npm install.
  4. If you're using VSCode, this repo is configured to work with CMakeTools + clangd + CodeLLDB + WASM DWARF Debug, and you can use their associated commands to build, execute & debug (P.S. Disable the regular C++ intellisense extension).
  5. If you're not on VSCode, you can still use the CMake presets:
  • Configure: cmake --preset debug-wasm-demo
  • Build: cmake --build --preset debug-wasm-demo
  • Replace debug-wasm-demo with release-wasm-demo to build for release.
  • Perhaps consult the Emscripten docs to set up debug tooling.

Notes

  • harness.js is the entrypoint for running/debugging under NodeJS:
    • You can run it with cd src && node harness.js.
    • This will only work for Debug builds (i.e. using the debug-wasm-demo CMake preset), as it compiles with -sENVIRONMENT=node,worker.
  • worker.js is the entrypoint for running under Cloudflare's local dev env:
    • You can run it with npx wrangler dev.
    • This will only work for Release builds (i.e. using the release-wasm-demo CMake preset), as it compiles with -sENVIRONMENT=worker.
  • Deployment to Cloudflare can be done using the regular npx wrangler deploy, but update wrangler.jsonc accordingly.
  • This has only been tried on Mac. Patches welcome for any other OS!

About

Boilerplate for deploying C++ via WASM to Cloudflare Worker

Topics

Resources

License

Stars

Watchers

Forks