Skip to content

Commit 1ce1c32

Browse files
committed
Add SPC_CMD_VAR_PHP_EMBED_TYPE for embed building in glibc mode
1 parent b6324fd commit 1ce1c32

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

config/env.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
7979
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"
8080
; make command
8181
SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}"
82+
; embed type for php, static (libphp.a) or shared (libphp.so)
83+
SPC_CMD_VAR_PHP_EMBED_TYPE="shared"
8284

8385
; *** default build vars for building php ***
8486
; CFLAGS for configuring php
@@ -115,6 +117,8 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
115117
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg"
116118
; make command
117119
SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}"
120+
; embed type for php, static or shared
121+
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
118122

119123
; *** default build vars for building php ***
120124
; CFLAGS for configuring php

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
169169
// micro latest needs do strip and upx pack later (strip, upx, cut binary manually supported)
170170
}
171171

172+
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
172173
shell()->cd(SOURCE_PATH . '/php-src')
173174
->exec(
174175
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
175176
($enable_cli ? '--enable-cli ' : '--disable-cli ') .
176177
($enable_fpm ? '--enable-fpm ' : '--disable-fpm ') .
177-
($enable_embed ? '--enable-embed=static ' : '--disable-embed ') .
178+
($enable_embed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
178179
($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') .
179180
$config_file_path .
180181
$config_file_scan_dir .

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
162162
);
163163
}
164164

165+
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
165166
shell()->cd(SOURCE_PATH . '/php-src')
166167
->exec(
167168
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
168169
($enableCli ? '--enable-cli ' : '--disable-cli ') .
169170
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
170-
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
171+
($enableEmbed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
171172
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
172173
$config_file_path .
173174
$config_file_scan_dir .

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,15 @@ protected function sanityCheck(int $build_target): void
192192
if ($ret !== 0) {
193193
throw new RuntimeException('embed failed sanity check: build failed. Error message: ' . implode("\n", $out));
194194
}
195-
[$ret, $output] = shell()->cd($sample_file_path)->execWithResult('./embed');
195+
// if someone changed to --enable-embed=shared, we need to add LD_LIBRARY_PATH
196+
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
197+
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_ROOT_PATH . '/lib:$LD_LIBRARY_PATH ';
198+
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.a');
199+
} else {
200+
$ext_path = '';
201+
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '/lib/libphp.so');
202+
}
203+
[$ret, $output] = shell()->cd($sample_file_path)->execWithResult($ext_path . './embed');
196204
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
197205
throw new RuntimeException('embed failed sanity check: run failed. Error message: ' . implode("\n", $output));
198206
}

src/SPC/store/FileSystem.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ public static function restoreBackupFile(string $path): void
454454
unlink($path . '.bak');
455455
}
456456

457+
public static function removeFileIfExists(string $string): void
458+
{
459+
if (file_exists($string)) {
460+
unlink($string);
461+
}
462+
}
463+
457464
/**
458465
* @throws RuntimeException
459466
* @throws FileSystemException

0 commit comments

Comments
 (0)