From f35f133115ffd0b58580d9e9b3ad8e4acfe48d2b Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 11 Mar 2026 15:29:00 +0800 Subject: [PATCH] Add ext-memcache --- config/pkg/ext/ext-memcache.yml | 14 ++++++ src/Package/Extension/memcache.php | 75 ++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 config/pkg/ext/ext-memcache.yml create mode 100644 src/Package/Extension/memcache.php diff --git a/config/pkg/ext/ext-memcache.yml b/config/pkg/ext/ext-memcache.yml new file mode 100644 index 00000000..9db51c05 --- /dev/null +++ b/config/pkg/ext/ext-memcache.yml @@ -0,0 +1,14 @@ +ext-memcache: + type: php-extension + artifact: + source: + type: pecl + name: memcache + metadata: + license-files: [LICENSE] + license: PHP-3.0 + depends: + - ext-zlib + - ext-session + php-extension: + arg-type: '--enable-memcache@shared_suffix@ --with-zlib-dir=@build_root_path@' diff --git a/src/Package/Extension/memcache.php b/src/Package/Extension/memcache.php new file mode 100644 index 00000000..a9c58b76 --- /dev/null +++ b/src/Package/Extension/memcache.php @@ -0,0 +1,75 @@ +isBuildStatic()) { + return false; + } + FileSystem::replaceFileStr( + "{$this->getSourceDir()}/config9.m4", + 'if test -d $abs_srcdir/src ; then', + 'if test -d $abs_srcdir/main ; then' + ); + FileSystem::replaceFileStr( + "{$this->getSourceDir()}/config9.m4", + 'export CPPFLAGS="$CPPFLAGS $INCLUDES"', + 'export CPPFLAGS="$CPPFLAGS $INCLUDES -I$abs_srcdir/main"' + ); + // add for in-tree building + file_put_contents( + "{$this->getSourceDir()}/php_memcache.h", + <<<'EOF' +#ifndef PHP_MEMCACHE_H +#define PHP_MEMCACHE_H + +extern zend_module_entry memcache_module_entry; +#define phpext_memcache_ptr &memcache_module_entry + +#endif +EOF + ); + return true; + } + + #[BeforeStage('ext-memcache', [self::class, 'configureForUnix'])] + #[PatchDescription('Fix memcache extension compile error when building as shared')] + public function patchBeforeSharedConfigure(): bool + { + if (!$this->isBuildShared()) { + return false; + } + FileSystem::replaceFileStr( + "{$this->getSourceDir()}/config9.m4", + 'if test -d $abs_srcdir/main ; then', + 'if test -d $abs_srcdir/src ; then', + ); + FileSystem::replaceFileStr( + "{$this->getSourceDir()}/config9.m4", + 'export CPPFLAGS="$CPPFLAGS $INCLUDES -I$abs_srcdir/main"', + 'export CPPFLAGS="$CPPFLAGS $INCLUDES"', + ); + return true; + } + + public function getSharedExtensionEnv(): array + { + $parent = parent::getSharedExtensionEnv(); + $parent['CFLAGS'] .= ' -std=c17'; + return $parent; + } +}