mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
Add extension rdkafka support
This commit is contained in:
parent
ac7a236763
commit
c0b52fc2d1
@ -385,6 +385,15 @@
|
||||
"libssh2"
|
||||
]
|
||||
},
|
||||
"rdkafka": {
|
||||
"type": "external",
|
||||
"source": "ext-rdkafka",
|
||||
"arg-type": "custom",
|
||||
"cpp-extension": true,
|
||||
"lib-depends": [
|
||||
"librdkafka"
|
||||
]
|
||||
},
|
||||
"swoole": {
|
||||
"type": "external",
|
||||
"source": "swoole",
|
||||
|
||||
@ -420,6 +420,18 @@
|
||||
"pkg-config": {
|
||||
"source": "pkg-config"
|
||||
},
|
||||
"librdkafka": {
|
||||
"source": "librdkafka",
|
||||
"static-libs-unix": [
|
||||
"librdkafka.a",
|
||||
"librdkafka++.a",
|
||||
"librdkafka-static.a"
|
||||
],
|
||||
"lib-depends": [
|
||||
"openssl",
|
||||
"zlib"
|
||||
]
|
||||
},
|
||||
"postgresql": {
|
||||
"source": "postgresql",
|
||||
"static-libs-unix": [
|
||||
|
||||
@ -42,6 +42,23 @@
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"librdkafka": {
|
||||
"type": "ghtar",
|
||||
"repo": "confluentinc/librdkafka",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-rdkafka": {
|
||||
"type": "ghtar",
|
||||
"repo": "arnaud-lb/php-rdkafka",
|
||||
"path": "php-src/ext/rdkafka",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-event": {
|
||||
"type": "url",
|
||||
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz",
|
||||
|
||||
36
src/SPC/builder/extension/rdkafka.php
Normal file
36
src/SPC/builder/extension/rdkafka.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('rdkafka')]
|
||||
class rdkafka extends Extension
|
||||
{
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
// when compiling rdkafka with inline builds, it shows some errors, I don't know why.
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/rdkafka/rdkafka.c',
|
||||
"#ifdef HAS_RD_KAFKA_TRANSACTIONS\n#include \"kafka_error_exception.h\"\n#endif",
|
||||
'#include "kafka_error_exception.h"'
|
||||
);
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/rdkafka/kafka_error_exception.h',
|
||||
['#ifdef HAS_RD_KAFKA_TRANSACTIONS', '#endif'],
|
||||
''
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getConfigureArg(): string
|
||||
{
|
||||
$pkgconf_libs = shell()->execWithResult('pkg-config --libs --static rdkafka')[1];
|
||||
$pkgconf_libs = trim(implode('', $pkgconf_libs));
|
||||
return '--with-rdkafka=' . BUILD_ROOT_PATH . ' LIBS="' . $pkgconf_libs . '"';
|
||||
}
|
||||
}
|
||||
13
src/SPC/builder/linux/library/librdkafka.php
Normal file
13
src/SPC/builder/linux/library/librdkafka.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class librdkafka extends LinuxLibraryBase
|
||||
{
|
||||
// TODO: Linux is buggy, see https://github.com/confluentinc/librdkafka/discussions/4495
|
||||
use \SPC\builder\unix\library\librdkafka;
|
||||
|
||||
public const NAME = 'librdkafka';
|
||||
}
|
||||
12
src/SPC/builder/macos/library/librdkafka.php
Normal file
12
src/SPC/builder/macos/library/librdkafka.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class librdkafka extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\librdkafka;
|
||||
|
||||
public const NAME = 'librdkafka';
|
||||
}
|
||||
35
src/SPC/builder/unix/library/librdkafka.php
Normal file
35
src/SPC/builder/unix/library/librdkafka.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
|
||||
trait librdkafka
|
||||
{
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$builddir = BUILD_ROOT_PATH;
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared --disable-curl --disable-sasl --disable-valgrind ' .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['rdkafka.pc', 'rdkafka-static.pc', 'rdkafka++.pc', 'rdkafka++-static.pc']);
|
||||
// remove dynamic libs
|
||||
shell()
|
||||
->exec("rm -rf {$builddir}/lib/*.so.*")
|
||||
->exec("rm -rf {$builddir}/lib/*.so")
|
||||
->exec("rm -rf {$builddir}/lib/*.dylib");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user