Skip to content

Commit 24fe7e6

Browse files
committed
chore: wip
1 parent b3392bc commit 24fe7e6

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

scripts/build-php.ts

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,17 +1103,57 @@ exec "$@"
11031103
log('Building PHP...')
11041104
const jobs = execSync('nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2', { encoding: 'utf8' }).trim()
11051105

1106-
// Disable parallel compilation on macOS to prevent hangs on mbstring and other extensions
1107-
const maxJobs = config.platform === 'darwin' ? 1 : parseInt(jobs)
1108-
log(`Using ${maxJobs} parallel jobs for compilation (${config.platform === 'darwin' ? 'sequential build for macOS stability' : 'parallel build'})`)
1109-
1110-
execSync(`make -j${maxJobs}`, {
1111-
stdio: 'inherit',
1112-
cwd: phpSourceDir,
1113-
env: buildEnv,
1114-
// Add timeout to prevent infinite hangs - longer for sequential macOS builds
1115-
timeout: config.platform === 'darwin' ? 90 * 60 * 1000 : 45 * 60 * 1000 // 90 min for macOS, 45 min for others
1116-
})
1106+
if (config.platform === 'darwin') {
1107+
// macOS: Use chunked compilation to prevent hangs
1108+
log('Using chunked compilation for macOS stability')
1109+
1110+
try {
1111+
// First, try to build core components with shorter timeout
1112+
log('Building core PHP components...')
1113+
execSync('make -j1 Zend/zend_language_scanner.lo', {
1114+
stdio: 'inherit',
1115+
cwd: phpSourceDir,
1116+
env: buildEnv,
1117+
timeout: 10 * 60 * 1000 // 10 minutes for individual components
1118+
})
1119+
1120+
log('Building Zend engine...')
1121+
execSync('make -j1 libphp.la', {
1122+
stdio: 'inherit',
1123+
cwd: phpSourceDir,
1124+
env: buildEnv,
1125+
timeout: 20 * 60 * 1000 // 20 minutes for Zend engine
1126+
})
1127+
1128+
log('Building remaining components...')
1129+
execSync('make -j1', {
1130+
stdio: 'inherit',
1131+
cwd: phpSourceDir,
1132+
env: buildEnv,
1133+
timeout: 60 * 60 * 1000 // 60 minutes for remaining build
1134+
})
1135+
} catch (error) {
1136+
log('Chunked compilation failed, falling back to standard build with extended timeout...')
1137+
// Fallback to standard build with very long timeout
1138+
execSync('make -j1', {
1139+
stdio: 'inherit',
1140+
cwd: phpSourceDir,
1141+
env: buildEnv,
1142+
timeout: 120 * 60 * 1000 // 2 hours timeout as last resort
1143+
})
1144+
}
1145+
} else {
1146+
// Linux/other platforms: Use parallel compilation
1147+
const maxJobs = Math.min(parseInt(jobs), 4) // Limit to 4 jobs max for stability
1148+
log(`Using ${maxJobs} parallel jobs for compilation`)
1149+
1150+
execSync(`make -j${maxJobs}`, {
1151+
stdio: 'inherit',
1152+
cwd: phpSourceDir,
1153+
env: buildEnv,
1154+
timeout: 45 * 60 * 1000 // 45 minutes timeout
1155+
})
1156+
}
11171157

11181158
log('Installing PHP...')
11191159
execSync('make install', {

0 commit comments

Comments
 (0)