修正 POSIX sccache 绕过日志

明确记录 Linux 和 macOS 本地开发实际绕过 sccache

补充 POSIX 日志回归测试并更新排障文档
This commit is contained in:
2026-09-14 06:29:28 +00:00
committed by 孔令弘
parent a3918c89f0
commit fed9960684
3 changed files with 38 additions and 6 deletions
@@ -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
+11 -5
View File
@@ -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;
+26
View File
@@ -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,