支持 Windows 本地 sccache 自动回退
Windows 本地开发检测可用的 sccache 并启用缓存 未安装或不可执行时清空 Rust wrapper 并回退到 rustc 补充测试并更新开发运维文档
This commit is contained in:
+21
-5
@@ -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;
|
||||
|
||||
+5
-6
@@ -657,17 +657,16 @@ describe('dev scheduler local worker cleanup', () => {
|
||||
});
|
||||
|
||||
describe('dev scheduler Rust build env', () => {
|
||||
test('local dev Rust env bypasses project sccache wrapper', () => {
|
||||
test('local dev Rust env enables available sccache wrapper', () => {
|
||||
const env = buildLocalRustProcessEnv(
|
||||
{
|
||||
RUSTC_WRAPPER: '/usr/bin/sccache',
|
||||
CARGO_BUILD_RUSTC_WRAPPER: 'sccache',
|
||||
},
|
||||
{ log: false },
|
||||
{ log: false, sccacheAvailable: true },
|
||||
);
|
||||
|
||||
expect(env.RUSTC_WRAPPER).not.toBe('/usr/bin/sccache');
|
||||
expect(env.RUSTC_WRAPPER).not.toBe('sccache');
|
||||
expect(env.RUSTC_WRAPPER).toBe('sccache');
|
||||
expect(env.CARGO_BUILD_RUSTC_WRAPPER).toBe(env.RUSTC_WRAPPER);
|
||||
});
|
||||
|
||||
@@ -684,7 +683,7 @@ describe('dev scheduler Rust build env', () => {
|
||||
expect(env.CARGO_BUILD_RUSTC_WRAPPER).toBe('custom-wrapper');
|
||||
});
|
||||
|
||||
test('Windows 下本地 dev Rust env 用空 wrapper 覆盖项目 sccache', () => {
|
||||
test('Windows 下未安装 sccache 时回退到空 wrapper', () => {
|
||||
const originalPlatform = Object.getOwnPropertyDescriptor(
|
||||
process,
|
||||
'platform',
|
||||
@@ -700,7 +699,7 @@ describe('dev scheduler Rust build env', () => {
|
||||
RUSTC_WRAPPER: 'sccache',
|
||||
CARGO_BUILD_RUSTC_WRAPPER: 'sccache',
|
||||
},
|
||||
{ log: false },
|
||||
{ log: false, sccacheAvailable: false },
|
||||
);
|
||||
|
||||
expect(env.RUSTC_WRAPPER).toBe('');
|
||||
|
||||
Reference in New Issue
Block a user