Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.13 KB

README.md

File metadata and controls

37 lines (25 loc) · 1.13 KB

Template for C/C++ Cloudflare Workers

A minimal template for running C/C++ code on Cloudflare Workers using WebAssembly and Emscripten. This is a trimmed down version of cloudflare/worker-emscripten-template.

Usage

1. Compile to WebAssembly

# Using Emscripten 2.0.25
emcc -O2 pi.c -o pi.js \
  -s INVOKE_RUN=0 \
  -s EXPORTED_RUNTIME_METHODS=["callMain"] \
  -s ENVIRONMENT="web" \
  -s MODULARIZE=1

Notes:

2. Bind .wasm files to variables

Next, define the WebAssembly modules and their bindings in wrangler.toml:

wasm_modules = { PI_WASM = "./pi.wasm" }

See index.js to see how this PI_WASM variable is used to initalize the WebAssembly module.

3. Deploy

wrangler publish