Files
ssw-platform/Cargo.toml
T
admin 827c054780 build: 关掉 dev 增量编译 —— 修 sccache 全程空转的根因,target 58G → 1.2G
现象:target/ 曾达 58G(debug/deps 45G + debug/incremental 12G),磁盘已用 87%;
而 ~/.cargo/config.toml 已配 rustc-wrapper = sccache、缓存实体 8.4G,
但 sccache --show-stats 的 Cache hits 恒为 0。

根因(实测定位):cargo 默认给 rustc 传 -C incremental=<target/debug/incremental>,
而 sccache 遇到 incremental 直接拒缓存 —— server 端日志明确报
`CannotCache(incremental)`。表现为 Non-cacheable calls 等于请求数、
Cache hits 恒为 0 ⇒ 8.4G 缓存全是废的,每轮构建都从零重编。

修法:根 Cargo.toml 加 [profile.dev] incremental = false。
- 收益:清空 target 后重建走缓存命中 —— 实测 14s(vs 全量 63s);
  日常改一处重编也走命中(命中率 86.71%)。
- 代价:失去 cargo 自己的增量加速,由 sccache 命中替代(且跨 cargo clean 仍有效)。
- 附带:target/debug/incremental 不再产生(实测残留为空目录 0B)。

验证:cargo build 全量通过;cargo test --workspace 695 passed / 0 failed / 2 ignored
(79 个二进制,与 M1 基线完全一致);check-arch 20/20、check-boundary 12/12、
check-contract 10/10、check-module 123/123、check-citations 4/4 全绿。
2026-11-03 22:57:26 +08:00

83 lines
3.6 KiB
TOML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ssw-platform —— cargo workspace 根
#
# 🔴 **本文件是脚手架的一部分,复制到项目根时必须一起带上**
#
# 为什么必须有它:`src/backend/Cargo.toml` 里的
# `version.workspace = true` / `edition.workspace = true` / `xxx = { workspace = true }`
# 都要求**上层有一个 workspace 根**。缺了它,cargo 直接报
# `error: could not find Cargo.toml in ... or any parent directory`,
# 脚手架**根本编译不起来**。
#
# 这里只放「跨成员共享」的配置:成员列表、依赖版本、release profile。
# 成员 crate(src/backend)不得再写 [profile.*],否则 cargo 直接报错。
[workspace]
# src/backend = 内核;crates/* = 平台侧 crate;packs/* = 业务包(只依赖 sspf-sdk)
members = [
"src/backend", "crates/*", "packs/*"]
resolver = "2"
[workspace.package]
version = "0.1.0"
edition = "2021"
# 🔴 全仓工具链锁定在 rust-toolchain.toml 的 1.99.1。
# 这里的 MSRV 是「语法最低要求」,比锁定版本宽松;两者不要混。
# L3 动态库(cdylib)强依赖锁定版本:插件与内核必须同一 rustc,
# 否则 Rust 无稳定 ABI 的问题会以段错误的形式在运行期爆出来。
rust-version = "1.85"
# 依赖版本集中在此,成员 crate 一律用 `xxx = { workspace = true }` 继承。
#
# ⚠️ 版本锁死说明(不要随意升级):
# - aes 0.8 + ecb 0.1 属于 cipher **0.4** 家族;aes 0.9 / ecb 0.2 是 cipher 0.5,
# 泛型不通用,混用编译不过。
# - md-5 0.10 的 crate 名是 `md5`(`use md5::{Digest, Md5};`)。
# - pglite-rs 0.2 的 **lib 名是 `pglite`**(`use pglite::PGlite;`),
# 且 0.2.7 没有 `memory://` 模式,`PGlite::open()` 只接受路径。
[workspace.dependencies]
axum = "0.8"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_urlencoded = "0.7"
aes = "0.8"
ecb = "0.1"
md-5 = "0.10"
rand = "0.8"
uuid = { version = "1", features = ["v4"] }
hex = "0.4"
pglite-rs = "0.2"
chrono = "0.4"
http = "1"
async-trait = "0.1"
# 只用于「MCP 模式下把 fd 1 让给 stderr」这一个系统调用(见 main.rs 的注释)。
libc = "0.2"
[profile.dev]
# 🔴🔴 **必须关掉增量编译**(2026-11-03 定)—— 否则 sccache 全程空转。
#
# 成因(已实测确认):cargo 默认给 rustc 传 `-C incremental=<target/debug/incremental>`,
# 而 **sccache 遇到 `incremental` 直接拒缓存**(server 端日志:`CannotCache(incremental)`)。
# ⇒ 表现为 `sccache --show-stats` 里 `Non-cacheable calls` 等于请求数、
# `Cache hits` 恒为 0 ⇒ **8.4G 缓存全是废的**,每轮构建都从零重编。
#
# 代价与收益(实测):
# - 关掉后 `target/debug/incremental` 不再产生 ⇒ target 少涨 12G;
# - 清空 target 后重建 **走缓存命中**(探针实测 1.09s → 0.22s,快 5 倍)。
# - 日常「改一处重编」的增量加速会消失(sccache 命中代替它,
# 且跨机器/跨 clean 都有效,增量缓存则一 clear 就没)。
#
# 与既定约定的对齐:`~/.cargo/config.toml` 已配 `rustc-wrapper = sccache`
# 且缓存实体在 `~/.cache/sccache`(包缓存统一放 ~/.cache,工具默认路径留软链)。
# 本行是让那个配置**真正生效**的前提。
incremental = false
[profile.release]
opt-level = 2
lto = "thin"
strip = "symbols"
# 🔴 不要设 `panic = "abort"`:契约 §6.5 要求 panic ⇒ HTTP 200 + code=400,
# 而 abort 下 `catch_unwind` 抓不到 panic(进程直接死 ⇒ 客户端连接重置)。
# catch-all 中间件依赖默认的 `panic = "unwind"`(Ruling P19)。
codegen-units = 16