@@ -519,8 +519,7 @@ function generateConfigureArgs(config: BuildConfig, installPrefix: string): stri
519
519
...baseArgs ,
520
520
...dependencyArgs ,
521
521
...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' ,
524
523
'--with-readline' ,
525
524
'--with-zip' ,
526
525
'--enable-dtrace' ,
@@ -1272,9 +1271,29 @@ async function buildPhp(config: BuildConfig): Promise<string> {
1272
1271
// macOS: Use dynamic rpaths based on actual library locations, removing duplicates
1273
1272
const uniqueLibPaths = [ ...new Set ( libPaths ) ]
1274
1273
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
1276
1275
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
+
1278
1297
buildEnv . LDFLAGS += ` -lresolv${ iconvFlag } ${ rpathFlags } -Wl,-headerpad_max_install_names`
1279
1298
// Set up runtime library path for macOS (build-time only)
1280
1299
buildEnv . DYLD_LIBRARY_PATH = uniqueLibPaths . join ( ':' )
@@ -2318,6 +2337,27 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
2318
2337
stdio : 'inherit' ,
2319
2338
} )
2320
2339
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
+
2321
2361
log ( 'Configuring PHP with system libraries...' )
2322
2362
const baseConfigureArgs = [
2323
2363
`--prefix=${ installPrefix } ` ,
@@ -2353,8 +2393,7 @@ function buildPhpWithSystemLibraries(config: BuildConfig, installPrefix: string)
2353
2393
'--with-curl' ,
2354
2394
'--with-openssl' ,
2355
2395
'--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' ,
2358
2397
'--with-readline' ,
2359
2398
'--without-ldap-sasl' ,
2360
2399
]
0 commit comments