Boilerplate for deploying C++ via WASM to a Cloudflare Worker.
- 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. - Ensure the
toolchainFilepath inCMakePresets.jsonpoints to your Emscripten install (edit if necessary). - From the repo root, install the Cloudflare tooling (i.e.
wrangler) withnpm install. - 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).
- 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-demowithrelease-wasm-demoto build for release. - Perhaps consult the Emscripten docs to set up debug tooling.
harness.jsis 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-demoCMake preset), as it compiles with-sENVIRONMENT=node,worker.
- You can run it with
worker.jsis 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-demoCMake preset), as it compiles with-sENVIRONMENT=worker.
- You can run it with
- Deployment to Cloudflare can be done using the regular
npx wrangler deploy, but updatewrangler.jsoncaccordingly. - This has only been tried on Mac. Patches welcome for any other OS!