-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from crazywhalecc/ext/rdkafka
Add extension rdkafka support
- Loading branch information
Showing
8 changed files
with
149 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 . '"'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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; | ||
|
||
$zstd_option = $this->builder->getLib('zstd') ? ("STATIC_LIB_libzstd={$builddir}/lib/libzstd.a ") : ''; | ||
shell()->cd($this->source_dir) | ||
->exec( | ||
$zstd_option . | ||
'./configure ' . | ||
'--enable-static --disable-shared --disable-curl --disable-sasl --disable-valgrind --disable-zlib --disable-ssl ' . | ||
($zstd_option == '' ? '--disable-zstd ' : '') . | ||
'--prefix=' | ||
) | ||
->exec('make clean') | ||
->exec("make -j{$this->builder->concurrency}") | ||
->exec("make install DESTDIR={$builddir}"); | ||
$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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters