diff --git a/config/env.ini b/config/env.ini index 85ca6821..1849a371 100644 --- a/config/env.ini +++ b/config/env.ini @@ -79,6 +79,8 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force" SPC_CMD_PREFIX_PHP_CONFIGURE="${SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --with-pic" ; make command SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}" +; embed type for php, static (libphp.a) or shared (libphp.so) +SPC_CMD_VAR_PHP_EMBED_TYPE="shared" ; *** default build vars for building php *** ; CFLAGS for configuring php @@ -115,6 +117,8 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force" SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg" ; make command SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}" +; embed type for php, static or shared +SPC_CMD_VAR_PHP_EMBED_TYPE="static" ; *** default build vars for building php *** ; CFLAGS for configuring php diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index 556638e9..b809a005 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -169,12 +169,13 @@ class LinuxBuilder extends UnixBuilderBase // micro latest needs do strip and upx pack later (strip, upx, cut binary manually supported) } + $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; shell()->cd(SOURCE_PATH . '/php-src') ->exec( getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . ($enable_cli ? '--enable-cli ' : '--disable-cli ') . ($enable_fpm ? '--enable-fpm ' : '--disable-fpm ') . - ($enable_embed ? '--enable-embed=static ' : '--disable-embed ') . + ($enable_embed ? "--enable-embed={$embed_type} " : '--disable-embed ') . ($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') . $config_file_path . $config_file_scan_dir . diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 95aa2c5e..dba0cd43 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -162,12 +162,13 @@ class MacOSBuilder extends UnixBuilderBase ); } + $embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static'; shell()->cd(SOURCE_PATH . '/php-src') ->exec( getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' . ($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableFpm ? '--enable-fpm ' : '--disable-fpm ') . - ($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') . + ($enableEmbed ? "--enable-embed={$embed_type} " : '--disable-embed ') . ($enableMicro ? '--enable-micro ' : '--disable-micro ') . $config_file_path . $config_file_scan_dir . diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 08bab8a0..785b2087 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -192,7 +192,15 @@ abstract class UnixBuilderBase extends BuilderBase if ($ret !== 0) { throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out)); } - [$ret, $output] = shell()->cd($sample_file_path)->execWithResult('./embed'); + // if someone changed to --enable-embed=shared, we need to add LD_LIBRARY_PATH + if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') { + $ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH '; + FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a'); + } else { + $ext_path = ''; + FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so'); + } + [$ret, $output] = shell()->cd($sample_file_path)->execWithResult($ext_path . './embed'); if ($ret !== 0 || trim(implode('', $output)) !== 'hello') { throw new RuntimeException('embed failed sanity check: run failed. Error message: ' . implode("\n", $output)); } diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 5780a216..67b21ec4 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -454,6 +454,13 @@ class FileSystem unlink($path . '.bak'); } + public static function removeFileIfExists(string $string): void + { + if (file_exists($string)) { + unlink($string); + } + } + /** * @throws RuntimeException * @throws FileSystemException