Skip to content

feat(infra): add Rust (workers-rs) Cloudflare Worker example - #38

Merged
cooper (czxtm) merged 3 commits into
mainfrom
feat/rust-worker-example
Oct 26, 2026
Merged

cooper (czxtm) merged 3 commits into
mainfrom
feat/rust-worker-example

Conversation

@czxtm

@czxtm cooper (czxtm) commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a Cloudflare Worker written in Rust with workers-rs, deployed by the existing Alchemy stack. Alchemy does not compile Rust, so a Command.Build runs worker-build first and a bundle: false Worker uploads its output.

 crates/
 ├── alloy-web3-example/
+└── cloudflare-worker-example/   # workers-rs crate: GET / -> GREETING var, GET /artifacts -> R2 list
 packages/infra/
 ├── alchemy.run.ts               # + yield RustCloudflareWorker, output rustCloudflareWorkerUrl
 └── src/
+    └── rust-cloudflare-worker.ts # Command.Build(worker-build) -> Cloudflare.Worker(bundle: false)
 nix/flake/devShells/default.nix  # + pkgs.worker-build, pkgs.lld
alchemy deploy
  RustCloudflareWorkerBuild   worker-build --release in crates/cloudflare-worker-example
                    skipped when src/, crate + workspace Cargo.toml, Cargo.lock, .cargo/config.toml are unchanged
  RustCloudflareWorker        main = build.outdir/index.js, uploads index.js + index_bg.wasm
                    env: ARTIFACTS (the stack's R2 bucket), GREETING

The crate is a Cargo workspace member, so host cargo check/test --workspace covers it. It sets rust-version = "1.88" because workers-rs 0.8 pulls in wasm-streams 0.6.

Reference docs for the team: darkmatter/skills#20 (Alchemy skill, examples.md).

Evidence

Live on Cloudflare (Alchemy 2.0.0-beta.81, throwaway stages, destroyed after):

  • First deploy: RustWorkerBuild created, then RustWorker created; GET / returned the greeting, GET /artifacts listed an object uploaded to the R2 bucket.
  • Redeploy with no changes: RustWorkerBuild noop, RustWorker noop.
  • Rust source edit: build updated, Worker updated, response showed the new text.
  • Root Cargo.toml edit: RustWorkerBuild updated, RustWorker updated — Uploading worker (196.57 KB).
  • alchemy dev: Worker served on localhost:1337 and reloaded after a manual worker-build --release.
  • Destroy: Cloudflare API shows no leftover Workers, R2 buckets, D1 databases, or queues for the stages.

Checks in the Nix devshell, all exit 0: bun run check, bun run test, bun run lint, bun run fmt:check, cargo check --workspace, cargo test --workspace, cargo fmt --all -- --check, nix flake check.

Merge Danger

Door: two-way

Revert removes the crate, the stack entry, and the devshell packages.

Blast Radius: deploys

Every alchemy deploy/alchemy dev of packages/infra now creates this Worker and needs worker-build, the wasm32 std, and lld whenever the build runs. The Nix devshell provides them; a non-Nix machine does not. GitHub CI is unaffected: it runs no Alchemy and only builds the crate for the host on stable Rust.

@czxtm
cooper (czxtm) merged commit a43d761 into main Oct 26, 2026
1 check passed
@linear-code

linear-code Bot commented Oct 26, 2026

Copy link
Copy Markdown

ENG-1227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant