From 1791b443bc8f72613350b674d228358b564f2bdb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Sun, 23 Mar 2025 15:35:25 +0700 Subject: [PATCH] add xdebug dynamic extension --- config/ext.json | 7 +++++-- config/lib.json | 6 ++++++ config/source.json | 11 ++++++++++ src/SPC/builder/extension/xdebug.php | 11 ++++++++++ src/SPC/builder/linux/library/xdebug.php | 15 ++++++++++++++ src/SPC/builder/unix/library/xdebug.php | 26 ++++++++++++++++++++++++ src/SPC/command/BuildPHPCommand.php | 24 ++++++++++++++++++++-- src/SPC/store/Downloader.php | 9 +++++++- src/SPC/util/DynamicExt.php | 8 ++++++++ 9 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 src/SPC/builder/extension/xdebug.php create mode 100644 src/SPC/builder/linux/library/xdebug.php create mode 100644 src/SPC/builder/unix/library/xdebug.php create mode 100644 src/SPC/util/DynamicExt.php diff --git a/config/ext.json b/config/ext.json index 4d6044b3..45b9c905 100644 --- a/config/ext.json +++ b/config/ext.json @@ -888,13 +888,16 @@ ] }, "xdebug": { - "type": "builtin", + "type": "external", "support": { "Windows": "wip", "BSD": "no", "Darwin": "no", - "Linux": "no" + "Linux": "wip" }, + "lib-depends": [ + "xdebug" + ], "notes": true }, "xhprof": { diff --git a/config/lib.json b/config/lib.json index 8e728ccd..3aabecd8 100644 --- a/config/lib.json +++ b/config/lib.json @@ -738,6 +738,12 @@ "libiconv" ] }, + "xdebug": { + "source": "xdebug", + "static-libs-unix": [ + "xdebug.so" + ] + }, "xz": { "source": "xz", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index e5cc9212..40c516b6 100644 --- a/config/source.json +++ b/config/source.json @@ -895,6 +895,17 @@ "path": "COPYING" } }, + "xdebug": { + "type": "ghrel", + "repo": "xdebug/xdebug", + "match": "Source code", + "prefer-stable": true, + "provide-pre-built": false, + "license": { + "type": "file", + "path": "LICENSE" + } + }, "xhprof": { "type": "url", "url": "https://pecl.php.net/get/xhprof", diff --git a/src/SPC/builder/extension/xdebug.php b/src/SPC/builder/extension/xdebug.php new file mode 100644 index 00000000..c5cd901d --- /dev/null +++ b/src/SPC/builder/extension/xdebug.php @@ -0,0 +1,11 @@ +cd($this->source_dir) + ->exec(BUILD_BIN_PATH . '/phpize') + ->exec('./configure --with-php-config=' . BUILD_BIN_PATH . '/php-config') + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}"); + copy($this->source_dir . '/modules/xdebug.so', BUILD_LIB_PATH . '/xdebug.so'); + copy($this->source_dir . '/modules/xdebug.la', BUILD_LIB_PATH . '/xdebug.la'); + } +} diff --git a/src/SPC/command/BuildPHPCommand.php b/src/SPC/command/BuildPHPCommand.php index 6bafce54..ceeaca34 100644 --- a/src/SPC/command/BuildPHPCommand.php +++ b/src/SPC/command/BuildPHPCommand.php @@ -11,6 +11,7 @@ use SPC\store\Config; use SPC\store\FileSystem; use SPC\store\SourcePatcher; use SPC\util\DependencyUtil; +use SPC\util\DynamicExt; use SPC\util\GlobalEnvManager; use SPC\util\LicenseDumper; use Symfony\Component\Console\Attribute\AsCommand; @@ -109,6 +110,18 @@ class BuildPHPCommand extends BuildCommand $include_suggest_lib = $this->getOption('with-suggested-libs'); [$extensions, $libraries, $not_included] = DependencyUtil::getExtsAndLibs($extensions, $libraries, $include_suggest_ext, $include_suggest_lib); $display_libs = array_filter($libraries, fn ($lib) => in_array(Config::getLib($lib, 'type', 'lib'), ['lib', 'package'])); + $dynamic_libs = $dynamic_exts = array_filter($extensions, function (string $ext) { + $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/builder/extension', 'SPC\builder\extension'); + $extension = array_find($classes, function (string $class) use ($ext) { + $a = explode('\\', $class); + return end($a) === $ext; + }); + $reflector = new \ReflectionClass($extension); + $attributes = $reflector->getAttributes(); + return array_find($attributes, fn ($attr) => $attr->getName() === DynamicExt::class) !== null; + }); + $extensions = array_diff($extensions, $dynamic_exts); + $libraries = array_diff($libraries, $dynamic_libs); // print info $indent_texts = [ @@ -153,7 +166,7 @@ class BuildPHPCommand extends BuildCommand $builder->proveLibs($libraries); // check extensions $builder->proveExts($extensions); - // validate libs and exts + // validate libs and extensions $builder->validateLibsAndExts(); // clean builds and sources @@ -183,6 +196,13 @@ class BuildPHPCommand extends BuildCommand // start to build $builder->buildPHP($rule); + if ($rule & BUILD_TARGET_EMBED) { + // build dynamic extensions + $builder->proveLibs($dynamic_libs); + // build or install libraries + $builder->setupLibs(); + } + // compile stopwatch :P $time = round(microtime(true) - START_TIME, 3); logger()->info(''); @@ -217,7 +237,7 @@ class BuildPHPCommand extends BuildCommand file_put_contents(BUILD_ROOT_PATH . '/build-libraries.json', json_encode($libraries, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); // export licenses $dumper = new LicenseDumper(); - $dumper->addExts($extensions)->addLibs($libraries)->addSources(['php-src'])->dump(BUILD_ROOT_PATH . '/license'); + $dumper->addExts($extensions)->addLibs($libraries)->addLibs($dynamic_libs)->addSources(['php-src'])->dump(BUILD_ROOT_PATH . '/license'); $path = FileSystem::convertPath("{$build_root_path}/license/"); logger()->info("License path{$fixed}: {$path}"); return static::SUCCESS; diff --git a/src/SPC/store/Downloader.php b/src/SPC/store/Downloader.php index 16edeeae..e2a6280f 100644 --- a/src/SPC/store/Downloader.php +++ b/src/SPC/store/Downloader.php @@ -73,7 +73,7 @@ class Downloader $url = $data[0]['tarball_url']; } else { $id = 0; - while ($data[$id]['prerelease'] === true) { + while (($data[$id]['prerelease'] ?? false) === true) { ++$id; } $url = $data[$id]['tarball_url'] ?? null; @@ -122,6 +122,10 @@ class Downloader if (!$match_result) { return $release['assets']; } + if ($source['match'] === 'Source code') { + $url = $release['tarball_url']; + break; + } foreach ($release['assets'] as $asset) { if (preg_match('|' . $source['match'] . '|', $asset['name'])) { $url = $asset['browser_download_url']; @@ -134,6 +138,9 @@ class Downloader throw new DownloaderException("failed to find {$name} release metadata"); } $filename = basename($url); + if ($source['match'] === 'Source code') { + $filename = $name . $filename . '.tar.gz'; + } return [$url, $filename]; } diff --git a/src/SPC/util/DynamicExt.php b/src/SPC/util/DynamicExt.php new file mode 100644 index 00000000..d5fd549d --- /dev/null +++ b/src/SPC/util/DynamicExt.php @@ -0,0 +1,8 @@ +