mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-04 15:25:41 +08:00
only link static ext libraries into sapi builds
This commit is contained in:
@@ -29,7 +29,7 @@ abstract class BuilderBase
|
||||
/** @var array<int, string> extension names */
|
||||
protected array $ext_list = [];
|
||||
|
||||
/** @var array<int, string> library names */
|
||||
/** @var array<int, string> all libraries being built (resolved dep list) */
|
||||
protected array $lib_list = [];
|
||||
|
||||
/** @var bool compile libs only (just mark it) */
|
||||
|
||||
@@ -334,7 +334,7 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
*/
|
||||
private function getMakeExtraVars(): array
|
||||
{
|
||||
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true, 'absolute_libs' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
||||
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true, 'absolute_libs' => true]))->config(array_keys($this->getExts(false)), [], $this->getOption('with-suggested-exts'), $this->lib_list);
|
||||
$static = SPCTarget::isStatic() ? '-all-static' : '';
|
||||
$lib = BUILD_LIB_PATH;
|
||||
$extra_ldflags = (string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS');
|
||||
|
||||
@@ -293,7 +293,7 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
|
||||
private function getMakeExtraVars(): array
|
||||
{
|
||||
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
||||
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config(array_keys($this->getExts(false)), [], $this->getOption('with-suggested-exts'), $this->lib_list);
|
||||
return array_filter([
|
||||
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
||||
'EXTRA_LDFLAGS_PROGRAM' => '-L' . BUILD_LIB_PATH,
|
||||
|
||||
@@ -229,7 +229,7 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
copy(ROOT_DIR . '/src/globals/common-tests/embed.c', $sample_file_path . '/embed.c');
|
||||
copy(ROOT_DIR . '/src/globals/common-tests/embed.php', $sample_file_path . '/embed.php');
|
||||
$util = new SPCConfigUtil($this);
|
||||
$config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
||||
$config = $util->config(array_keys($this->getExts(false)), [], $this->getOption('with-suggested-exts'), $this->lib_list);
|
||||
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
|
||||
if (SPCTarget::isStatic()) {
|
||||
$lens .= ' -static';
|
||||
@@ -440,7 +440,7 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
$staticFlags = '-static-pie';
|
||||
}
|
||||
|
||||
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list);
|
||||
$config = (new SPCConfigUtil($this))->config(array_keys($this->getExts(false)), [], false, $this->lib_list);
|
||||
$cflags = "{$this->arch_c_flags} {$config['cflags']} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -DFRANKENPHP_VERSION=' . $frankenPhpVersion;
|
||||
$libs = $config['libs'];
|
||||
// Go's gcc driver doesn't automatically link against -lgcov or -lrt. Ugly, but necessary fix.
|
||||
|
||||
@@ -101,11 +101,15 @@ class DependencyUtil
|
||||
/**
|
||||
* Get extension dependencies in correct order
|
||||
*
|
||||
* @param array $exts Array of extension names
|
||||
* @param array $additional_libs Array of additional libraries
|
||||
* @return array Ordered array of extension names
|
||||
* @param array $exts Array of extension names
|
||||
* @param array $additional_libs Array of additional libraries
|
||||
* @param bool $include_suggested_exts Whether to follow ext-suggests edges
|
||||
* @param array|bool $include_suggested_libs true = follow all lib-suggests edges;
|
||||
* false = follow none;
|
||||
* array = follow lib-suggests edges only when the suggested lib is in this list (i.e. it's already being built)
|
||||
* @return array Ordered array of extension names
|
||||
*/
|
||||
public static function getExtsAndLibs(array $exts, array $additional_libs = [], bool $include_suggested_exts = false, bool $include_suggested_libs = false): array
|
||||
public static function getExtsAndLibs(array $exts, array $additional_libs = [], bool $include_suggested_exts = false, array|bool $include_suggested_libs = false): array
|
||||
{
|
||||
$dep_list = self::platExtToLibs();
|
||||
|
||||
@@ -127,16 +131,20 @@ class DependencyUtil
|
||||
}
|
||||
}
|
||||
|
||||
// include suggested libraries
|
||||
if ($include_suggested_libs) {
|
||||
// check every deps suggests
|
||||
// include suggested libraries (all, or only those in the available set)
|
||||
if ($include_suggested_libs !== false) {
|
||||
$available = is_array($include_suggested_libs) ? $include_suggested_libs : null;
|
||||
foreach ($dep_list as $name => $obj) {
|
||||
$del_list = [];
|
||||
foreach ($obj['suggests'] as $id => $suggest) {
|
||||
if (!str_starts_with($suggest, 'ext@')) {
|
||||
$dep_list[$name]['depends'][] = $suggest;
|
||||
$del_list[] = $id;
|
||||
if (str_starts_with($suggest, 'ext@')) {
|
||||
continue;
|
||||
}
|
||||
if ($available !== null && !in_array($suggest, $available, true)) {
|
||||
continue;
|
||||
}
|
||||
$dep_list[$name]['depends'][] = $suggest;
|
||||
$del_list[] = $id;
|
||||
}
|
||||
foreach ($del_list as $id) {
|
||||
unset($dep_list[$name]['suggests'][$id]);
|
||||
|
||||
@@ -117,7 +117,7 @@ class LicenseDumper
|
||||
/**
|
||||
* Loads a source license file from the specified path.
|
||||
*/
|
||||
private function loadSourceFile(string $source_name, int $index, array|string|null $in_path, ?string $custom_base_path = null): string
|
||||
private function loadSourceFile(string $source_name, int $index, null|array|string $in_path, ?string $custom_base_path = null): string
|
||||
{
|
||||
if (is_null($in_path)) {
|
||||
throw new SPCInternalException("source [{$source_name}] license file is not set, please check config/source.json");
|
||||
|
||||
@@ -42,17 +42,18 @@ class SPCConfigUtil
|
||||
/**
|
||||
* Generate configuration for building PHP extensions.
|
||||
*
|
||||
* @param array $extensions Extension name list
|
||||
* @param array $libraries Additional library name list
|
||||
* @param bool $include_suggest_ext Include suggested extensions
|
||||
* @param bool $include_suggest_lib Include suggested libraries
|
||||
* @param array $extensions Extension name list
|
||||
* @param array $libraries Additional library name list
|
||||
* @param bool $include_suggest_ext Include suggested extensions
|
||||
* @param array|bool $include_suggest_lib true/false to include all/no suggested libs; array to include only suggests that point at libs in the array erse of libs being built)
|
||||
* @return array{
|
||||
* cflags: string,
|
||||
* ldflags: string,
|
||||
* libs: string
|
||||
* }
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false): array
|
||||
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, array|bool $include_suggest_lib = false): array
|
||||
{
|
||||
logger()->debug('config extensions: ' . implode(',', $extensions));
|
||||
logger()->debug('config libs: ' . implode(',', $libraries));
|
||||
|
||||
Reference in New Issue
Block a user