vercel/next.js
Crates
The Rust workspace at the root of the repo. Combined with the Turbopack subtree, the framework's Rust code spans 269,139 lines across 948 files in 69 Cargo crates. This page covers the Next.js-specific crates under crates/. The Turbopack crates have their own section: turbopack/.
Crate list
| Crate | Page | Role |
|---|---|---|
crates/next-core |
next-core | Translates Next.js config into Turbopack module options |
crates/next-api |
next-api | Public API: build a project, get entries, get manifests |
crates/next-build |
other-crates | Orchestrates a full build run |
crates/next-custom-transforms |
next-custom-transforms | SWC visitors for next/font, server actions, dynamic IO |
crates/next-napi-bindings |
next-napi-bindings | napi-rs glue exposed as @next/swc |
crates/wasm |
other-crates | wasm-bindgen wrapper |
crates/next-build-test |
other-crates | Test harness for the build |
crates/next-code-frame |
other-crates | Source-mapped code-frame error formatter |
crates/next-error-code-swc-plugin |
other-crates | SWC plugin that rewrites error-code helpers |
crates/next-taskless |
other-crates | Taskless integration |
How they relate
graph TD
NodeJS[Node.js<br/>packages/next] --> Bindings[next-napi-bindings<br/>napi-rs surface]
Bindings --> Api[next-api<br/>public crate API]
Api --> Core[next-core<br/>config + module options]
Api --> Build[next-build<br/>build orchestration]
Core --> CustomTransforms[next-custom-transforms<br/>SWC visitors]
Core --> Tp[turbopack-core<br/>+ siblings]
Wasm[crates/wasm] --> Api
BuildTest[next-build-test] --> Build
BuildTest --> Api
Bindings --> CustomTransformsThe dependency arrows are deliberate:
next-napi-bindingsis the only crate published as a Node-loadable binary. Everything else exists to support it.next-apiis the public API crate. It's stable enough that the JavaScript side reads its types and treats it as a contract.next-coreis where Next.js's opinions live: how to configure Turbopack to produce app-router bundles, edge bundles, server bundles, etc.next-custom-transformsis the SWC visitor library. Next.js's compiler quirks (server actions,next/font,'use server'/'use client'enforcement) are implemented as SWC passes here.next-buildorchestrates a full build by composing Turbopack project entries vianext-api.
Build outputs
graph LR
Source[Rust source] --> Cargo[cargo build]
Cargo --> Native[platform .node binary]
Cargo --> WasmBuild[wasm-bindgen]
Native --> Pkg[packages/next-swc/native/]
WasmBuild --> WasmPkg[wasm package]
Pkg --> Distro[npm @next/swc-{platform}]The pnpm swc-build-native script invokes cargo build --release -p next-napi-bindings. The scripts/install-native.mjs postinstall picks the right pre-built binary from npm when local builds aren't required. See packages/next-swc.
Workspace layout
The Cargo workspace is rooted at Cargo.toml and includes:
members = [
"scripts/send-trace-to-jaeger",
"crates/next-napi-bindings",
"crates/wasm",
"crates/next-api",
"crates/next-build-test",
"crates/next-build",
"crates/next-code-frame",
"crates/next-core",
"crates/next-custom-transforms",
"crates/next-taskless",
"turbopack/crates/*",
"turbopack/crates/*/fuzz",
"turbopack/xtask",
]
exclude = [
"crates/next-error-code-swc-plugin",
"rspack/crates/binding"
]The two excluded directories build standalone:
crates/next-error-code-swc-plugin— built into a standalone .wasm viacrates/next-error-code-swc-plugin/build-and-move.sh. SWC plugins are loaded as wasm modules.rspack/crates/binding— built independently for the rspack integration.
Toolchain
- Channel:
nightly-2026-04-02(rust-toolchain.toml) - Components: rustfmt, clippy, rust-analyzer
- Profile: minimal
The dev profile uses debug = "line-tables-only" for compile-time savings; deps build at opt-level = 1 to keep cold builds fast. The turbo-persistence crate is special-cased to opt-level = 1 even in the workspace because it is performance-sensitive.
How to build everything
# JS only (after bootstrap)
pnpm build
# JS + Rust native binaries
pnpm build-all
# Just the napi binding
pnpm swc-build-native
# Just the wasm
pnpm swc-build-wasm
# Run cargo directly
cargo build --release -p <crate>After branch switches, prefer pnpm build-all so dependent JS packages pick up Rust changes.
Linting and formatting
cargo fmt # ASCII-ordered import groups; just run it
cargo clippy # workspace lintsWorkspace lint config (in root Cargo.toml):
[workspace.lints.clippy]
too_many_arguments = "allow"
[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)', 'cfg(fuzzing)', 'cfg(codspeed)'] }Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.