refactor(ci): simplify CMake job limit plugin by removing app/build.gradle patching
This commit is contained in:
@@ -6,17 +6,15 @@ const MAX_JOBS = '8';
|
|||||||
|
|
||||||
// React Native's hermes-engine build hardcodes
|
// React Native's hermes-engine build hardcodes
|
||||||
// Runtime.getRuntime().availableProcessors()
|
// Runtime.getRuntime().availableProcessors()
|
||||||
// for cmake --build -j, ignoring all env vars.
|
// for `cmake --build -j`, ignoring the CMAKE_BUILD_PARALLEL_LEVEL env var.
|
||||||
// On high-core CI runners this exhausts memory.
|
// On high-core CI runners this exhausts memory.
|
||||||
// This plugin patches hermes-engine/build.gradle.kts
|
// This plugin caps it during prebuild.
|
||||||
// during prebuild to cap parallel jobs.
|
|
||||||
const withCmakeJobLimit = (config) =>
|
const withCmakeJobLimit = (config) =>
|
||||||
withDangerousMod(config, [
|
withDangerousMod(config, [
|
||||||
'android',
|
'android',
|
||||||
async (config) => {
|
async (config) => {
|
||||||
const root = config.modRequest.projectRoot;
|
const root = config.modRequest.projectRoot;
|
||||||
|
|
||||||
// 1. Patch hermes-engine: availableProcessors() -> "8"
|
|
||||||
const hermesPath = path.join(
|
const hermesPath = path.join(
|
||||||
root,
|
root,
|
||||||
'node_modules',
|
'node_modules',
|
||||||
@@ -32,25 +30,7 @@ const withCmakeJobLimit = (config) =>
|
|||||||
`"${MAX_JOBS}"`,
|
`"${MAX_JOBS}"`,
|
||||||
);
|
);
|
||||||
fs.writeFileSync(hermesPath, content);
|
fs.writeFileSync(hermesPath, content);
|
||||||
}
|
console.log(`[withCmakeJobLimit] capped hermes-engine jobs to ${MAX_JOBS}`);
|
||||||
|
|
||||||
// 2. Patch app/build.gradle: add cmake -j argument to externalNativeBuild
|
|
||||||
const appGradlePath = path.join(
|
|
||||||
config.modRequest.platformProjectRoot,
|
|
||||||
'app',
|
|
||||||
'build.gradle',
|
|
||||||
);
|
|
||||||
if (fs.existsSync(appGradlePath)) {
|
|
||||||
let content = fs.readFileSync(appGradlePath, 'utf-8');
|
|
||||||
// Insert externalNativeBuild cmake arguments block inside the android { } block
|
|
||||||
// We add it right after "ndkVersion rootProject.ext.ndkVersion"
|
|
||||||
if (!content.includes('CMAKE_BUILD_PARALLEL_LEVEL')) {
|
|
||||||
content = content.replace(
|
|
||||||
/(\s*ndkVersion rootProject\.ext\.ndkVersion)/,
|
|
||||||
`$1\n externalNativeBuild {\n cmake {\n arguments "-j${MAX_JOBS}"\n }\n }`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
fs.writeFileSync(appGradlePath, content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
Reference in New Issue
Block a user