Skip to content

Commit b338ced

Browse files
committed
chore: wip
1 parent fb14b59 commit b338ced

File tree

1 file changed

+13
-108
lines changed

1 file changed

+13
-108
lines changed

scripts/build-php.ts

Lines changed: 13 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ exec ./configure "$@"
23312331

23322332
if (!existsSync(phpBinaryPath)) {
23332333
log('💥 ❌ CRITICAL: make install failed to create PHP binary')
2334-
log(`💥 Expected PHP binary at: ${phpBinaryPath}`)
2334+
log(`💥 Expected PHP binary at: ${join(installPrefix, 'bin', 'php')}`)
23352335
log(`💥 Build-time binary exists: ${existsSync(buildTimePhpBinary)}`)
23362336

23372337
if (existsSync(buildTimePhpBinary)) {
@@ -2347,113 +2347,14 @@ exec ./configure "$@"
23472347

23482348
log('✅ make install successfully created PHP binary')
23492349

2350-
// Copy the main PHP binary
2351-
copyFileSync(buildTimePhpBinary, phpBinaryPath)
2352-
chmodSync(phpBinaryPath, '755') // Make executable
2353-
log(`🔧 ✅ Manually copied PHP binary from ${buildTimePhpBinary} to ${phpBinaryPath}`)
2354-
2355-
// Helper function to safely copy files (skip sockets, pipes, etc.)
2356-
const safeCopyFile = (source: string, target: string): boolean => {
2357-
try {
2358-
const stats = statSync(source)
2359-
if (!stats.isFile()) {
2360-
log(`🔧 ⚠️ Skipping ${source} - not a regular file (type: ${stats.isSocket() ? 'socket' : stats.isFIFO() ? 'pipe' : stats.isDirectory() ? 'directory' : 'other'})`)
2361-
return false
2362-
}
2363-
copyFileSync(source, target)
2364-
chmodSync(target, '755')
2365-
return true
2366-
} catch (error) {
2367-
log(`🔧 ⚠️ Failed to copy ${source}: ${error}`)
2368-
return false
2369-
}
2370-
}
2371-
2372-
// Also copy other important binaries if they exist and weren't installed
2373-
const otherBinaries = ['php-cgi', 'php-config', 'phpize', 'pear', 'pecl']
2374-
for (const binary of otherBinaries) {
2375-
const sourceBinary = join(phpSourceDir, 'sapi', 'cgi', binary) // Try CGI first
2376-
const altSourceBinary = join(phpSourceDir, 'scripts', binary) // Try scripts dir
2377-
const altSource2Binary = join(phpSourceDir, binary) // Try root
2378-
const targetBinary = join(installPrefix, 'bin', binary)
2379-
2380-
if (!existsSync(targetBinary)) {
2381-
if (existsSync(sourceBinary) && safeCopyFile(sourceBinary, targetBinary)) {
2382-
log(`🔧 ✅ Manually copied ${binary}`)
2383-
} else if (existsSync(altSourceBinary) && safeCopyFile(altSourceBinary, targetBinary)) {
2384-
log(`🔧 ✅ Manually copied ${binary} from scripts`)
2385-
} else if (existsSync(altSource2Binary) && safeCopyFile(altSource2Binary, targetBinary)) {
2386-
log(`🔧 ✅ Manually copied ${binary} from root`)
2387-
}
2388-
}
2389-
}
2390-
2391-
// Copy CGI binary specifically
2392-
const cgiBinarySource = join(phpSourceDir, 'sapi', 'cgi', 'php-cgi')
2393-
const cgiBinaryTarget = join(installPrefix, 'bin', 'php-cgi')
2394-
if (!existsSync(cgiBinaryTarget) && existsSync(cgiBinarySource) && safeCopyFile(cgiBinarySource, cgiBinaryTarget)) {
2395-
log(`🔧 ✅ Manually copied php-cgi binary`)
2396-
}
2397-
2398-
// Copy FPM binary specifically
2399-
const fpmBinarySource = join(phpSourceDir, 'sapi', 'fpm', 'php-fpm')
2400-
const fpmBinaryTarget = join(installPrefix, 'sbin', 'php-fpm')
2401-
if (!existsSync(fpmBinaryTarget) && existsSync(fpmBinarySource)) {
2402-
mkdirSync(join(installPrefix, 'sbin'), { recursive: true })
2403-
if (safeCopyFile(fpmBinarySource, fpmBinaryTarget)) {
2404-
log(`🔧 ✅ Manually copied php-fpm binary`)
2405-
}
2406-
}
2407-
}
2408-
2409-
} catch (error) {
2410-
if (config.platform === 'darwin') {
2411-
log('🔧 ❌ Installation failed, checking build-time PHP binary again...')
2412-
2413-
const buildTimePhpBinary = join(phpSourceDir, 'sapi', 'cli', 'php')
2414-
if (existsSync(buildTimePhpBinary)) {
2415-
// Check what's wrong with the binary
2416-
try {
2417-
const otoolOutput = execSync(`otool -L "${buildTimePhpBinary}"`, { encoding: 'utf8' })
2418-
log('🔧 Build-time PHP binary dependencies:')
2419-
log(otoolOutput)
2420-
2421-
// Try one more comprehensive fix
2422-
log('🔧 Attempting final library path fix...')
2423-
fixMacOSLibraryPaths(buildTimePhpBinary, homeDir)
2424-
2425-
// Test the binary one more time
2426-
execSync(`"${buildTimePhpBinary}" --version`, {
2427-
stdio: 'inherit',
2428-
env: installEnv
2429-
})
2430-
2431-
log('🔧 Binary is now working, retrying installation...')
2432-
execSync('make install', {
2433-
stdio: 'inherit',
2434-
cwd: phpSourceDir,
2435-
env: installEnv,
2436-
timeout: 15 * 60 * 1000,
2437-
})
2438-
} catch (finalError) {
2439-
log(`🔧 Final installation attempt failed: ${finalError}`)
2440-
throw error
2441-
}
2442-
} else {
2443-
throw error
2444-
}
2445-
} else {
2446-
throw error
2447-
}
2448-
}
24492350

24502351
// Additional post-build validation
24512352
log('🔍 Performing post-build validation...')
24522353

24532354
// Verify final PHP binary works correctly
24542355
try {
24552356
const phpBinaryPath = join(installPrefix, 'bin', 'php')
2456-
const versionOutput = execSync(`"${phpBinaryPath}" --version`, {
2357+
const versionOutput = execSync(`"${join(installPrefix, 'bin', 'php')}" --version`, {
24572358
encoding: 'utf8',
24582359
env: {
24592360
...process.env,
@@ -2466,7 +2367,7 @@ exec ./configure "$@"
24662367
log(`📋 PHP Version: ${versionOutput.split('\n')[0]}`)
24672368

24682369
// Check for required extensions
2469-
const extensionsOutput = execSync(`"${phpBinaryPath}" -m`, {
2370+
const extensionsOutput = execSync(`"${join(installPrefix, 'bin', 'php')}" -m`, {
24702371
encoding: 'utf8',
24712372
env: {
24722373
...process.env,
@@ -2553,11 +2454,10 @@ exec ./configure "$@"
25532454
log(`✅ PHP ${config.phpVersion} built successfully at ${installPrefix}`)
25542455

25552456
// Verify that the binary was actually installed
2556-
const phpBinaryPath = join(installPrefix, 'bin', 'php')
2557-
if (existsSync(phpBinaryPath)) {
2558-
log(`✅ PHP binary verified at: ${phpBinaryPath}`)
2457+
if (existsSync(join(installPrefix, 'bin', 'php'))) {
2458+
log(`✅ PHP binary verified at: ${join(installPrefix, 'bin', 'php')}`)
25592459
} else {
2560-
log(`❌ PHP binary not found at expected location: ${phpBinaryPath}`)
2460+
log(`❌ PHP binary not found at expected location: ${join(installPrefix, 'bin', 'php')}`)
25612461
log(`🔍 Contents of ${installPrefix}:`)
25622462
if (existsSync(installPrefix)) {
25632463
const contents = readdirSync(installPrefix)
@@ -2647,6 +2547,11 @@ exec ./configure "$@"
26472547
}
26482548

26492549
return installPrefix
2550+
} catch (error) {
2551+
log('💥 ❌ CRITICAL: PHP installation failed')
2552+
log(`💥 Error: ${error}`)
2553+
throw new Error(`Build failed during installation: ${error}`)
2554+
}
26502555
}
26512556

26522557
// Add a BZip2 specific cache variable for configure
@@ -2909,9 +2814,9 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
29092814
// Verify that the binary was actually installed
29102815
const phpBinaryPath = join(installPrefix, 'bin', 'php')
29112816
if (existsSync(phpBinaryPath)) {
2912-
log(`✅ PHP binary verified at: ${phpBinaryPath}`)
2817+
log(`✅ PHP binary verified at: ${join(installPrefix, 'bin', 'php')}`)
29132818
} else {
2914-
log(`❌ PHP binary not found at expected location: ${phpBinaryPath}`)
2819+
log(`❌ PHP binary not found at expected location: ${join(installPrefix, 'bin', 'php')}`)
29152820
log(`🔍 Contents of ${installPrefix}:`)
29162821
if (existsSync(installPrefix)) {
29172822
const contents = readdirSync(installPrefix)

0 commit comments

Comments
 (0)