From 3136d6edc1485a053485bf1f8f213cbe83c54479 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Thu, 16 May 2024 13:01:11 +0800 Subject: [PATCH] Put extension and library compatibility checks before compilation (#451) --- src/SPC/builder/BuilderBase.php | 37 ++++++++++++++++++- src/SPC/builder/Extension.php | 5 +++ src/SPC/builder/LibraryBase.php | 5 +++ src/SPC/builder/extension/imap.php | 6 ++- src/SPC/builder/extension/opcache.php | 6 ++- src/SPC/builder/extension/parallel.php | 3 +- .../builder/extension/swoole_hook_pgsql.php | 6 ++- .../builder/extension/swoole_hook_sqlite.php | 6 ++- src/SPC/builder/freebsd/BSDBuilder.php | 3 +- src/SPC/builder/unix/UnixBuilderBase.php | 12 +----- src/SPC/builder/windows/WindowsBuilder.php | 12 +----- src/SPC/command/BuildCliCommand.php | 17 +++++++-- src/SPC/command/BuildLibsCommand.php | 4 +- 13 files changed, 86 insertions(+), 36 deletions(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index ee4d9d615..fb3fd70fa 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -33,7 +33,7 @@ abstract class BuilderBase protected string $patch_point = ''; /** - * Build libraries + * Convert libraries to class * * @param array $sorted_libraries Libraries to build (if not empty, must sort first) * @throws FileSystemException @@ -41,7 +41,27 @@ abstract class BuilderBase * @throws WrongUsageException * @internal */ - abstract public function buildLibs(array $sorted_libraries); + abstract public function proveLibs(array $sorted_libraries); + + /** + * Build libraries + * + * @throws FileSystemException + * @throws RuntimeException + * @throws WrongUsageException + */ + public function buildLibs(): void + { + // build all libs + foreach ($this->libs as $lib) { + match ($lib->tryBuild($this->getOption('rebuild', false))) { + BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), + BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), + BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), + default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'), + }; + } + } /** * Add library to build. @@ -335,6 +355,19 @@ public function getPatchPoint(): string return $this->patch_point; } + /** + * Validate libs and exts can be compiled successfully in current environment + */ + public function validateLibsAndExts(): void + { + foreach ($this->libs as $lib) { + $lib->validate(); + } + foreach ($this->exts as $ext) { + $ext->validate(); + } + } + public function emitPatchPoint(string $point_name): void { $this->patch_point = $point_name; diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index ea875a789..5a3171848 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -223,6 +223,11 @@ public function runCliCheckWindows(): void } } + public function validate(): void + { + // do nothing, just throw wrong usage exception if not valid + } + /** * @throws RuntimeException */ diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index cff8ff2b5..ef6ea79d6 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -177,6 +177,11 @@ public function patchBeforeBuild(): bool return false; } + public function validate(): void + { + // do nothing, just throw wrong usage exception if not valid + } + /** * Get current builder object. */ diff --git a/src/SPC/builder/extension/imap.php b/src/SPC/builder/extension/imap.php index 389223ec1..bdb1cd8c7 100644 --- a/src/SPC/builder/extension/imap.php +++ b/src/SPC/builder/extension/imap.php @@ -14,11 +14,15 @@ class imap extends Extension /** * @throws WrongUsageException */ - public function getUnixConfigureArg(): string + public function validate(): void { if ($this->builder->getOption('enable-zts')) { throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds'); } + } + + public function getUnixConfigureArg(): string + { $arg = '--with-imap=' . BUILD_ROOT_PATH; if ($this->builder->getLib('openssl') !== null) { $arg .= ' --with-imap-ssl=' . BUILD_ROOT_PATH; diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index 82efc8530..0bd972d67 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -16,11 +16,15 @@ class opcache extends Extension * @throws WrongUsageException * @throws RuntimeException */ - public function getUnixConfigureArg(): string + public function validate(): void { if ($this->builder->getPHPVersionID() < 80000) { throw new WrongUsageException('Statically compiled PHP with Zend Opcache only available for PHP >= 8.0 !'); } + } + + public function getUnixConfigureArg(): string + { return '--enable-opcache'; } diff --git a/src/SPC/builder/extension/parallel.php b/src/SPC/builder/extension/parallel.php index 8fdf1824a..f50dffb26 100644 --- a/src/SPC/builder/extension/parallel.php +++ b/src/SPC/builder/extension/parallel.php @@ -11,11 +11,10 @@ #[CustomExt('parallel')] class parallel extends Extension { - public function getConfigureArg(): string + public function validate(): void { if (!$this->builder->getOption('enable-zts')) { throw new WrongUsageException('ext-parallel must be built with ZTS builds. Use "--enable-zts" option!'); } - return parent::getConfigureArg(); // TODO: Change the autogenerated stub } } diff --git a/src/SPC/builder/extension/swoole_hook_pgsql.php b/src/SPC/builder/extension/swoole_hook_pgsql.php index dd77db18e..a1c58f9f7 100644 --- a/src/SPC/builder/extension/swoole_hook_pgsql.php +++ b/src/SPC/builder/extension/swoole_hook_pgsql.php @@ -17,12 +17,16 @@ public function getDistName(): string return 'swoole'; } - public function getUnixConfigureArg(): string + public function validate(): void { // pdo_pgsql need to be disabled if ($this->builder->getExt('pdo_pgsql') !== null) { throw new WrongUsageException('swoole-hook-pgsql provides pdo_pgsql, if you enable pgsql hook for swoole, you must remove pdo_pgsql extension.'); } + } + + public function getUnixConfigureArg(): string + { // enable swoole pgsql hook return '--enable-swoole-pgsql'; } diff --git a/src/SPC/builder/extension/swoole_hook_sqlite.php b/src/SPC/builder/extension/swoole_hook_sqlite.php index 4dbfd0df7..60ffe5d2a 100644 --- a/src/SPC/builder/extension/swoole_hook_sqlite.php +++ b/src/SPC/builder/extension/swoole_hook_sqlite.php @@ -17,12 +17,16 @@ public function getDistName(): string return 'swoole'; } - public function getUnixConfigureArg(): string + public function validate(): void { // pdo_pgsql need to be disabled if ($this->builder->getExt('pdo_sqlite') !== null) { throw new WrongUsageException('swoole-hook-sqlite provides pdo_sqlite, if you enable sqlite hook for swoole, you must remove pdo_sqlite extension.'); } + } + + public function getUnixConfigureArg(): string + { // enable swoole pgsql hook return '--enable-swoole-sqlite'; } diff --git a/src/SPC/builder/freebsd/BSDBuilder.php b/src/SPC/builder/freebsd/BSDBuilder.php index 2317bccbe..ffb443160 100644 --- a/src/SPC/builder/freebsd/BSDBuilder.php +++ b/src/SPC/builder/freebsd/BSDBuilder.php @@ -86,7 +86,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void SourcePatcher::patchBeforeConfigure($this); $json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : ''; - $zts = $this->getOption('enable-zts', false) ? '--enable-zts --disable-zend-signals ' : ''; + $zts_enable = $this->getPHPVersionID() < 80000 ? '--enable-maintainer-zts --disable-zend-signals' : '--enable-zts --disable-zend-signals'; + $zts = $this->getOption('enable-zts', false) ? $zts_enable : ''; $enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI; $enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM; diff --git a/src/SPC/builder/unix/UnixBuilderBase.php b/src/SPC/builder/unix/UnixBuilderBase.php index 934ddaad9..7b17698a7 100644 --- a/src/SPC/builder/unix/UnixBuilderBase.php +++ b/src/SPC/builder/unix/UnixBuilderBase.php @@ -90,7 +90,7 @@ public function makeAutoconfFlags(int $flag = AUTOCONF_ALL): string return $extra; } - public function buildLibs(array $sorted_libraries): void + public function proveLibs(array $sorted_libraries): void { // search all supported libs $support_lib_list = []; @@ -137,16 +137,6 @@ public function buildLibs(array $sorted_libraries): void SourceManager::initSource(libs: $sorted_libraries); $this->emitPatchPoint('after-libs-extract'); - - // build all libs - foreach ($this->libs as $lib) { - match ($lib->tryBuild($this->getOption('rebuild', false))) { - BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), - BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), - BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), - default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'), - }; - } } /** diff --git a/src/SPC/builder/windows/WindowsBuilder.php b/src/SPC/builder/windows/WindowsBuilder.php index dff8b7461..f20260553 100644 --- a/src/SPC/builder/windows/WindowsBuilder.php +++ b/src/SPC/builder/windows/WindowsBuilder.php @@ -205,7 +205,7 @@ public function buildMicro(): void $this->deployBinary(BUILD_TARGET_MICRO); } - public function buildLibs(array $sorted_libraries): void + public function proveLibs(array $sorted_libraries): void { // search all supported libs $support_lib_list = []; @@ -242,16 +242,6 @@ public function buildLibs(array $sorted_libraries): void // extract sources SourceManager::initSource(libs: $sorted_libraries); - - // build all libs - foreach ($this->libs as $lib) { - match ($lib->tryBuild($this->getOption('rebuild', false))) { - BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'), - BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'), - BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'), - default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'), - }; - } } /** diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index e6d0d0aec..d196b4550 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -93,6 +93,9 @@ public function handle(): int if ($this->getOption('no-strip')) { logger()->warning('--with-upx-pack conflicts with --no-strip, --no-strip won\'t work!'); } + if (($rule & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) { + logger()->warning('Some cases micro.sfx cannot be packed via UPX due to dynamic size bug, be aware!'); + } } try { // create builder @@ -133,17 +136,23 @@ public function handle(): int } $this->printFormatInfo($this->getDefinedEnvs(), true); $this->printFormatInfo($indent_texts); + logger()->notice('Build will start after 2s ...'); sleep(2); + // compile libraries + $builder->proveLibs($libraries); + // check extensions + $builder->proveExts($extensions); + // validate libs and exts + $builder->validateLibsAndExts(); + // build libraries + $builder->buildLibs(); + if ($this->input->getOption('with-clean')) { logger()->info('Cleaning source dir...'); FileSystem::removeDir(SOURCE_PATH); } - // compile libraries - $builder->buildLibs($libraries); - // check extensions - $builder->proveExts($extensions); // Process -I option $custom_ini = []; diff --git a/src/SPC/command/BuildLibsCommand.php b/src/SPC/command/BuildLibsCommand.php index 8edaacf66..8bb08f617 100644 --- a/src/SPC/command/BuildLibsCommand.php +++ b/src/SPC/command/BuildLibsCommand.php @@ -63,7 +63,9 @@ public function handle(): int $libraries = DependencyUtil::getLibs($libraries); logger()->info('Building libraries: ' . implode(',', $libraries)); sleep(2); - $builder->buildLibs($libraries); + $builder->proveLibs($libraries); + $builder->validateLibsAndExts(); + $builder->buildLibs(); $time = round(microtime(true) - START_TIME, 3); logger()->info('Build libs complete, used ' . $time . ' s !');