支持 Windows 本地 sccache 自动回退

Windows 本地开发检测可用的 sccache 并启用缓存

未安装或不可执行时清空 Rust wrapper 并回退到 rustc

补充测试并更新开发运维文档
This commit is contained in:
2026-09-14 05:20:11 +00:00
committed by 孔令弘
parent 2566ae705f
commit dcaa1a2dd5
3 changed files with 27 additions and 12 deletions
+21 -5
View File
@@ -146,9 +146,23 @@ function applyLocalFfmpegEnv(env, platform = process.platform) {
return env;
}
function resolveLocalDevRustcWrapperBypass() {
// Windows 下不能把 rustc 自身当成 Cargo wrapper;空值会覆盖仓库 .cargo/config.toml 中的 sccache。
return process.platform === 'win32' ? '' : '/usr/bin/env';
function resolveLocalDevRustcWrapperBypass(options = {}) {
if (process.platform !== 'win32') {
return '/usr/bin/env';
}
const sccacheAvailable =
options.sccacheAvailable ??
(() => {
const result = spawnSync('sccache', ['--version'], {
cwd: repoRoot,
encoding: 'utf8',
shell: true,
windowsHide: true,
});
return !result.error && result.status === 0;
})();
return sccacheAvailable ? 'sccache' : '';
}
const SERVICE_NAMES = [
@@ -592,12 +606,14 @@ function buildLocalRustProcessEnv(env, options = {}) {
return mergedEnv;
}
const rustcWrapperBypass = resolveLocalDevRustcWrapperBypass();
const rustcWrapperBypass = resolveLocalDevRustcWrapperBypass(options);
mergedEnv.RUSTC_WRAPPER = rustcWrapperBypass;
mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = rustcWrapperBypass;
if (options.log !== false) {
console.warn(
'[dev:rust] 本地 dev 构建绕过项目 sccache wrapper,避免缓存进程异常阻断启动。',
rustcWrapperBypass
? '[dev:rust] 本地 dev 构建启用 sccache wrapper。'
: '[dev:rust] 本地 dev 构建未找到可用 sccache,回退到直接 rustc。',
);
}
return mergedEnv;