From 371a1af5724a23cfd46d1d75ae0ae0669430ec97 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 12 Mar 2026 15:08:11 +0800 Subject: [PATCH] Add ext-opcache --- config/pkg/ext/builtin-extensions.yml | 7 +++ src/Package/Extension/opcache.php | 76 +++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/Package/Extension/opcache.php diff --git a/config/pkg/ext/builtin-extensions.yml b/config/pkg/ext/builtin-extensions.yml index 7a14dcef..da6ec1e9 100644 --- a/config/pkg/ext/builtin-extensions.yml +++ b/config/pkg/ext/builtin-extensions.yml @@ -140,6 +140,13 @@ ext-odbc: - unixodbc php-extension: arg-type@unix: '--with-unixODBC@shared_path_suffix@' +ext-opcache: + type: php-extension + php-extension: + arg-type@unix: custom + arg-type@windows: enable + zend-extension: true + display-name: 'Zend Opcache' ext-openssl: type: php-extension depends: diff --git a/src/Package/Extension/opcache.php b/src/Package/Extension/opcache.php new file mode 100644 index 00000000..93cb0a9f --- /dev/null +++ b/src/Package/Extension/opcache.php @@ -0,0 +1,76 @@ += 8.0 !'); + } + } + + #[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-opcache')] + #[PatchDescription('Fix static opcache build for PHP 8.2.0 to 8.4.x')] + public function patchBeforeBuildconf(PackageInstaller $installer): bool + { + $version = php::getPHPVersion(); + $php_src = $installer->getTargetPackage('php')->getSourceDir(); + if (file_exists("{$php_src}/.opcache_patched")) { + return false; + } + // if 8.2.0 <= PHP_VERSION < 8.2.23, we need to patch from legacy patch file + if (version_compare($version, '8.2.0', '>=') && version_compare($version, '8.2.23', '<')) { + SourcePatcher::patchFile('spc_fix_static_opcache_before_80222.patch', $php_src); + } + // if 8.3.0 <= PHP_VERSION < 8.3.11, we need to patch from legacy patch file + elseif (version_compare($version, '8.3.0', '>=') && version_compare($version, '8.3.11', '<')) { + SourcePatcher::patchFile('spc_fix_static_opcache_before_80310.patch', $php_src); + } + // if 8.3.12 <= PHP_VERSION < 8.5.0-dev, we need to patch from legacy patch file + elseif (version_compare($version, '8.5.0-dev', '<')) { + SourcePatcher::patchPhpSrc(items: ['static_opcache']); + } + // PHP 8.5.0-dev and later supports static opcache without patching + else { + return false; + } + return file_put_contents($php_src . '/.opcache_patched', '1') !== false; + } + + #[CustomPhpConfigureArg('Darwin')] + #[CustomPhpConfigureArg('Linux')] + public function getUnixConfigureArg(bool $shared, PackageBuilder $builder): string + { + $phpVersionID = php::getPHPVersionID(); + $opcache_jit = ' --enable-opcache-jit'; + if ((SystemTarget::getTargetOS() === 'Linux' && + SystemTarget::getLibc() === 'musl' && + $builder->getOption('enable-zts') && + SystemTarget::getTargetArch() === 'x86_64' && + $phpVersionID < 80500) || + $builder->getOption('disable-opcache-jit') + ) { + $opcache_jit = ' --disable-opcache-jit'; + } + return '--enable-opcache' . ($shared ? '=shared' : '') . $opcache_jit; + } +}