workerd/clippy.toml
Dan Lapid e697d63925 server: add the C++ worker factory and the Rust server crate
The new server is added beside the C++ one and is not yet part of the
`workerd` binary; the next commit switches the binary over and deletes
`server.c++`. Here it builds, and the crate's unit tests run.

The `workerd-server` crate (`server/`) drives a C++ `WorkerFactory`
(`factory/`) through one cxx bridge (`server/bridge.rs`), the one module
of the crate that allows `unsafe`. The two depend on each other through
that bridge, so they land together. The bridge's async functions that
borrow their arguments are declared `async unsafe fn f<'a>`, the form the
in-tree cxx requires of a future that is not `'static`.

The factory keeps everything that touches the isolate: compiling a worker,
starting a request on it, constructing actors with their storage, alarms
and containers, the capnp RPC servers, channel-token encoding, the
inspector, and the single-tenant policy objects. The server owns the rest:
config interpretation, bindings and channel numbering, services,
listeners, actor lifecycle and eviction, dynamic workers, drain and the
test runner. A worker's bindings cross as one message: the server
interprets `Worker.bindings` and `ctx.exports` into `Globals`
(`compiled-bindings.capnp`), every capability a channel number, and a new
`WorkerdApi::compileGlobals` overload reads that message. The overload
taking `WorkerdApi::Global` stays for `server.c++` until the switch.
`server/entry.rs` owns the process's schedule: `factory/bootstrap.c++`
sets up logging around the command, a `kj_rs_tokio::Runtime` builds the
KJ loop with its tokio runtime, the bootstrap sets up perfetto, autogates
and V8 on it and builds the factory, and the command blocks on the server
as a task on that loop. Sockets are bound and external servers dialed
through kj-rs-io's Rust API, and HTTP in both directions is hyper through
kj-hyper.

Alongside:

- `build/wd_rust_crate.bzl` gains `cxx_bridge_visibility`, so that the
  factory's C++, in another package, can include the server crate's
  bridge header.
- `deps/rust/Cargo.toml` adds `httpdate`, `percent-encoding` and `url`
  (the disk service), `data-encoding` (CryptoKey bindings), `glob` (test
  filters) and `ipnet` (`allow` / `deny` ranges).
- `clippy.toml` adds `SQLite` and `WebSockets` to `doc-valid-idents`, for
  the new doc comments.
- `json-logger.h` declares `buildJsonLogMessage`, which the server's
  command-line log lines use.
- `:channel-token`, `:v8-platform-impl` and `:workerd_capnp` are visible
  to the new subpackages.

Size, by `wc -l` without the `-test.rs` files: the server crate is 9,779
lines, the factory 3,821 and `compiled-bindings.capnp` 107, together
13,707 against the 9,193 they replace (`server.c++`, `server.h`,
`cli-main.{h,c++}`): 1.49x. The crate's unit tests are another 1,412
lines in eight `-test.rs` files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-12 22:02:46 -04:00

6 lines
245 B