缓存 sccache 探测结果避免重复阻塞
在当前 dev 编排进程内复用 sccache wrapper 探测结果 避免 API 与 worker 重启重复同步等待 同步更新排障文档
This commit is contained in:
@@ -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`。
|
||||
|
||||
|
||||
+11
-1
@@ -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' : '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user