Files
next.js/turbopack/crates/turbopack-cli/Cargo.toml
7984e4ab5c turbopack-cli: add --persistent-caching flag for filesystem-backed cache (#91657)
### What?

Adds `--persistent-caching` and `--cache-dir` CLI flags to `turbopack
dev` and `turbopack build` in the standalone `turbopack-cli` crate.

### Why?

The standalone `turbopack-cli` binary (used independently of `next`) had
no way to opt into the filesystem-backed persistent cache that the
`next-napi-bindings` integration already supports. Without this,
repeated builds always start cold — every incremental run re-computes
the full task graph from scratch.

### How?

**`build.rs` (new):** A Cargo build script that uses `vergen-gitcl` to
emit `VERGEN_GIT_DESCRIBE` and `VERGEN_GIT_DIRTY` as compile-time env
vars. These are used to key the cache by git version, matching the same
approach as `next-napi-bindings`. The build script embeds the dirty
state at compile time rather than runtime to avoid a git subprocess on
every startup.

The dirty-state caching tradeoff (explained in the build script
comment): there's a narrow edge case where the tree becomes newly dirty
without triggering a Cargo rebuild, but in practice this is safe — if
nothing in the crate changed, the binary is semantically equivalent to a
clean build, so using the HEAD hash as the cache key is correct.

**`arguments.rs`:** Two new flags on `CommonArguments` (shared by both
`dev` and `build` subcommands):
- `--persistent-caching` — opt-in flag to enable the filesystem cache
- `--cache-dir <PATH>` — override the cache directory (defaults to
`.turbopack/cache` in the project root)

**`dev/mod.rs` and `build/mod.rs`:**
- The `Backend` type alias changes from
`TurboTasksBackend<NoopBackingStorage>` to
`TurboTasksBackend<Either<TurboBackingStorage, NoopBackingStorage>>` to
unify the type without dynamic dispatch.
- When `--persistent-caching` is set: initializes `TurboBackingStorage`
via `turbo_backing_storage()`, selects
`StorageMode::ReadWriteOnShutdown` for CI/short sessions and
`StorageMode::ReadWrite` for interactive dev, and prints a warning if
the cache was invalidated on startup.
- When not set: falls back to `noop_backing_storage()` — identical
behavior to before.
- Respects the `TURBO_ENGINE_READ_ONLY` env var to force read-only mode.

---------

Co-authored-by: Tobias Koppers <[email protected]>
Co-authored-by: Claude <[email protected]>
2026-03-20 19:15:03 +01:00

88 lines
2.4 KiB
TOML

[package]
name = "turbopack-cli"
version = "0.1.0"
description = "TBD"
license = "MIT"
edition = "2024"
autobenches = false
[[bin]]
name = "turbopack-cli"
path = "src/main.rs"
bench = false
[lib]
bench = false
[[bench]]
name = "mod"
harness = false
[[bench]]
name = "small_apps"
harness = false
[features]
default = ["custom_allocator"]
serializable = []
tokio_console = [
"dep:console-subscriber",
"tokio/tracing",
"turbo-tasks/tokio_tracing",
]
profile = []
custom_allocator = ["turbo-tasks-malloc/custom_allocator"]
[lints]
workspace = true
[dependencies]
anyhow = { workspace = true }
bincode = { workspace = true }
clap = { workspace = true, features = ["derive", "env"] }
console-subscriber = { workspace = true, optional = true }
dunce = { workspace = true }
either = { workspace = true }
futures = { workspace = true }
owo-colors = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
swc_core = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["json"] }
turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-backend = { workspace = true }
turbo-tasks-env = { workspace = true }
turbo-unix-path = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-malloc = { workspace = true, default-features = false }
turbopack = { workspace = true }
turbopack-browser = { workspace = true }
turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true }
turbopack-css = { workspace = true }
turbopack-dev-server = { workspace = true }
turbopack-ecmascript = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, features = [
"transform_emotion",
] }
turbopack-ecmascript-runtime = { workspace = true }
turbopack-env = { workspace = true }
turbopack-node = { workspace = true, default-features = false, features = ["process_pool"]}
turbopack-nodejs = { workspace = true }
turbopack-resolve = { workspace = true }
turbopack-trace-utils = { workspace = true }
webbrowser = { workspace = true }
[build-dependencies]
anyhow = { workspace = true }
vergen-gitcl = { workspace = true }
[dev-dependencies]
criterion = { workspace = true, features = ["async_tokio"] }
regex = { workspace = true }
turbopack-bench = { workspace = true }
turbo-tasks-malloc = { workspace = true, features = ["custom_allocator"] }