按显式配置控制 Windows sccache

未配置 wrapper 时默认回退到直接 rustc

处理 sccache 探测失败与 wrapper 配置冲突

同步更新开发运维和排障文档
This commit is contained in:
2026-09-14 06:19:38 +00:00
parent e85c216112
commit 136756134a
4 changed files with 62 additions and 17 deletions
+25 -11
View File
@@ -591,23 +591,37 @@ function buildLocalRustProcessEnv(env, options = {}) {
String(mergedEnv.RUSTC_WRAPPER ?? '').trim(),
String(mergedEnv.CARGO_BUILD_RUSTC_WRAPPER ?? '').trim(),
].filter(Boolean);
const customWrapper = wrappers.find(
(wrapper) => !isSccacheRustcWrapper(wrapper),
);
if (customWrapper) {
mergedEnv.RUSTC_WRAPPER = customWrapper;
mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = customWrapper;
const uniqueWrappers = [...new Set(wrappers)];
if (uniqueWrappers.length > 1) {
mergedEnv.RUSTC_WRAPPER = '';
mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = '';
if (options.log !== false) {
console.warn(
'[dev:rust] RUSTC_WRAPPER 与 CARGO_BUILD_RUSTC_WRAPPER 配置冲突,回退到直接 rustc。',
);
}
return mergedEnv;
}
const rustcWrapperBypass = resolveLocalDevRustcWrapperBypass(options);
mergedEnv.RUSTC_WRAPPER = rustcWrapperBypass;
mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = rustcWrapperBypass;
const configuredWrapper = uniqueWrappers[0] ?? '';
if (configuredWrapper && !isSccacheRustcWrapper(configuredWrapper)) {
mergedEnv.RUSTC_WRAPPER = configuredWrapper;
mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = configuredWrapper;
return mergedEnv;
}
const rustcWrapper = configuredWrapper
? resolveLocalDevRustcWrapperBypass(options)
: '';
mergedEnv.RUSTC_WRAPPER = rustcWrapper;
mergedEnv.CARGO_BUILD_RUSTC_WRAPPER = rustcWrapper;
if (options.log !== false) {
console.warn(
rustcWrapperBypass
rustcWrapper
? '[dev:rust] 本地 dev 构建启用 sccache wrapper。'
: '[dev:rust] 本地 dev 构建未找到可用 sccache,回退到直接 rustc。',
: configuredWrapper
? '[dev:rust] sccache wrapper 探测失败,回退到直接 rustc。'
: '[dev:rust] 未显式配置 Rust wrapper,使用直接 rustc。',
);
}
return mergedEnv;
+34 -3
View File
@@ -657,6 +657,28 @@ describe('dev scheduler local worker cleanup', () => {
});
describe('dev scheduler Rust build env', () => {
test('Windows 下未显式配置 wrapper 时默认关闭 sccache', () => {
const originalPlatform = Object.getOwnPropertyDescriptor(
process,
'platform',
);
Object.defineProperty(process, 'platform', {
configurable: true,
value: 'win32',
});
try {
const env = buildLocalRustProcessEnv(
{},
{ log: false, sccacheAvailable: true },
);
expect(env.RUSTC_WRAPPER).toBe('');
expect(env.CARGO_BUILD_RUSTC_WRAPPER).toBe('');
} finally {
if (originalPlatform)
Object.defineProperty(process, 'platform', originalPlatform);
}
});
test('local dev Rust env enables available sccache wrapper', () => {
const originalPlatform = Object.getOwnPropertyDescriptor(
process,
@@ -670,7 +692,7 @@ describe('dev scheduler Rust build env', () => {
try {
const env = buildLocalRustProcessEnv(
{
RUSTC_WRAPPER: '/usr/bin/sccache',
RUSTC_WRAPPER: 'sccache',
CARGO_BUILD_RUSTC_WRAPPER: 'sccache',
},
{ log: false, sccacheAvailable: true },
@@ -685,11 +707,11 @@ describe('dev scheduler Rust build env', () => {
}
});
test('local dev Rust env keeps healthy custom wrapper untouched', () => {
test('Rust wrapper 配置为同一个自定义 wrapper 时保持不变', () => {
const env = buildLocalRustProcessEnv(
{
RUSTC_WRAPPER: 'custom-wrapper',
CARGO_BUILD_RUSTC_WRAPPER: 'sccache',
CARGO_BUILD_RUSTC_WRAPPER: 'custom-wrapper',
},
{ log: false },
);
@@ -725,6 +747,15 @@ describe('dev scheduler Rust build env', () => {
}
}
});
test('Rust wrapper 配置冲突时回退到空 wrapper', () => {
const env = buildLocalRustProcessEnv(
{ RUSTC_WRAPPER: 'sccache', CARGO_BUILD_RUSTC_WRAPPER: 'custom-wrapper' },
{ log: false },
);
expect(env.RUSTC_WRAPPER).toBe('');
expect(env.CARGO_BUILD_RUSTC_WRAPPER).toBe('');
});
});
describe('dev scheduler stack state file', () => {