From cf4a275d26eee1d46d2c0cf4182d6010cb6a3c9d Mon Sep 17 00:00:00 2001 From: Linghong Date: Mon, 14 Sep 2026 08:52:01 +0000 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=20sccache=20=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B=E7=BB=93=E6=9E=9C=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在当前 dev 编排进程内复用 sccache wrapper 探测结果 避免 API 与 worker 重启重复同步等待 同步更新排障文档 --- docs/project-memory/shared-memory/pitfalls.md | 2 +- scripts/dev.mjs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/project-memory/shared-memory/pitfalls.md b/docs/project-memory/shared-memory/pitfalls.md index a99b093a4..cddbf819f 100644 --- a/docs/project-memory/shared-memory/pitfalls.md +++ b/docs/project-memory/shared-memory/pitfalls.md @@ -1211,7 +1211,7 @@ Cocos Creator 根目录由 `package.json.creator.version` 与普通 `assets/` - 现象:Windows 上执行 `npm run dev:api-server` 时,api-server 在 Cargo 启动阶段失败,日志出现 `error: multiple input filenames provided (first two filenames are ... rustc.exe and -)`,`/healthz` 无法访问。 - 原因:`server-rs/.cargo/config.toml` 默认配置 `rustc-wrapper = "sccache"`;本地 dev 脚本为了绕过损坏的 sccache 需要覆盖 wrapper。Windows 下如果把 `RUSTC_WRAPPER` 设置为 `rustc`,Cargo 会按 wrapper 协议调用 `rustc <真实rustc路径> - ...`,真实 rustc 把 wrapper 传入的 rustc 路径和 stdin `-` 都当输入文件。 -- 处理:Windows 本地 dev 脚本默认把两个 wrapper 设为空字符串;只有用户显式配置 `RUSTC_WRAPPER` 或 `CARGO_BUILD_RUSTC_WRAPPER` 时才处理 sccache。sccache 配置会先限时执行真实 `sccache rustc -vV` 探测,失败、超时或两个变量冲突时回退到直接 rustc;Linux 保持 `/usr/bin/env` 绕过 sccache。 +- 处理:Windows 本地 dev 脚本默认把两个 wrapper 设为空字符串;只有用户显式配置 `RUSTC_WRAPPER` 或 `CARGO_BUILD_RUSTC_WRAPPER` 时才处理 sccache。sccache 配置会在当前 dev 编排进程内只执行一次限时真实 `sccache rustc -vV` 探测,并缓存成功或失败结果;失败、超时或两个变量冲突时回退到直接 rustc,避免每次 API / worker 重启重复同步阻塞;Linux 保持 `/usr/bin/env` 绕过 sccache。 - 验证:`npm run test -- scripts/dev.test.ts -t "dev scheduler Rust build env"`;POSIX 显式配置 sccache 时日志应明确说明绕过并使用直接 rustc;再用 `npm run dev:api-server` 拉起后访问实际 api 端口的 `/healthz` 返回 200。 - 关联:`scripts/dev.mjs`、`scripts/dev.test.ts`、`docs/【开发运维】本地开发验证与生产运维-2026-05-15.md`。 diff --git a/scripts/dev.mjs b/scripts/dev.mjs index 62d4f2732..ebedfea92 100644 --- a/scripts/dev.mjs +++ b/scripts/dev.mjs @@ -146,6 +146,8 @@ function applyLocalFfmpegEnv(env, platform = process.platform) { return env; } +const localSccacheProbeCache = new Map(); + function resolveLocalDevRustcWrapperBypass(options = {}) { if (process.platform !== 'win32') { return '/usr/bin/env'; @@ -154,6 +156,12 @@ function resolveLocalDevRustcWrapperBypass(options = {}) { const sccacheAvailable = options.sccacheAvailable ?? (() => { + const cacheKey = `${process.platform}:sccache`; + const cached = localSccacheProbeCache.get(cacheKey); + if (cached !== undefined) { + return cached; + } + const result = spawnSync('sccache', ['rustc', '-vV'], { cwd: repoRoot, encoding: 'utf8', @@ -161,7 +169,9 @@ function resolveLocalDevRustcWrapperBypass(options = {}) { windowsHide: true, timeout: options.sccacheProbeTimeoutMs ?? 10_000, }); - return !result.error && result.status === 0; + const available = !result.error && result.status === 0; + localSccacheProbeCache.set(cacheKey, available); + return available; })(); return sccacheAvailable ? 'sccache' : ''; }