From c0b52fc2d161e0e6bf4b8fa58e456acf9d515867 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 5 Nov 2023 17:09:48 +0800 Subject: [PATCH 1/6] Add extension rdkafka support --- config/ext.json | 9 +++++ config/lib.json | 12 +++++++ config/source.json | 17 +++++++++ src/SPC/builder/extension/rdkafka.php | 36 ++++++++++++++++++++ src/SPC/builder/linux/library/librdkafka.php | 13 +++++++ src/SPC/builder/macos/library/librdkafka.php | 12 +++++++ src/SPC/builder/unix/library/librdkafka.php | 35 +++++++++++++++++++ 7 files changed, 134 insertions(+) create mode 100644 src/SPC/builder/extension/rdkafka.php create mode 100644 src/SPC/builder/linux/library/librdkafka.php create mode 100644 src/SPC/builder/macos/library/librdkafka.php create mode 100644 src/SPC/builder/unix/library/librdkafka.php diff --git a/config/ext.json b/config/ext.json index b18c8eb93..2ab3dc65c 100644 --- a/config/ext.json +++ b/config/ext.json @@ -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", diff --git a/config/lib.json b/config/lib.json index 6a602d16b..4df318dad 100644 --- a/config/lib.json +++ b/config/lib.json @@ -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": [ diff --git a/config/source.json b/config/source.json index cd849f86f..447bc65ab 100644 --- a/config/source.json +++ b/config/source.json @@ -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", diff --git a/src/SPC/builder/extension/rdkafka.php b/src/SPC/builder/extension/rdkafka.php new file mode 100644 index 000000000..50610325f --- /dev/null +++ b/src/SPC/builder/extension/rdkafka.php @@ -0,0 +1,36 @@ +execWithResult('pkg-config --libs --static rdkafka')[1]; + $pkgconf_libs = trim(implode('', $pkgconf_libs)); + return '--with-rdkafka=' . BUILD_ROOT_PATH . ' LIBS="' . $pkgconf_libs . '"'; + } +} diff --git a/src/SPC/builder/linux/library/librdkafka.php b/src/SPC/builder/linux/library/librdkafka.php new file mode 100644 index 000000000..2ccd701af --- /dev/null +++ b/src/SPC/builder/linux/library/librdkafka.php @@ -0,0 +1,13 @@ +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"); + } +} From 330dd2bfc6092a3bde6ae0b710b53338d43579da Mon Sep 17 00:00:00 2001 From: daddeffe Date: Mon, 23 Sep 2024 10:19:40 +0200 Subject: [PATCH 2/6] Added optional zlib and disabled two extension (#545) asd --- config/lib.json | 5 ++--- src/SPC/builder/unix/library/librdkafka.php | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config/lib.json b/config/lib.json index 4df318dad..3c84b2bfb 100644 --- a/config/lib.json +++ b/config/lib.json @@ -427,9 +427,8 @@ "librdkafka++.a", "librdkafka-static.a" ], - "lib-depends": [ - "openssl", - "zlib" + "lib-suggests": [ + "zstd" ] }, "postgresql": { diff --git a/src/SPC/builder/unix/library/librdkafka.php b/src/SPC/builder/unix/library/librdkafka.php index 41f6ed32d..5ee4c0c8e 100644 --- a/src/SPC/builder/unix/library/librdkafka.php +++ b/src/SPC/builder/unix/library/librdkafka.php @@ -16,15 +16,19 @@ trait librdkafka 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 ' . + '--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=' . BUILD_ROOT_PATH); + ->exec("make install DESTDIR={$builddir}"); $this->patchPkgconfPrefix(['rdkafka.pc', 'rdkafka-static.pc', 'rdkafka++.pc', 'rdkafka++-static.pc']); // remove dynamic libs shell() From c840165fa84b366f3b8fb47a66ca66c62d48eaaf Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 23 Sep 2024 16:52:01 +0800 Subject: [PATCH 3/6] Add tests for rdkafka --- src/globals/test-extensions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 755bdf4a6..22c67d3e2 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -19,13 +19,13 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'gmssl', - 'Windows' => 'gmssl', + 'Linux', 'Darwin' => 'rdkafka', + 'Windows' => 'rdkafka', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). $with_libs = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'liblz4', + 'Linux', 'Darwin' => '', 'Windows' => '', }; From 10ef4c0d3b1cd766c8fa83e98ad4ead5f9088602 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 13 Dec 2024 15:22:54 +0800 Subject: [PATCH 4/6] Adjust config --- config/ext.json | 4 ++++ config/lib.json | 1 + 2 files changed, 5 insertions(+) diff --git a/config/ext.json b/config/ext.json index 7b7bf677f..64ff42ecc 100644 --- a/config/ext.json +++ b/config/ext.json @@ -709,6 +709,10 @@ ] }, "rdkafka": { + "support": { + "BSD": "wip", + "Windows": "wip" + }, "type": "external", "source": "ext-rdkafka", "arg-type": "custom", diff --git a/config/lib.json b/config/lib.json index b7d8b51ac..8879763f8 100644 --- a/config/lib.json +++ b/config/lib.json @@ -565,6 +565,7 @@ "librdkafka++.a", "librdkafka-static.a" ], + "cpp-library": true, "lib-suggests": [ "zstd" ] From 44dcc830f47ce77666dc7ef55cb0ed0c7ca26650 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 13 Dec 2024 15:23:55 +0800 Subject: [PATCH 5/6] Add rdkafka tests --- src/globals/test-extensions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 8f0c32cc6..0fa04ab24 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -26,7 +26,7 @@ ]; // whether enable thread safe -$zts = true; +$zts = false; $no_strip = false; @@ -38,8 +38,8 @@ // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gmp,gettext,iconv,igbinary,imagick,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,parallel,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,ssh2,sysvmsg,sysvsem,sysvshm,tidy,tokenizer,xlswriter,xml,xmlreader,xmlwriter,zip,zlib,yaml,zstd', - 'Windows' => 'amqp,apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,ds,exif,ffi,fileinfo,filter,ftp,gd,iconv,igbinary,libxml,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pdo,pdo_mysql,pdo_sqlite,pdo_sqlsrv,phar,rar,redis,session,shmop,simdjson,simplexml,soap,sockets,sqlite3,sqlsrv,ssh2,swow,sysvshm,tokenizer,xml,xmlreader,xmlwriter,yac,yaml,zip,zlib', + 'Linux', 'Darwin' => 'rdkafka', + 'Windows' => 'zlib', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). @@ -52,7 +52,7 @@ // You can use `common`, `bulk`, `minimal` or `none`. // note: combination is only available for *nix platform. Windows must use `none` combination $base_combination = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'none', + 'Linux', 'Darwin' => 'minimal', 'Windows' => 'none', }; From 985cd6781e665ad0b8cb5d80b1961bbb2d0cbca2 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 13 Dec 2024 15:36:51 +0800 Subject: [PATCH 6/6] Add macOS x86_64 test --- src/globals/test-extensions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 0fa04ab24..dee912db4 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -21,8 +21,9 @@ // test os (macos-13, macos-14, ubuntu-latest, windows-latest are available) $test_os = [ - 'macos-14', - 'ubuntu-latest', + // 'macos-14', + 'macos-13', + // 'ubuntu-latest', ]; // whether enable thread safe @@ -52,7 +53,7 @@ // You can use `common`, `bulk`, `minimal` or `none`. // note: combination is only available for *nix platform. Windows must use `none` combination $base_combination = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'minimal', + 'Linux', 'Darwin' => 'bulk', 'Windows' => 'none', };