Skip to content

Commit 1d0f4d9

Browse files
committed
chore: wip
1 parent e8cb2fb commit 1d0f4d9

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

scripts/build-php.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,7 @@ function generateConfigureArgs(config: BuildConfig, installPrefix: string): stri
519519
...baseArgs,
520520
...dependencyArgs,
521521
...platformDependencyArgs,
522-
// Conditionally enable opcache - disable JIT for x86_64 macOS due to inline assembly issues in PHP 8.4+
523-
...(config.arch === 'x86_64' ? ['--enable-opcache=shared', '--disable-opcache-jit'] : ['--enable-opcache=shared']),
522+
'--enable-opcache=shared',
524523
'--with-readline',
525524
'--with-zip',
526525
'--enable-dtrace',
@@ -1272,9 +1271,29 @@ async function buildPhp(config: BuildConfig): Promise<string> {
12721271
// macOS: Use dynamic rpaths based on actual library locations, removing duplicates
12731272
const uniqueLibPaths = [...new Set(libPaths)]
12741273
const rpathFlags = uniqueLibPaths.map(path => `-Wl,-rpath,${path}`).join(' ')
1275-
// Handle libiconv with absolute path instead of problematic @rpath reference
1274+
// Handle libiconv with architecture-specific linking to avoid dyld symbol conflicts
12761275
const iconvLibPath = uniqueLibPaths.find(p => p.includes('libiconv'))
1277-
const iconvFlag = iconvLibPath ? ` ${iconvLibPath}/libiconv.2.dylib` : ' -liconv'
1276+
let iconvFlag = ' -liconv' // fallback to system iconv
1277+
1278+
if (iconvLibPath) {
1279+
if (config.arch === 'x86_64') {
1280+
// For x86_64, use static linking to avoid dyld symbol override conflicts
1281+
const staticLib = join(iconvLibPath, 'libiconv.a')
1282+
if (existsSync(staticLib)) {
1283+
iconvFlag = ` ${staticLib}`
1284+
log(`🔧 ✅ Using static iconv library for x86_64: ${staticLib}`)
1285+
} else {
1286+
// Fallback: use -liconv to link against system library
1287+
iconvFlag = ' -liconv'
1288+
log(`🔧 ⚠️ Static iconv not found, using system iconv for x86_64`)
1289+
}
1290+
} else {
1291+
// ARM64 can use dynamic linking without dyld conflicts
1292+
iconvFlag = ` ${iconvLibPath}/libiconv.2.dylib`
1293+
log(`🔧 ✅ Using dynamic iconv library for ARM64: ${iconvLibPath}`)
1294+
}
1295+
}
1296+
12781297
buildEnv.LDFLAGS += ` -lresolv${iconvFlag} ${rpathFlags} -Wl,-headerpad_max_install_names`
12791298
// Set up runtime library path for macOS (build-time only)
12801299
buildEnv.DYLD_LIBRARY_PATH = uniqueLibPaths.join(':')
@@ -2318,6 +2337,27 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
23182337
stdio: 'inherit',
23192338
})
23202339

2340+
// Apply source patches for macOS x86_64 inline assembly issues
2341+
if (config.platform === 'darwin' && config.arch === 'x86_64') {
2342+
log('Applying macOS x86_64 inline assembly patches...')
2343+
try {
2344+
const irX86File = join(phpSourceDir, 'ext/opcache/jit/ir/ir_x86.dasc')
2345+
if (existsSync(irX86File)) {
2346+
// Fix invalid operand for inline asm constraint 'S' on macOS Intel
2347+
// The "S" constraint requires a register but sometimes gets an incompatible operand
2348+
// Replace with "r" (general register) constraint which is more compatible
2349+
execSync(`sed -i.bak 's/asm volatile(".byte 0x0f, 0x1c, 0x06" :: "S" (p))/asm volatile(".byte 0x0f, 0x1c, 0x06" : : "r" (p) : "memory")/g' "${irX86File}"`, {
2350+
cwd: phpSourceDir,
2351+
stdio: 'inherit',
2352+
})
2353+
log('✅ Applied inline assembly constraint fix for macOS x86_64')
2354+
}
2355+
} catch (patchError) {
2356+
log(`⚠️ Failed to apply inline assembly patch: ${patchError}`)
2357+
// Continue anyway - the build might still work
2358+
}
2359+
}
2360+
23212361
log('Configuring PHP with system libraries...')
23222362
const baseConfigureArgs = [
23232363
`--prefix=${installPrefix}`,
@@ -2353,8 +2393,7 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
23532393
'--with-curl',
23542394
'--with-openssl',
23552395
'--with-zlib',
2356-
// Conditionally enable opcache - disable JIT for x86_64 macOS due to inline assembly issues in PHP 8.4+
2357-
...(config.platform === 'darwin' && config.arch === 'x86_64' ? ['--enable-opcache=shared', '--disable-opcache-jit'] : ['--enable-opcache=shared']),
2396+
'--enable-opcache=shared',
23582397
'--with-readline',
23592398
'--without-ldap-sasl',
23602399
]

0 commit comments

Comments
 (0)