Skip to content

Commit d588ebc

Browse files
committed
chore: wip
1 parent 9f823c1 commit d588ebc

File tree

1 file changed

+72
-2
lines changed

1 file changed

+72
-2
lines changed

scripts/build-php.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bun
22
import { execSync } from 'node:child_process'
3-
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
3+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, copyFileSync, chmodSync } from 'node:fs'
44
import path, { join } from 'node:path'
55
import process from 'node:process'
66

@@ -2282,12 +2282,82 @@ exec ./configure "$@"
22822282
}
22832283

22842284
try {
2285+
// First, ensure the install directory structure exists
2286+
mkdirSync(join(installPrefix, 'bin'), { recursive: true })
2287+
mkdirSync(join(installPrefix, 'lib'), { recursive: true })
2288+
mkdirSync(join(installPrefix, 'share'), { recursive: true })
2289+
mkdirSync(join(installPrefix, 'sbin'), { recursive: true })
2290+
2291+
// Use DESTDIR to ensure make install targets the correct location
2292+
// This forces PHP's build system to install to the correct prefix
22852293
execSync('make install', {
22862294
stdio: 'inherit',
22872295
cwd: phpSourceDir,
2288-
env: installEnv,
2296+
env: {
2297+
...installEnv,
2298+
DESTDIR: '', // Ensure DESTDIR is empty so prefix is used directly
2299+
INSTALL_ROOT: '' // Also ensure INSTALL_ROOT doesn't interfere
2300+
},
22892301
timeout: 15 * 60 * 1000, // 15 minutes timeout for install
22902302
})
2303+
2304+
// Fallback: if make install didn't create the binary, manually copy it
2305+
const phpBinaryPath = join(installPrefix, 'bin', 'php')
2306+
const buildTimePhpBinary = join(phpSourceDir, 'sapi', 'cli', 'php')
2307+
2308+
if (!existsSync(phpBinaryPath) && existsSync(buildTimePhpBinary)) {
2309+
log('🔧 ⚠️ make install did not create PHP binary, manually copying...')
2310+
2311+
// Copy the main PHP binary
2312+
copyFileSync(buildTimePhpBinary, phpBinaryPath)
2313+
chmodSync(phpBinaryPath, '755') // Make executable
2314+
log(`🔧 ✅ Manually copied PHP binary from ${buildTimePhpBinary} to ${phpBinaryPath}`)
2315+
2316+
// Also copy other important binaries if they exist and weren't installed
2317+
const otherBinaries = ['php-cgi', 'php-config', 'phpize', 'pear', 'pecl']
2318+
for (const binary of otherBinaries) {
2319+
const sourceBinary = join(phpSourceDir, 'sapi', 'cgi', binary) // Try CGI first
2320+
const altSourceBinary = join(phpSourceDir, 'scripts', binary) // Try scripts dir
2321+
const altSource2Binary = join(phpSourceDir, binary) // Try root
2322+
const targetBinary = join(installPrefix, 'bin', binary)
2323+
2324+
if (!existsSync(targetBinary)) {
2325+
if (existsSync(sourceBinary)) {
2326+
copyFileSync(sourceBinary, targetBinary)
2327+
chmodSync(targetBinary, '755')
2328+
log(`🔧 ✅ Manually copied ${binary}`)
2329+
} else if (existsSync(altSourceBinary)) {
2330+
copyFileSync(altSourceBinary, targetBinary)
2331+
chmodSync(targetBinary, '755')
2332+
log(`🔧 ✅ Manually copied ${binary} from scripts`)
2333+
} else if (existsSync(altSource2Binary)) {
2334+
copyFileSync(altSource2Binary, targetBinary)
2335+
chmodSync(targetBinary, '755')
2336+
log(`🔧 ✅ Manually copied ${binary} from root`)
2337+
}
2338+
}
2339+
}
2340+
2341+
// Copy CGI binary specifically
2342+
const cgiBinarySource = join(phpSourceDir, 'sapi', 'cgi', 'php-cgi')
2343+
const cgiBinaryTarget = join(installPrefix, 'bin', 'php-cgi')
2344+
if (!existsSync(cgiBinaryTarget) && existsSync(cgiBinarySource)) {
2345+
copyFileSync(cgiBinarySource, cgiBinaryTarget)
2346+
chmodSync(cgiBinaryTarget, '755')
2347+
log(`🔧 ✅ Manually copied php-cgi binary`)
2348+
}
2349+
2350+
// Copy FPM binary specifically
2351+
const fpmBinarySource = join(phpSourceDir, 'sapi', 'fpm', 'php-fpm')
2352+
const fpmBinaryTarget = join(installPrefix, 'sbin', 'php-fpm')
2353+
if (!existsSync(fpmBinaryTarget) && existsSync(fpmBinarySource)) {
2354+
mkdirSync(join(installPrefix, 'sbin'), { recursive: true })
2355+
copyFileSync(fpmBinarySource, fpmBinaryTarget)
2356+
chmodSync(fpmBinaryTarget, '755')
2357+
log(`🔧 ✅ Manually copied php-fpm binary`)
2358+
}
2359+
}
2360+
22912361
} catch (error) {
22922362
if (config.platform === 'darwin') {
22932363
log('🔧 ❌ Installation failed, checking build-time PHP binary again...')

0 commit comments

Comments
 (0)