Skip to content

Commit dc6e63e

Browse files
committed
fix logic errors in shared ext patching
1 parent 88d2f0f commit dc6e63e

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/Package/Target/php/unix.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,13 @@ public function makeEmbedForUnix(TargetPackage $package, PackageInstaller $insta
354354

355355
// ------------- SPC_CMD_VAR_PHP_EMBED_TYPE=static -------------
356356

357-
// process libphp.a for static embed
358-
if (!file_exists("{$package->getLibDir()}/libphp.a")) {
359-
return;
357+
// process libphp.a for static embed (only when present)
358+
if (file_exists("{$package->getLibDir()}/libphp.a")) {
359+
$ar = getenv('AR') ?: 'ar';
360+
$libphp_a = "{$package->getLibDir()}/libphp.a";
361+
shell()->exec("{$ar} -t {$libphp_a} | grep '\\.a$' | xargs -n1 {$ar} d {$libphp_a}");
362+
UnixUtil::exportDynamicSymbols($libphp_a);
360363
}
361-
$ar = getenv('AR') ?: 'ar';
362-
$libphp_a = "{$package->getLibDir()}/libphp.a";
363-
shell()->exec("{$ar} -t {$libphp_a} | grep '\\.a$' | xargs -n1 {$ar} d {$libphp_a}");
364-
UnixUtil::exportDynamicSymbols($libphp_a);
365364

366365
// deploy embed php scripts
367366
$package->runStage([$this, 'patchUnixEmbedScripts']);
@@ -510,7 +509,8 @@ public function patchUnixEmbedScripts(): void
510509
if (file_exists(BUILD_BIN_PATH . '/php-config')) {
511510
logger()->debug('Patching php-config prefix and libs order');
512511
$php_config_str = FileSystem::readFile(BUILD_BIN_PATH . '/php-config');
513-
$php_config_str = str_replace('prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
512+
// anchor to start-of-line so we don't also match `program_prefix=""`
513+
$php_config_str = preg_replace('/^prefix=""/m', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
514514
// move mimalloc to the beginning of libs
515515
$php_config_str = preg_replace('/(libs=")(.*?)\s*(' . preg_quote(BUILD_LIB_PATH, '/') . '\/mimalloc\.o)\s*(.*?)"/', '$1$3 $2 $4"', $php_config_str);
516516
// move lstdc++ to the end of libs

src/StaticPHP/Package/PhpExtensionPackage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function configureForUnix(array $env, PhpExtensionPackage $package): void
306306
shell()->cd($package->getSourceDir())
307307
->setEnv($env)
308308
->exec(
309-
'./configure ' . $this->getPhpConfigureArg(SystemTarget::getCurrentPlatformString(), true) .
309+
'./configure ' . $this->getPhpConfigureArg(SystemTarget::getTargetOS(), true) .
310310
' --with-php-config=' . BUILD_BIN_PATH . '/php-config ' .
311311
"--enable-shared --disable-static {$phpvars}"
312312
);

0 commit comments

Comments
 (0)