From fed9960684b1d1b7b87c8702a1e11368de0147e2 Mon Sep 17 00:00:00 2001 From: Linghong Date: Mon, 14 Sep 2026 06:29:28 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20POSIX=20sccache=20?= =?UTF-8?q?=E7=BB=95=E8=BF=87=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 明确记录 Linux 和 macOS 本地开发实际绕过 sccache 补充 POSIX 日志回归测试并更新排障文档 --- docs/project-memory/shared-memory/pitfalls.md | 2 +- scripts/dev.mjs | 16 ++++++++---- scripts/dev.test.ts | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/docs/project-memory/shared-memory/pitfalls.md b/docs/project-memory/shared-memory/pitfalls.md index 35b3a8ea9..a99b093a4 100644 --- a/docs/project-memory/shared-memory/pitfalls.md +++ b/docs/project-memory/shared-memory/pitfalls.md @@ -1212,7 +1212,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。 -- 验证:`npm run test -- scripts/dev.test.ts -t "dev scheduler Rust build env"`,并用 `npm run dev:api-server` 拉起后访问实际 api 端口的 `/healthz` 返回 200。 +- 验证:`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`。 ## Pingora 直连 80/443 不能只改 env diff --git a/scripts/dev.mjs b/scripts/dev.mjs index 8656e44b3..62d4f2732 100644 --- a/scripts/dev.mjs +++ b/scripts/dev.mjs @@ -623,12 +623,18 @@ function buildLocalRustProcessEnv(env, options = {}) { mergedEnv.RUSTC_WRAPPER = rustcWrapper; mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = rustcWrapper; if (options.log !== false) { + const isPosixSccacheBypass = + configuredWrapper && + isSccacheRustcWrapper(configuredWrapper) && + process.platform !== 'win32'; console.warn( - rustcWrapper - ? '[dev:rust] 本地 dev 构建启用 sccache wrapper。' - : configuredWrapper - ? '[dev:rust] sccache wrapper 探测失败,回退到直接 rustc。' - : '[dev:rust] 未显式配置 Rust wrapper,使用直接 rustc。', + isPosixSccacheBypass + ? '[dev:rust] POSIX 本地 dev 构建绕过 sccache,使用直接 rustc。' + : rustcWrapper + ? '[dev:rust] 本地 dev 构建启用 sccache wrapper。' + : configuredWrapper + ? '[dev:rust] sccache wrapper 探测失败,回退到直接 rustc。' + : '[dev:rust] 未显式配置 Rust wrapper,使用直接 rustc。', ); } return mergedEnv; diff --git a/scripts/dev.test.ts b/scripts/dev.test.ts index 35d2aec26..169c361f7 100644 --- a/scripts/dev.test.ts +++ b/scripts/dev.test.ts @@ -679,6 +679,32 @@ describe('dev scheduler Rust build env', () => { } }); + test('POSIX 显式配置 sccache 时日志说明实际绕过', () => { + const originalPlatform = Object.getOwnPropertyDescriptor( + process, + 'platform', + ); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + Object.defineProperty(process, 'platform', { + configurable: true, + value: 'linux', + }); + try { + const env = buildLocalRustProcessEnv( + { RUSTC_WRAPPER: 'sccache', CARGO_BUILD_RUSTC_WRAPPER: 'sccache' }, + { log: true }, + ); + expect(env.RUSTC_WRAPPER).toBe('/usr/bin/env'); + expect(warn).toHaveBeenCalledWith( + '[dev:rust] POSIX 本地 dev 构建绕过 sccache,使用直接 rustc。', + ); + } finally { + warn.mockRestore(); + if (originalPlatform) + Object.defineProperty(process, 'platform', originalPlatform); + } + }); + test('local dev Rust env enables available sccache wrapper', () => { const originalPlatform = Object.getOwnPropertyDescriptor( process,