Skip to content

Rewrite the command generator in Rust - #299

Draft
penalosa wants to merge 1 commit into
mainfrom
penalosa/rust-generator
Draft

penalosa wants to merge 1 commit into
mainfrom
penalosa/rust-generator

Conversation

@penalosa

@penalosa penalosa commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Rewrites cf's command generator, previously a TypeScript forge plugin compiled to WebAssembly, as a native Rust crate in packages/generator.

What changed

  • packages/generator/: new cf-generator crate. It uses forge as a library (a git dependency pinned to a commit) and implements forge::Plugin directly against forge's model, so there's no WebAssembly component or wit-bindgen layer. Its only other dependencies are serde and serde_json, which type the emitted metadata. The emitters write TypeScript with writeln! and leave whitespace to vp fmt.
  • packages/cli/generator/run.ts: runs the crate with cargo run --release --locked, passing the hand-written registry and meta.ts sidecars as JSON. generate.ts and the test helpers use it.
  • Removed: the TypeScript plugin (generator/plugin/, generator/index.ts), the task:generate:plugin task, the vendored @cloudflare/forge tarball, @bytecodealliance/jco, and scripts/sync-forge.ts.
  • Tests: the plugin's TypeScript unit tests are ported to Rust (cargo test). The forge-model and hand-written-roots tests now run the Rust binary.
  • CI: the check job runs cargo fmt --check, cargo clippy -D warnings, and cargo test --locked.
  • Docs: AGENTS.md files are updated for the new layout.

Verification

The oracle is the generated output: pnpm generate leaves packages/cli/src/commands/_generated/ byte-for-byte unchanged, so this PR contains no generated diff.

  • pnpm check passes.
  • CLI tests: 1542 passed, 6 skipped.
  • Rust: 48 tests pass, and fmt and clippy are clean.

No changeset is included, since the CLI output is unchanged.

Note: generation now needs a Rust toolchain (1.88+). On first run, cargo fetches and compiles forge.

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@299

commit: 9c91794

@github-actions

Copy link
Copy Markdown
Contributor

cf --help startup

mean stddev min max
PR 175.8 ms 3.4 ms 170.1 ms 181.0 ms
base 182.5 ms 4.9 ms 172.7 ms 197.1 ms

Δ (PR vs base): ↓ -6.6 ms (-3.6%)

Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.

@ask-bonk

ask-bonk Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@penalosa
penalosa force-pushed the penalosa/rust-generator branch from 9c91794 to 9cb7ade Compare October 13, 2026 21:31

@srikrsna srikrsna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, the only question is how much overhead does cargo run add

Comment on lines +71 to +76
if group.parent().is_some() {
return Ok(Vec::new().into_iter());
}
let ops = operations(iter::once(group).chain(group.descendants()));
let command = commands::command(group, &mut Vec::new());
Ok(files::command_files(&ops, &command, &self.hand)?.into_iter())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the handwritten config is already here, if we generate one group at a time, instead of collecting all sub groups, this will run highly concurrently

Comment thread pnpm-workspace.yaml

@NuroDev NuroDev Oct 14, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a helpful FYI: pnpm supports Cargo workspaces too now https://pnpm.io/cargo 🎉

@petebacondarwin
petebacondarwin requested review from a team and petebacondarwin and removed request for a team October 23, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants