2026-06-15 22:58:48 +08:00
|
|
|
const { withDangerousMod } = require('@expo/config-plugins');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
2026-06-16 11:44:05 +08:00
|
|
|
const MAX_JOBS = '3';
|
2026-06-15 22:58:48 +08:00
|
|
|
|
|
|
|
|
// React Native's hermes-engine build hardcodes
|
|
|
|
|
// Runtime.getRuntime().availableProcessors()
|
2026-06-15 23:51:20 +08:00
|
|
|
// for `cmake --build -j`, ignoring the CMAKE_BUILD_PARALLEL_LEVEL env var.
|
2026-06-15 22:58:48 +08:00
|
|
|
// On high-core CI runners this exhausts memory.
|
2026-06-15 23:51:20 +08:00
|
|
|
// This plugin caps it during prebuild.
|
2026-06-15 22:58:48 +08:00
|
|
|
const withCmakeJobLimit = (config) =>
|
|
|
|
|
withDangerousMod(config, [
|
|
|
|
|
'android',
|
|
|
|
|
async (config) => {
|
|
|
|
|
const root = config.modRequest.projectRoot;
|
|
|
|
|
|
|
|
|
|
const hermesPath = path.join(
|
|
|
|
|
root,
|
|
|
|
|
'node_modules',
|
|
|
|
|
'react-native',
|
|
|
|
|
'ReactAndroid',
|
|
|
|
|
'hermes-engine',
|
|
|
|
|
'build.gradle.kts',
|
|
|
|
|
);
|
|
|
|
|
if (fs.existsSync(hermesPath)) {
|
|
|
|
|
let content = fs.readFileSync(hermesPath, 'utf-8');
|
|
|
|
|
content = content.replace(
|
|
|
|
|
/Runtime\.getRuntime\(\)\.availableProcessors\(\)\.toString\(\)/,
|
|
|
|
|
`"${MAX_JOBS}"`,
|
|
|
|
|
);
|
|
|
|
|
fs.writeFileSync(hermesPath, content);
|
2026-06-15 23:51:20 +08:00
|
|
|
console.log(`[withCmakeJobLimit] capped hermes-engine jobs to ${MAX_JOBS}`);
|
2026-06-15 22:58:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
module.exports = withCmakeJobLimit;
|