Add ext-memcache

This commit is contained in:
crazywhalecc 2026-03-11 15:29:00 +08:00
parent cbfeefc808
commit f35f133115
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
2 changed files with 89 additions and 0 deletions

View File

@ -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@'

View File

@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
#[Extension('memcache')]
class memcache extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-memcache')]
public function patchBeforeBuildconf(): bool
{
if (!$this->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;
}
}