Edge
Two builds reach the edge. -e edge makes a single-threaded WebAssembly module and loader for a Cloudflare Worker. -e http makes a WASI HTTP component, a C++ request handler with no JavaScript, for wasmtime serve, Spin and wasmCloud.
Cloudflare Workers
Workers run JavaScript in V8 isolates, with no Web Workers and no SharedArrayBuffer, and there is no bundler plugin: the Worker imports the build output itself. Install the CLI and name the project, which names the output files:
Without a bundler, the build binds every .h file in src/native, so a port is reached through a header of your own. Build; the loader and its wasm land in dist:
Native is a class in src/native/native.h. Workers cannot compile WebAssembly from bytes, so the Worker imports the .wasm as a module and getWasmFunction (Runtime API) hands it to the loader. initNative() starts once per isolate.
Start it in the handler, not with a top-level await: Workers forbid random numbers in global scope, and Rust's standard library asks for some as the module starts. The build also writes dist/edge/wasm.mjs, which does both imports and exports initNative and every bound name; a package publishes it as its edge entry (Publishing packages).
Wrangler bundles the .wasm import with no extra rules:
To start from a working Worker instead, npm create crossbind@beta -- my-worker Cloud "Cloudflare Worker" scaffolds one.
Limits
- Single-threaded only.
-r mtanduseWorkerneed Web Workers, which an isolate does not have. - Files live in memory.
m.FSkeeps them only as long as the isolate, and there is no OPFS. Keep durable data in a store such as R2 or KV and pass it in from JavaScript. - No header constants.
#defineandconstvalues bind only for names an app imports, and a Worker imports no header. - Platform caps. A free Worker gets 10 ms of CPU per request, and every plan caps a Worker's size; check your
.wasmagainst yours.
WASI HTTP components
-e http links your C++ into a component that exports wasi:http/[email protected] (the wasi:http/service world). There is no main() and no JavaScript: src/native defines the one function <crossbind/http.h> declares, and the host calls it for each request.
Spin 4 serves the same file from a manifest, with spin up:
wasmCloud's wash dev takes it as build.component_path in .wash/config.yaml. The build compiles like a WASI command, and ports link from their -wasi packages.
Requestcarriesmethod,authority,pathandqueryas the client sent them,headerswith lowercase names, andbody, read whole beforehandleruns.Responseisstatus(200 unless set),headersandbody.- An exception out of
handleanswers 500 and logscrossbind: <method> <path> threw: <what>to stderr. - A host can reuse one instance for many requests, so static state outlives a request. Calls of
handlenever overlap, but one can run while an earlier response body is still being written. - Each request runs on a 1 MiB stack of its own;
-Wl,-z,stack-size=<bytes>inbinary.wasiFlagschanges it.
Not there yet: outgoing requests (wasi:http/client), streamed request and response bodies, trailers, threads, Rust, and the data files and environment of dependencies such as PROJ, GDAL and OpenSSL, which no host passes to a component. The component also imports the wasi:cli environment, exit and terminal interfaces, so a host that offers only the wasi:http/service imports rejects it.
examples/cloud-cloudflare-worker is a complete Worker; e2e/cloud-wasi-http builds a component and tests it under wasmtime serve and Spin.