@@ -783,7 +783,12 @@ async function buildPhp(config: BuildConfig): Promise<string> {
783
783
return await downloadWindowsPhpBinary ( config )
784
784
}
785
785
786
- // For Unix systems, use Launchpad dependency management
786
+ // For Unix systems, use different strategies based on platform
787
+ if ( config . platform === 'linux' ) {
788
+ log ( 'Using system libraries for Linux PHP build to avoid libstdc++ conflicts' )
789
+ return buildPhpWithSystemLibraries ( config , installPrefix )
790
+ }
791
+
787
792
log ( 'Using Launchpad-managed dependencies for PHP build' )
788
793
789
794
const phpSourceDir = downloadPhpSource ( config )
@@ -915,12 +920,26 @@ async function buildPhp(config: BuildConfig): Promise<string> {
915
920
buildEnv . CXX = 'g++'
916
921
buildEnv . CFLAGS = ( buildEnv . CFLAGS || '' ) + ' -O2 -fPIC'
917
922
buildEnv . CXXFLAGS = ( buildEnv . CXXFLAGS || '' ) + ' -O2 -fPIC'
918
- // Use system libstdc++ instead of Launchpad's to avoid linking issues
923
+ // Force system libstdc++ and clear any cached paths
924
+ buildEnv . LDFLAGS = ( buildEnv . LDFLAGS || '' ) . replace ( / - L [ ^ \s ] * g n u \. o r g \/ g c c [ ^ \s ] * / g, '' )
925
+ buildEnv . LDFLAGS = buildEnv . LDFLAGS . replace ( / - L [ ^ \s ] * l i b s t d c x x [ ^ \s ] * / g, '' )
919
926
// Set preprocessor to avoid traditional-cpp issues
920
927
buildEnv . CPP = 'gcc -E'
928
+ // Clear any environment variables that might contain gcc paths
929
+ delete buildEnv . LIBRARY_PATH
930
+ delete buildEnv . LD_LIBRARY_PATH
921
931
// Disable iconv completely on Linux due to glibc errno check failure
922
932
}
923
933
934
+ // Clear any configure cache that might contain libstdc++ paths
935
+ if ( config . platform === 'linux' ) {
936
+ try {
937
+ execSync ( 'rm -rf autom4te.cache config.cache' , { cwd : phpSourceDir , stdio : 'ignore' } )
938
+ } catch ( e ) {
939
+ // Ignore if cache files don't exist
940
+ }
941
+ }
942
+
924
943
log ( 'Running buildconf...' )
925
944
926
945
// Fix m4 compatibility issue on macOS
@@ -1022,7 +1041,30 @@ exec "$@"
1022
1041
if ( existsSync ( buildEnvScript ) ) {
1023
1042
configureCommand = `source ${ buildEnvScript } && ./configure ${ configureArgs . join ( ' ' ) } `
1024
1043
} else {
1025
- throw new Error ( 'build-env.sh still not found after dependency installation' )
1044
+ log ( 'Configuring PHP build...' )
1045
+
1046
+ // Force clean environment for Linux to prevent libstdc++ injection
1047
+ if ( config . platform === 'linux' ) {
1048
+ // Clear any remaining gcc/libstdc++ references from environment
1049
+ Object . keys ( buildEnv ) . forEach ( key => {
1050
+ if ( typeof buildEnv [ key ] === 'string' && buildEnv [ key ] . includes ( 'gnu.org/gcc' ) ) {
1051
+ buildEnv [ key ] = buildEnv [ key ] . replace ( / [ ^ \s ] * g n u \. o r g \/ g c c [ ^ \s ] * / g, '' )
1052
+ }
1053
+ if ( typeof buildEnv [ key ] === 'string' && buildEnv [ key ] . includes ( 'libstdcxx' ) ) {
1054
+ buildEnv [ key ] = buildEnv [ key ] . replace ( / [ ^ \s ] * l i b s t d c x x [ ^ \s ] * / g, '' )
1055
+ }
1056
+ } )
1057
+ }
1058
+
1059
+ if ( config . config === 'ci' ) {
1060
+ // Use CI-specific configure for GitHub Actions
1061
+ const ciConfigureArgs = generateCIConfigureArgs ( config , installPrefix )
1062
+ configureCommand = `./configure ${ ciConfigureArgs . join ( ' ' ) } `
1063
+ } else {
1064
+ // Use standard configure for local builds
1065
+ const configureArgs = generateConfigureArgs ( config , installPrefix )
1066
+ configureCommand = `./configure ${ configureArgs . join ( ' ' ) } `
1067
+ }
1026
1068
}
1027
1069
} catch ( error ) {
1028
1070
log ( '❌ Failed to install Launchpad dependencies, falling back to system libraries' )
@@ -1158,6 +1200,112 @@ exec "$@"
1158
1200
return installPrefix
1159
1201
}
1160
1202
1203
+ function buildPhpWithSystemLibraries ( config : BuildConfig , installPrefix : string ) : string {
1204
+ log ( 'Building PHP with system libraries only (Linux)' )
1205
+
1206
+ const phpSourceDir = downloadPhpSource ( config )
1207
+ mkdirSync ( installPrefix , { recursive : true } )
1208
+
1209
+ // Use clean system environment without any Launchpad paths
1210
+ const buildEnv = {
1211
+ ...process . env ,
1212
+ CC : 'gcc' ,
1213
+ CXX : 'g++' ,
1214
+ CPP : 'gcc -E' ,
1215
+ CFLAGS : '-O2 -fPIC' ,
1216
+ CXXFLAGS : '-O2 -fPIC' ,
1217
+ // Clear any paths that might contain libstdc++
1218
+ PKG_CONFIG_PATH : '' ,
1219
+ LDFLAGS : '' ,
1220
+ CPPFLAGS : '' ,
1221
+ LD_LIBRARY_PATH : '' ,
1222
+ LIBRARY_PATH : ''
1223
+ }
1224
+
1225
+ // Clear configure cache
1226
+ try {
1227
+ execSync ( 'rm -rf autom4te.cache config.cache' , { cwd : phpSourceDir , stdio : 'ignore' } )
1228
+ } catch ( e ) {
1229
+ // Ignore if cache files don't exist
1230
+ }
1231
+
1232
+ log ( 'Running buildconf...' )
1233
+ execSync ( './buildconf --force' , {
1234
+ cwd : phpSourceDir ,
1235
+ env : buildEnv ,
1236
+ stdio : 'inherit'
1237
+ } )
1238
+
1239
+ log ( 'Configuring PHP with system libraries...' )
1240
+ const configureArgs = [
1241
+ `--prefix=${ installPrefix } ` ,
1242
+ '--enable-bcmath' ,
1243
+ '--enable-calendar' ,
1244
+ '--enable-dba' ,
1245
+ '--enable-exif' ,
1246
+ '--enable-ftp' ,
1247
+ '--enable-fpm' ,
1248
+ '--enable-gd' ,
1249
+ '--enable-intl' ,
1250
+ '--enable-mbregex' ,
1251
+ '--enable-mbstring' ,
1252
+ '--enable-mysqlnd' ,
1253
+ '--enable-pcntl' ,
1254
+ '--disable-phpdbg' ,
1255
+ '--enable-shmop' ,
1256
+ '--enable-soap' ,
1257
+ '--enable-sockets' ,
1258
+ '--enable-sysvmsg' ,
1259
+ '--enable-sysvsem' ,
1260
+ '--enable-sysvshm' ,
1261
+ '--with-pear' ,
1262
+ '--with-pcre-jit' ,
1263
+ '--with-layout=GNU' ,
1264
+ '--with-libxml' ,
1265
+ '--with-pdo-sqlite' ,
1266
+ '--with-pic' ,
1267
+ '--with-sqlite3' ,
1268
+ '--disable-dtrace' ,
1269
+ '--without-ndbm' ,
1270
+ '--without-gdbm' ,
1271
+ '--with-curl' ,
1272
+ '--with-openssl' ,
1273
+ '--with-zlib' ,
1274
+ '--enable-opcache=shared' ,
1275
+ '--with-readline' ,
1276
+ '--without-zip' ,
1277
+ '--without-iconv' ,
1278
+ '--without-ldap-sasl'
1279
+ ]
1280
+
1281
+ execSync ( `./configure ${ configureArgs . join ( ' ' ) } ` , {
1282
+ cwd : phpSourceDir ,
1283
+ env : buildEnv ,
1284
+ stdio : 'inherit'
1285
+ } )
1286
+
1287
+ log ( 'Building PHP...' )
1288
+ const jobs = execSync ( 'nproc 2>/dev/null || echo 2' , { encoding : 'utf8' } ) . trim ( )
1289
+ execSync ( `make -j${ jobs } ` , {
1290
+ cwd : phpSourceDir ,
1291
+ env : buildEnv ,
1292
+ stdio : 'inherit'
1293
+ } )
1294
+
1295
+ log ( 'Installing PHP...' )
1296
+ execSync ( 'make install' , {
1297
+ cwd : phpSourceDir ,
1298
+ env : buildEnv ,
1299
+ stdio : 'inherit'
1300
+ } )
1301
+
1302
+ // Create php.ini for Unix builds
1303
+ createUnixPhpIni ( installPrefix , config )
1304
+
1305
+ log ( `✅ PHP ${ config . phpVersion } built successfully with system libraries` )
1306
+ return installPrefix
1307
+ }
1308
+
1161
1309
async function main ( ) : Promise < void > {
1162
1310
try {
1163
1311
const config = getConfig ( )
0 commit comments