Skip to content

Commit 1a0bdc1

Browse files
committed
chore: wip
1 parent 7de1f76 commit 1a0bdc1

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

scripts/build-php.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ openssl.capath =
683683

684684
function createUnixPhpIni(installPrefix: string, config: BuildConfig): void {
685685
const phpIniPath = join(installPrefix, 'lib', 'php.ini')
686-
686+
687687
// Create comprehensive php.ini content for Unix builds
688688
const phpIniContent = `; PHP Configuration File
689689
; Generated automatically for Launchpad PHP build (Unix)
@@ -766,7 +766,7 @@ openssl.capath =
766766
`
767767

768768
writeFileSync(phpIniPath, phpIniContent)
769-
769+
770770
// Also create a copy in the etc directory if it exists
771771
const etcPhpIniPath = join(installPrefix, 'etc', 'php.ini')
772772
const etcDir = join(installPrefix, 'etc')
@@ -788,7 +788,7 @@ async function buildPhp(config: BuildConfig): Promise<string> {
788788
log('Using system libraries for Linux PHP build to avoid libstdc++ conflicts')
789789
return buildPhpWithSystemLibraries(config, installPrefix)
790790
}
791-
791+
792792
log('Using Launchpad-managed dependencies for PHP build')
793793

794794
const phpSourceDir = downloadPhpSource(config)
@@ -827,11 +827,11 @@ async function buildPhp(config: BuildConfig): Promise<string> {
827827
`${launchpadRoot}/sqlite.org/v3.47.2/lib/pkgconfig`,
828828
`${launchpadRoot}/libzip.org/v1.11.4/lib/pkgconfig`
829829
]
830-
830+
831831
// Completely exclude libstdcxx and gcc paths on Linux
832832
if (config.platform === 'linux') {
833-
pkgConfigPaths = pkgConfigPaths.filter(path =>
834-
!path.includes('libstdcxx') &&
833+
pkgConfigPaths = pkgConfigPaths.filter(path =>
834+
!path.includes('libstdcxx') &&
835835
!path.includes('gcc') &&
836836
!path.includes('gnu.org/gcc')
837837
)
@@ -856,11 +856,11 @@ async function buildPhp(config: BuildConfig): Promise<string> {
856856
`${launchpadRoot}/sqlite.org/v3.47.2/lib`,
857857
`${launchpadRoot}/libzip.org/v1.11.4/lib`
858858
]
859-
859+
860860
// Completely exclude libstdcxx and gcc paths on Linux
861861
if (config.platform === 'linux') {
862-
libPaths = libPaths.filter(path =>
863-
!path.includes('libstdcxx') &&
862+
libPaths = libPaths.filter(path =>
863+
!path.includes('libstdcxx') &&
864864
!path.includes('gcc') &&
865865
!path.includes('gnu.org/gcc')
866866
)
@@ -1102,17 +1102,24 @@ exec "$@"
11021102
log('Building PHP...')
11031103
const jobs = execSync('nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2', { encoding: 'utf8' }).trim()
11041104

1105-
execSync(`make -j${jobs}`, {
1105+
// Limit parallel jobs on macOS to prevent compilation hangs
1106+
const maxJobs = config.platform === 'darwin' ? Math.min(parseInt(jobs), 2) : parseInt(jobs)
1107+
log(`Using ${maxJobs} parallel jobs for compilation`)
1108+
1109+
execSync(`make -j${maxJobs}`, {
11061110
stdio: 'inherit',
11071111
cwd: phpSourceDir,
1108-
env: buildEnv
1112+
env: buildEnv,
1113+
// Add timeout to prevent infinite hangs
1114+
timeout: 45 * 60 * 1000 // 45 minutes
11091115
})
11101116

11111117
log('Installing PHP...')
11121118
execSync('make install', {
11131119
stdio: 'inherit',
11141120
cwd: phpSourceDir,
1115-
env: buildEnv
1121+
env: buildEnv,
1122+
timeout: 15 * 60 * 1000 // 15 minutes timeout for install
11161123
})
11171124

11181125
// Create php.ini for Unix builds to enable OPcache and other extensions
@@ -1202,15 +1209,15 @@ exec "$@"
12021209

12031210
function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string): string {
12041211
log('Building PHP with system libraries only (Linux)')
1205-
1212+
12061213
const phpSourceDir = downloadPhpSource(config)
12071214
mkdirSync(installPrefix, { recursive: true })
12081215

12091216
// Install required system packages for extensions
12101217
log('Installing required system packages...')
12111218
try {
12121219
execSync('apt-get update && apt-get install -y libbz2-dev libzip-dev gettext libgettextpo-dev pkg-config', { stdio: 'inherit' })
1213-
1220+
12141221
// Verify libzip installation
12151222
try {
12161223
const libzipVersion = execSync('pkg-config --modversion libzip', { encoding: 'utf8' }).trim()
@@ -1312,18 +1319,18 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
13121319
configureSuccess = true
13131320
} catch (error) {
13141321
log('Full configure failed, trying individual extensions...')
1315-
1322+
13161323
// Try with individual extensions to see which ones work
13171324
const workingArgs = [...baseConfigureArgs]
1318-
1325+
13191326
// Test each extension individually with proper configuration
13201327
const extensionsToTest = [
13211328
{ flag: '--with-zip', name: 'zip' }, // Use --with-zip instead of --enable-zip
13221329
{ flag: '--with-iconv', name: 'iconv' },
13231330
{ flag: '--with-bz2', name: 'bz2' },
13241331
{ flag: '--with-gettext', name: 'gettext' }
13251332
]
1326-
1333+
13271334
for (const ext of extensionsToTest) {
13281335
try {
13291336
const testArgs = [...baseConfigureArgs, ext.flag]
@@ -1338,7 +1345,7 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
13381345
log(`❌ ${ext.name} extension: Not available, skipping`)
13391346
}
13401347
}
1341-
1348+
13421349
// Final configure with working extensions
13431350
execSync(`./configure ${workingArgs.join(' ')}`, {
13441351
cwd: phpSourceDir,
@@ -1347,24 +1354,29 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
13471354
})
13481355
configureSuccess = true
13491356
}
1350-
1357+
13511358
if (!configureSuccess) {
13521359
throw new Error('Configure failed even with minimal extensions')
13531360
}
13541361

13551362
log('Configure completed successfully, building PHP...')
13561363
const jobs = execSync('nproc 2>/dev/null || echo 2', { encoding: 'utf8' }).trim()
1357-
execSync(`make -j${jobs}`, {
1364+
const maxJobs = Math.min(parseInt(jobs), 4) // Limit to 4 jobs max to prevent resource issues
1365+
log(`Using ${maxJobs} parallel jobs for compilation`)
1366+
1367+
execSync(`make -j${maxJobs}`, {
13581368
cwd: phpSourceDir,
13591369
env: buildEnv,
1360-
stdio: 'inherit'
1370+
stdio: 'inherit',
1371+
timeout: 45 * 60 * 1000 // 45 minutes timeout
13611372
})
13621373

13631374
log('Installing PHP...')
13641375
execSync('make install', {
13651376
cwd: phpSourceDir,
13661377
env: buildEnv,
1367-
stdio: 'inherit'
1378+
stdio: 'inherit',
1379+
timeout: 30 * 60 * 1000 // 30 minutes timeout for install
13681380
})
13691381

13701382
// Create php.ini for Unix builds

0 commit comments

Comments
 (0)