Skip to content

robertaboukhalil/cf-workers-emscripten

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Template for using Cloudflare Workers with WebAssembly and Emscripten

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Languages

  • C 72.5%
  • JavaScript 20.6%
  • Shell 6.9%