From 1fb47ea0dd7e28fcb8cd0791ce85fb1c6847d262 Mon Sep 17 00:00:00 2001 From: larryTheCoder Date: Thu, 29 Jun 2023 02:27:45 +0800 Subject: [PATCH] Add our own flavour --- .gitignore | 3 + README.md | 1 + compile.sh | 391 ++++++++++++++++++++++++++++++++++++++++- windows-compile-vs.bat | 117 +++++++++++- 4 files changed, 506 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 224d8c03..7288e420 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ bin/ +bin-debug/ install_data/ +download_cache/ +test.dSYM/ install.log temp_data/ compile.log diff --git a/README.md b/README.md index efed0663..2140f816 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Bash script used to compile PHP on MacOS and Linux platforms. Make sure you have | -d | Compiles with debugging symbols and disables optimizations (slow, but useful for debugging segfaults) | | -D | Compiles with separated debugging symbols, but leaves optimizations enabled (used for distributed binaries) | | -g | Will compile GD2 | +| -F | Will compile FFI | | -j | Set make threads to # | | -l | Uses the folder specified for caching compilation artifacts (useful for rapid rebuild and testing) | | -n | Don't remove sources after completing compilation | diff --git a/compile.sh b/compile.sh index 0432311f..afe43eec 100755 --- a/compile.sh +++ b/compile.sh @@ -13,6 +13,10 @@ OPENSSL_VERSION="3.2.1" LIBZIP_VERSION="1.10.1" SQLITE3_VERSION="3450200" #3.45.2 LIBDEFLATE_VERSION="275aa5141db6eda3587214e0f1d3a134768f557d" #1.20 +LIBRDKAFKA_VER="2.1.1" +LIBZSTD_VER="1.5.5" +LIBGRPC_VER="1.58.1" +SASL2_VERSION="2.1.28" EXT_PMMPTHREAD_VERSION="6.1.0" EXT_YAML_VERSION="2.2.3" @@ -27,6 +31,10 @@ EXT_MORTON_VERSION="0.1.2" EXT_XXHASH_VERSION="0.2.0" EXT_ARRAYDEBUG_VERSION="0.2.0" EXT_ENCODING_VERSION="0.3.0" +EXT_RDKAFKA_VERSION="6.0.3" +EXT_ZSTD_VERSION="0.13.3" +EXT_GRPC_VERSION="1.57.3" +EXT_VANILLAGENERATOR_VERSION="abd059fd2ca79888aab3b9c5070d83ceea55fada" function write_out { echo "[$1] $2" @@ -144,6 +152,7 @@ FLAGS_LTO="" HAVE_OPCACHE_JIT="no" COMPILE_GD="no" +COMPILE_FFI="no" PM_VERSION_MAJOR="" @@ -151,7 +160,7 @@ DOWNLOAD_INSECURE="no" DOWNLOAD_CACHE="" SEPARATE_SYMBOLS="no" -while getopts "::t:j:sdDxfgnva:P:c:l:Ji" OPTION; do +while getopts "::t:j:sdDFxfgnva:P:c:l:Ji" OPTION; do case $OPTION in l) @@ -199,6 +208,10 @@ while getopts "::t:j:sdDxfgnva:P:c:l:Ji" OPTION; do f) write_out "deprecated" "The -f flag is deprecated, as optimizations are now enabled by default unless -d (debug mode) is specified" ;; + F) + write_out "opt" "Will enable FFI" + COMPILE_FFI="yes" + ;; g) write_out "opt" "Will enable GD2" COMPILE_GD="yes" @@ -300,6 +313,38 @@ function download_github_src { download_file "https://github.com/$1/archive/$2.tar.gz" "$3" } +function git_download_file { + local url="$1" + local prefix="$2" + local git_branch="$3" + local git_path="$4" + local base_name=${git_path##*/} + local cached_filename="$prefix-$base_name.tar.gz" + + if [[ "$DOWNLOAD_CACHE" != "" ]]; then + if [[ ! -d "$DOWNLOAD_CACHE" ]]; then + mkdir "$DOWNLOAD_CACHE" >> "$DIR/install.log" 2>&1 + fi + if [[ -f "$DOWNLOAD_CACHE/$cached_filename" ]]; then + echo "Cache hit for git repository URL: $url" >> "$DIR/install.log" + tar xzf "$DOWNLOAD_CACHE/$cached_filename" $git_path >> "$DIR/install.log" 2>&1 + else + echo "Downloading git repository to cache: $url" >> "$DIR/install.log" + git clone -b "$git_branch" --depth=1 $url $git_path >> "$DIR/install.log" 2>&1 + pushd $git_path >> "$DIR/install.log" 2>&1 + git submodule update --depth=1 --init >> "$DIR/install.log" 2>&1 + popd >> "$DIR/install.log" 2>&1 + tar czf "$DOWNLOAD_CACHE/$cached_filename" $git_path >> "$DIR/install.log" 2>&1 + fi + else + echo "Downloading non-cached git repository: $url" >> "$DIR/install.log" + git clone -b "$git_branch" --depth=1 $url $git_path >> "$DIR/install.log" 2>&1 + pushd $git_path >> "$DIR/install.log" 2>&1 + git submodule update --depth=1 --init >> "$DIR/install.log" 2>&1 + popd >> "$DIR/install.log" 2>&1 + fi +} + GMP_ABI="" TOOLCHAIN_PREFIX="" OPENSSL_TARGET="" @@ -425,8 +470,10 @@ fi [ -z "$mtune" ] && mtune=native; [ -z "$CFLAGS" ] && CFLAGS=""; -if [ "$DO_STATIC" == "no" ]; then - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; +LDORIGIN_MODIFY="no" +if [ "$DO_STATIC" == "no" ] && [ -z "$LDFLAGS" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + LDORIGIN_MODIFY="yes" fi [ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; @@ -506,6 +553,199 @@ download_github_src "php/php-src" "php-$PHP_VERSION" "php" | tar -zx >> "$DIR/in mv php-src-php-$PHP_VERSION php write_done +function build_sasl2 { + write_library sasl2 "$SASL2_VERSION" + local sasl2_dir="./sasl2-$SASL2_VERSION" + + if cant_use_cache "$sasl2_dir"; then + rm -rf "$sasl2_dir" + write_download + download_file "https://github.com/cyrusimap/cyrus-sasl/archive/cyrus-sasl-$SASL2_VERSION.tar.gz" "sasl2" | tar -zx >> "$DIR/install.log" 2>&1 + mv cyrus-sasl-cyrus-sasl-$SASL2_VERSION "$sasl2_dir" + echo -n "checking... " + cd "$sasl2_dir" + if [ "$DO_STATIC" == "yes" ]; then + local EXTRA_FLAGS="--enable-shared=no --enable-static=yes" + else + local EXTRA_FLAGS="--enable-shared=yes --enable-static=no" + fi + NOCONFIGURE="no" ./autogen.sh >> "$DIR/install.log" 2>&1 + LDFLAGS="$LDFLAGS -L${INSTALL_DIR}/lib" CPPFLAGS="$CPPFLAGS -I${INSTALL_DIR}/include" RANLIB=$RANLIB ./configure \ + --prefix="$INSTALL_DIR" \ + --with-openssl="$INSTALL_DIR" \ + --libdir="$INSTALL_DIR/lib" \ + $EXTRA_FLAGS \ + $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 + + echo -n "compiling... " + make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache + else + write_caching + cd "$sasl2_dir" + fi + write_install + if [ "$(uname -s)" == "Darwin" ]; then + make install-am >> "$DIR/install.log" 2>&1 + else + make install >> "$DIR/install.log" 2>&1 + fi + cd .. + write_done +} + +function build_zstd { + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$ORIGIN/../lib' -Wl,-rpath-link='\$ORIGIN/../lib'"; + fi + + write_library zstd "$LIBZSTD_VER" + local zstd_dir="./zstd-$LIBZSTD_VER" + + if cant_use_cache "$zstd_dir"; then + rm -rf "$zstd_dir" + write_download + download_file "https://github.com/facebook/zstd/archive/v$LIBZSTD_VER.tar.gz" "zstd" | tar -zx >> "$DIR/install.log" 2>&1 + echo -n " checking..." + pushd $zstd_dir/build/cmake >> "$DIR/install.log" 2>&1 + if [ "$DO_STATIC" != "yes" ]; then + local EXTRA_FLAGS="-DBUILD_SHARED_LIBS=ON" + else + local EXTRA_FLAGS="" + fi + cmake . \ + -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ + -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE=Release \ + $CMAKE_GLOBAL_EXTRA_FLAGS \ + $EXTRA_FLAGS \ + >> "$DIR/install.log" 2>&1 + write_compile + make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache + else + write_caching + pushd "$zstd_dir" + fi + write_install + make install >> "$DIR/install.log" 2>&1 + popd >> "$DIR/install.log" 2>&1 + write_done + + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + fi +} + +function build_grpc { + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$ORIGIN/../lib' -Wl,-rpath-link='\$ORIGIN/../lib'"; + fi + + write_library libgrpc "$LIBGRPC_VER" + local grpc_dir="./grpc-$LIBGRPC_VER" + + if cant_use_cache "$grpc_dir"; then + rm -rf "$grpc_dir" + write_download + git_download_file "https://github.com/grpc/grpc.git" "grpc" "v$LIBGRPC_VER" $grpc_dir >> "$DIR/install.log" 2>&1 + echo -n " checking..." + pushd $grpc_dir >> "$DIR/install.log" 2>&1 + if [ "$DO_STATIC" != "yes" ]; then + local EXTRA_FLAGS="-DBUILD_SHARED_LIBS=ON" + else + local EXTRA_FLAGS="" + fi + mkdir -p cmake/build + pushd cmake/build >> "$DIR/install.log" 2>&1 + cmake ../.. \ + -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ + -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE=Release \ + -DgRPC_INSTALL=ON \ + -DgRPC_SSL_PROVIDER="package" \ + -DgRPC_ZLIB_PROVIDER="package" \ + -DgRPC_BUILD_CSHARP_EXT=OFF \ + -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \ + $CMAKE_GLOBAL_EXTRA_FLAGS \ + $EXTRA_FLAGS \ + >> "$DIR/install.log" 2>&1 + write_compile + make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache + else + write_caching + pushd "$grpc_dir/cmake/build" + fi + + write_install + make install >> "$DIR/install.log" 2>&1 + popd >> "$DIR/install.log" 2>&1 + popd >> "$DIR/install.log" 2>&1 + + echo -n " copying..." + cp -R $grpc_dir/third_party/protobuf/php/ext/google/protobuf $BUILD_DIR/php/ext/protobuf >> "$DIR/install.log" 2>&1 + cp -R $grpc_dir/third_party/protobuf/third_party $BUILD_DIR/php/ext/protobuf/third_party >> "$DIR/install.log" 2>&1 + + write_done + + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + fi +} + +function build_kafka { + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$ORIGIN/../lib' -Wl,-rpath-link='\$ORIGIN/../lib'"; + fi + + write_library librdkafka "$LIBRDKAFKA_VER" + local librdkafka_dir="./librdkafka-$LIBRDKAFKA_VER" + + if cant_use_cache "$librdkafka_dir"; then + rm -rf "$librdkafka_dir" + write_download + download_file "https://github.com/confluentinc/librdkafka/archive/v$LIBRDKAFKA_VER.tar.gz" "librdkafka" | tar -zx >> "$DIR/install.log" 2>&1 + pushd "$librdkafka_dir" >> "$DIR/install.log" 2>&1 + echo -n " checking..." + + if [ "$DO_STATIC" != "yes" ]; then + local EXTRA_FLAGS="-DBUILD_SHARED_LIBS=ON" + else + local EXTRA_FLAGS="" + fi + + cmake . \ + -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \ + -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DWITH_ZSTD=ON \ + -DWITH_SSL=ON \ + -DWITH_CURL=OFF \ + -DENABLE_LZ4_EXT=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + $CMAKE_GLOBAL_EXTRA_FLAGS \ + $EXTRA_FLAGS \ + >> "$DIR/install.log" 2>&1 + + echo -n " compiling..." + make -j $THREADS >> "$DIR/install.log" 2>&1 && mark_cache + else + write_caching + pushd "$librdkafka_dir" >> "$DIR/install.log" 2>&1 + fi + write_install + make install >> "$DIR/install.log" 2>&1 + popd >> "$DIR/install.log" 2>&1 + write_done + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + fi +} + function build_zlib { if [ "$DO_STATIC" == "yes" ]; then local EXTRA_FLAGS="--static" @@ -606,7 +846,6 @@ function build_openssl { --libdir="$INSTALL_DIR/lib" \ no-asm \ no-hw \ - no-engine \ $EXTRA_FLAGS >> "$DIR/install.log" 2>&1 write_compile @@ -718,6 +957,9 @@ function build_yaml { } function build_leveldb { + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$ORIGIN/../lib' -Wl,-rpath-link='\$ORIGIN/../lib'"; + fi write_library leveldb "$LEVELDB_VERSION" local leveldb_dir="./leveldb-$LEVELDB_VERSION" if cant_use_cache "$leveldb_dir"; then @@ -758,6 +1000,9 @@ function build_leveldb { make install >> "$DIR/install.log" 2>&1 cd .. write_done + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + fi } function build_libpng { @@ -869,6 +1114,9 @@ function build_libxml2 { } function build_libzip { + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$ORIGIN/../lib' -Wl,-rpath-link='\$ORIGIN/../lib'"; + fi #libzip if [ "$DO_STATIC" == "yes" ]; then local CMAKE_LIBZIP_EXTRA_FLAGS="-DBUILD_SHARED_LIBS=OFF" @@ -910,6 +1158,9 @@ function build_libzip { make install >> "$DIR/install.log" 2>&1 cd .. write_done + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + fi } function build_sqlite3 { @@ -948,6 +1199,9 @@ function build_sqlite3 { } function build_libdeflate { + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$ORIGIN/../lib' -Wl,-rpath-link='\$ORIGIN/../lib'"; + fi write_library libdeflate "$LIBDEFLATE_VERSION" local libdeflate_dir="./libdeflate-$LIBDEFLATE_VERSION" @@ -980,6 +1234,9 @@ function build_libdeflate { make install >> "$DIR/install.log" 2>&1 cd .. write_done + if [ "$LDORIGIN_MODIFY" != "no" ]; then + LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib' -Wl,-rpath-link='\$\$ORIGIN/../lib'"; + fi } cd "$LIB_BUILD_DIR" @@ -988,6 +1245,10 @@ build_zlib build_gmp build_openssl build_curl +build_sasl2 +build_zstd +build_kafka +build_grpc build_yaml build_leveldb if [ "$COMPILE_GD" == "yes" ]; then @@ -1000,6 +1261,12 @@ else HAS_LIBJPEG="" fi +if [ "$COMPILE_FFI" == "yes" ]; then + HAS_FFI="--with-ffi" +else + HAS_FFI="" +fi + build_libxml2 build_libzip build_sqlite3 @@ -1068,6 +1335,104 @@ get_github_extension "arraydebug" "$EXT_ARRAYDEBUG_VERSION" "pmmp" "ext-arraydeb get_github_extension "encoding" "$EXT_ENCODING_VERSION" "pmmp" "ext-encoding" +get_github_extension "grpc" "$EXT_GRPC_VERSION" "larryTheCoder" "php-grpc" + +get_github_extension "vanillagenerator" "$EXT_VANILLAGENERATOR_VERSION" "NetherGamesMC" "ext-vanillagenerator" + +get_github_extension "rdkafka" "$EXT_RDKAFKA_VERSION" "arnaud-lb" "php-rdkafka" + +get_github_extension "zstd" "$EXT_ZSTD_VERSION" "kjdev" "php-ext-zstd" + +if [ "$(uname -s)" == "Darwin" ]; then + echo "[rdkafka] Implementing quick patch for MacOS support." + + rm $BUILD_DIR/php/ext/rdkafka/config.m4 2>&1 + + echo 'PHP_ARG_WITH(rdkafka, for rdkafka support,' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '[ --with-rdkafka Include rdkafka support])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo 'if test "$PHP_RDKAFKA" != "no"; then' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' SEARCH_PATH="/usr/local /usr" # you might want to change this' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' SEARCH_FOR="/include/librdkafka/rdkafka.h" # you most likely want to change this' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' if test -r $PHP_RDKAFKA/$SEARCH_FOR; then # path given as parameter' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' RDKAFKA_DIR=$PHP_RDKAFKA' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' else # search default path list' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_CHECKING([for librdkafka/rdkafka.h" in default path])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' for i in $SEARCH_PATH ; do' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' if test -r $i/$SEARCH_FOR; then' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' RDKAFKA_DIR=$i' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_RESULT(found in $i)' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' fi' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' done' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' fi' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' if test -z "$RDKAFKA_DIR"; then' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_RESULT([not found])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_ERROR([Please reinstall the rdkafka distribution])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' fi' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' PHP_ADD_INCLUDE($RDKAFKA_DIR/include)' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' SOURCES="rdkafka.c metadata.c metadata_broker.c metadata_topic.c metadata_partition.c metadata_collection.c conf.c topic.c queue.c message.c fun.c kafka_consumer.c topic_partition.c"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' LIBNAME=rdkafka' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' LIBSYMBOL=rd_kafka_new' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' [' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $RDKAFKA_DIR/$PHP_LIBDIR, RDKAFKA_SHARED_LIBADD)' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_DEFINE(HAVE_RDKAFKALIB,1,[ ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_ERROR([wrong rdkafka lib version or lib not found])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' -L$RDKAFKA_DIR/$PHP_LIBDIR -lm' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ORIG_LDFLAGS="$LDFLAGS"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ORIG_CPPFLAGS="$CPPFLAGS"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' LDFLAGS="-L$RDKAFKA_DIR/$PHP_LIBDIR -lm"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' CPPFLAGS="-I$RDKAFKA_DIR/include"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_CHECKING([for librdkafka version])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_EGREP_CPP(yes,[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '#include ' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '#if RD_KAFKA_VERSION >= 0x000b0000' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' yes' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '#endif' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_RESULT([>= 0.11.0])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_ERROR([librdkafka version 0.11.0 or greater required.])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_CHECK_LIB($LIBNAME,[rd_kafka_message_headers],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_DEFINE(HAVE_RD_KAFKA_MESSAGE_HEADERS,1,[ ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_WARN([no rd_kafka_message_headers, headers support will not be available])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_CHECK_LIB($LIBNAME,[rd_kafka_purge],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_DEFINE(HAS_RD_KAFKA_PURGE,1,[ ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_WARN([purge is not available])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_CHECK_LIB($LIBNAME,[rd_kafka_msg_partitioner_murmur2],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_DEFINE(HAS_RD_KAFKA_PARTITIONER_MURMUR2,1,[ ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ],[' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' AC_MSG_WARN([murmur2 partitioner is not available])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' ])' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' LDFLAGS="$ORIG_LDFLAGS"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' CPPFLAGS="$ORIG_CPPFLAGS"' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' PHP_SUBST(RDKAFKA_SHARED_LIBADD)' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo '' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo ' PHP_NEW_EXTENSION(rdkafka, $SOURCES, $ext_shared)' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 + echo 'fi' >> "$BUILD_DIR/php/ext/rdkafka/config.m4" 2>&1 +fi + write_library "PHP" "$PHP_VERSION" write_configure @@ -1149,6 +1514,8 @@ RANLIB=$RANLIB CFLAGS="$CFLAGS $FLAGS_LTO" CXXFLAGS="$CXXFLAGS $FLAGS_LTO" LDFLA --with-libdeflate \ $HAS_LIBJPEG \ $HAS_GD \ +$HAS_FFI \ +--with-rdkafka="$INSTALL_DIR" \ --with-leveldb="$INSTALL_DIR" \ --without-readline \ $HAS_DEBUG \ @@ -1173,6 +1540,7 @@ $HAS_DEBUG \ --with-pdo-sqlite \ --with-pdo-mysql \ --with-pic \ +--with-libzstd \ --enable-phar \ --enable-ctype \ --enable-sockets \ @@ -1186,6 +1554,10 @@ $HAVE_MYSQLI \ --enable-bcmath \ --enable-cli \ --enable-ftp \ +--enable-grpc="$INSTALL_DIR" \ +--enable-protobuf \ +--enable-zstd \ +--enable-vanillagenerator \ --enable-opcache=$HAVE_OPCACHE \ --enable-opcache-jit=$HAVE_OPCACHE_JIT \ --enable-igbinary \ @@ -1263,6 +1635,7 @@ echo "error_reporting=-1" >> "$INSTALL_DIR/bin/php.ini" echo "display_errors=1" >> "$INSTALL_DIR/bin/php.ini" echo "display_startup_errors=1" >> "$INSTALL_DIR/bin/php.ini" echo "recursionguard.enabled=0 ;disabled due to minor performance impact, only enable this if you need it for debugging" >> "$INSTALL_DIR/bin/php.ini" +echo "extension_dir=./$INSTALL_DIR/lib/php/extensions/no-debug-zts-20220829" >> "$INSTALL_DIR/bin/php.ini" if [ "$HAVE_OPCACHE" == "yes" ]; then echo "zend_extension=opcache.so" >> "$INSTALL_DIR/bin/php.ini" @@ -1347,13 +1720,21 @@ if [ "$DO_CLEANUP" == "yes" ]; then rm -f "$INSTALL_DIR/bin/curl-config"* >> "$DIR/install.log" 2>&1 rm -f "$INSTALL_DIR/bin/c_rehash"* >> "$DIR/install.log" 2>&1 rm -f "$INSTALL_DIR/bin/openssl"* >> "$DIR/install.log" 2>&1 + rm -f "$INSTALL_DIR/bin/zstd"* >> "$DIR/install.log" 2>&1 + rm -f "$INSTALL_DIR/bin/grpc_cpp_plugin" >> "$DIR/install.log" 2>&1 rm -r -f "$INSTALL_DIR/man" >> "$DIR/install.log" 2>&1 rm -r -f "$INSTALL_DIR/share/man" >> "$DIR/install.log" 2>&1 rm -r -f "$INSTALL_DIR/php" >> "$DIR/install.log" 2>&1 rm -r -f "$INSTALL_DIR/misc" >> "$DIR/install.log" 2>&1 rm -r -f "$INSTALL_DIR/lib/"*.a >> "$DIR/install.log" 2>&1 rm -r -f "$INSTALL_DIR/lib/"*.la >> "$DIR/install.log" 2>&1 - rm -r -f "$INSTALL_DIR/include" >> "$DIR/install.log" 2>&1 + mv "$INSTALL_DIR/include" "$INSTALL_DIR/include_copy" >> "$DIR/install.log" 2>&1 + mkdir "$INSTALL_DIR/include" >> "$DIR/install.log" 2>&1 + mv "$INSTALL_DIR/include_copy/google" "$INSTALL_DIR/include/google" >> "$DIR/install.log" 2>&1 + mv "$INSTALL_DIR/include_copy/grpc" "$INSTALL_DIR/include/grpc" >> "$DIR/install.log" 2>&1 + mv "$INSTALL_DIR/include_copy/grpc++" "$INSTALL_DIR/include/grpc++" >> "$DIR/install.log" 2>&1 + mv "$INSTALL_DIR/include_copy/grpcpp" "$INSTALL_DIR/include/grpcpp" >> "$DIR/install.log" 2>&1 + rm -r -f "$INSTALL_DIR/include_copy" >> "$DIR/install.log" 2>&1 fi date >> "$DIR/install.log" 2>&1 diff --git a/windows-compile-vs.bat b/windows-compile-vs.bat index 55d2fe54..5a7cf8a5 100644 --- a/windows-compile-vs.bat +++ b/windows-compile-vs.bat @@ -22,6 +22,9 @@ set LIBYAML_VER=0.2.5 set PTHREAD_W32_VER=3.0.0 set LEVELDB_MCPE_VER=1c7564468b41610da4f498430e795ca4de0931ff set LIBDEFLATE_VER=dd12ff2b36d603dbb7fa8838fe7e7176fcbd4f6f +set LIBRDKAFKA_VER=2.1.1 +set LIBZSTD_VER=1.5.5 +set LIBGRPC_VER=1.56.2 set PHP_PMMPTHREAD_VER=6.1.0 set PHP_YAML_VER=2.2.3 @@ -36,6 +39,10 @@ set PHP_XXHASH_VER=0.2.0 set PHP_XDEBUG_VER=3.3.1 set PHP_ARRAYDEBUG_VER=0.2.0 set PHP_ENCODING_VER=0.3.0 +set PHP_VANILLAGENERATOR_VER=2.1.7 +set PHP_LIBKAFKA_VER=6.0.3 +set PHP_ZSTD_VER=0.13.3 +SET PHP_GRPC_VER=1.57.3 set script_path=%~dp0 set log_file=%script_path%compile.log @@ -135,6 +142,99 @@ call bin\phpsdk_deps.bat -u -t %VC_VER% -b %PHP_MAJOR_VER% -a %ARCH% -f -d %DEPS call :pm-echo "Getting additional dependencies..." cd /D "%DEPS_DIR%" +call :pm-echo "Downloading grpc/grpc version %LIBGRPC_VER%..." +git clone -b v%LIBGRPC_VER% --depth=1 https://github.com/grpc/grpc >>"%log_file%" 2>&1 || exit 1 +cd /D grpc + +call :pm-echo "Updating submodules..." +git submodule update --depth=1 --init >>"%log_file%" 2>&1 || exit 1 + +call :pm-echo "Generating build configuration..." +cd cmake +md build +cd build +cmake -GNinja^ + -DCMAKE_PREFIX_PATH="%DEPS_DIR%"^ + -DCMAKE_INSTALL_PREFIX="%DEPS_DIR%"^ + -DCMAKE_BUILD_TYPE="%MSBUILD_CONFIGURATION%"^ + -DZLIB_LIBRARY="%DEPS_DIR%\lib\zlib_a.lib"^ + -DgRPC_BUILD_CSHARP_EXT=OFF^ + -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF^ + -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF^ + -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF^ + -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF^ + -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF^ + -DgRPC_SSL_PROVIDER="package"^ + -DgRPC_ZLIB_PROVIDER="package"^ + ..\.. >>"%log_file%" 2>&1 || exit 1 + +call :pm-echo "Compiling..." +cmake --build . >> "%log_file%" 2>&1 || exit 1 +call :pm-echo "Installing files..." +cmake -P cmake_install.cmake >> "%log_file%" 2>&1 || exit 1 +cd /D "%DEPS_DIR%" + +call :pm-echo "Moving php-gRPC extension source..." + +move grpc\third_party\protobuf\php\ext\google\protobuf ..\php-src\ext\protobuf >> "%log_file%" 2>&1 || exit 1 +move grpc\third_party\protobuf\third_party ..\php-src\ext\protobuf\third_party >> "%log_file%" 2>&1 || exit 1 +cd ..\php-src\ext\protobuf + +call :pm-echo "Generating files..." +echo|(set /p="ARG_ENABLE("protobuf", "Enable Protobuf extension", "yes");" & echo.) >> config.w32 +echo|(set /p="" & echo.) >> config.w32 +echo|(set /p="if (PHP_PROTOBUF != "no") {" & echo.) >> config.w32 +echo|(set /p=" EXTENSION("protobuf", "arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c", PHP_PROTOBUF_SHARED, "");" & echo.) >> config.w32 +echo|(set /p="" & echo.) >> config.w32 +echo|(set /p=" ADD_SOURCES(configure_module_dirname + "/third_party/utf8_range", "naive.c range2-neon.c range2-sse.c", "protobuf");" & echo.) >> config.w32 +echo|(set /p="" & echo.) >> config.w32 +echo|(set /p=" AC_DEFINE('HAVE_PROTOBUF', 1, '');" & echo.) >> config.w32 +echo|(set /p="}" & echo.) >> config.w32 + +cd /D "%DEPS_DIR%" + +call :pm-echo "Downloading zstd version %LIBZSTD_VER%..." +call :get-zip "https://github.com/facebook/zstd/archive/v%LIBZSTD_VER%.zip" || exit 1 +move zstd-%LIBZSTD_VER% zstd >> "%log_file%" 2>&1 +cd zstd/build/cmake +call :pm-echo "Generating build configuration..." +cmake -G "%CMAKE_TARGET%" -A "%ARCH%"^ + -DCMAKE_PREFIX_PATH="%DEPS_DIR%"^ + -DCMAKE_INSTALL_PREFIX="%DEPS_DIR%"^ + -DBUILD_SHARED_LIBS=ON^ + . >>"%log_file%" 2>&1 || exit 1 +call :pm-echo "Compiling..." +msbuild ALL_BUILD.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 +call :pm-echo "Installing files..." +msbuild INSTALL.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 +cd /D "%DEPS_DIR%" + +call :pm-echo "Downloading librdkafka version %LIBRDKAFKA_VER%..." +call :get-zip https://github.com/confluentinc/librdkafka/archive/v%LIBRDKAFKA_VER%.zip || exit 1 +move librdkafka-* librdkafka >>"%log_file%" 2>&1 +cd /D librdkafka + +call :pm-echo "Generating build configuration..." + +cmake -G "%CMAKE_TARGET%" -A "%ARCH%"^ + -DCMAKE_PREFIX_PATH="%DEPS_DIR%"^ + -DCMAKE_INSTALL_PREFIX="%DEPS_DIR%"^ + -DBUILD_SHARED_LIBS=ON^ + . >>"%log_file%" 2>&1 || exit 1 + +call :pm-echo "Compiling..." +msbuild ALL_BUILD.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% >>"%log_file%" 2>&1 || exit 1 +call :pm-echo "Installing files..." +msbuild INSTALL.vcxproj /p:Configuration=%MSBUILD_CONFIGURATION% /m >>"%log_file%" 2>&1 || exit 1 + +cd /D "%DEPS_DIR%" + +REM for no reason, php-rdkafka check for librdkafka and not rdkafka +REM move them to the appropriate location for php-rdkafka compatibility. +call :pm-echo "Moving libraries files for php-rdkafka compatibility..." +move "lib\rdkafka.lib" "lib\librdkafka.lib" >>"%log_file%" 2>&1 +move "lib\rdkafka++.lib" "lib\librdkafka++.lib" >>"%log_file%" 2>&1 + call :pm-echo "Downloading LibYAML version %LIBYAML_VER%..." call :get-zip https://github.com/yaml/libyaml/archive/%LIBYAML_VER%.zip || exit 1 move libyaml-%LIBYAML_VER% libyaml >>"%log_file%" 2>&1 @@ -223,6 +323,7 @@ call :pm-echo "Getting additional PHP extensions..." cd /D php-src\ext call :get-extension-zip-from-github "pmmpthread" "%PHP_PMMPTHREAD_VER%" "pmmp" "ext-pmmpthread" || exit 1 +call :get-extension-zip-from-github "vanillagenerator" "%PHP_VANILLAGENERATOR_VER%" "NetherGamesMC" "ext-vanillagenerator" || exit 1 call :get-extension-zip-from-github "yaml" "%PHP_YAML_VER%" "php" "pecl-file_formats-yaml" || exit 1 call :get-extension-zip-from-github "chunkutils2" "%PHP_CHUNKUTILS2_VER%" "pmmp" "ext-chunkutils2" || exit 1 call :get-extension-zip-from-github "igbinary" "%PHP_IGBINARY_VER%" "igbinary" "igbinary" || exit 1 @@ -234,6 +335,9 @@ call :get-extension-zip-from-github "xxhash" "%PHP_XXHASH_VER%" call :get-extension-zip-from-github "xdebug" "%PHP_XDEBUG_VER%" "xdebug" "xdebug" || exit 1 call :get-extension-zip-from-github "arraydebug" "%PHP_ARRAYDEBUG_VER%" "pmmp" "ext-arraydebug" || exit 1 call :get-extension-zip-from-github "encoding" "%PHP_ENCODING_VER%" "pmmp" "ext-encoding" || exit 1 +call :get-extension-zip-from-github "rdkafka" "%PHP_LIBKAFKA_VER%" "arnaud-lb" "php-rdkafka" || exit 1 +call :get-extension-zip-from-github "zstd" "%PHP_ZSTD_VER%" "kjdev" "php-ext-zstd" || exit 1 +call :get-extension-zip-from-github "grpc" "%PHP_GRPC_VER%" "larryTheCoder" "php-grpc" || exit 1 call :pm-echo " - crypto: downloading %PHP_CRYPTO_VER%..." git clone https://github.com/bukka/php-crypto.git crypto >>"%log_file%" 2>&1 || exit 1 @@ -278,6 +382,10 @@ call configure^ --enable-opcache^ --enable-opcache-jit=%PHP_JIT_ENABLE_ARG%^ --enable-phar^ + --enable-vanillagenerator=shared^ + --enable-zstd^ + --enable-grpc=shared^ + --enable-protobuf=shared^ --enable-recursionguard=shared^ --enable-sockets^ --enable-tokenizer^ @@ -309,6 +417,7 @@ call configure^ --with-xdebug-compression^ --with-xml^ --with-yaml^ + --with-rdkafka=shared^ --with-pdo-mysql^ --with-pdo-sqlite^ --without-readline >>"%log_file%" 2>&1 || call :pm-fatal-error "Error configuring PHP" @@ -329,7 +438,9 @@ rmdir /s /q "%SOURCES_PATH%\php-src\%ARCH%\Release_TS\php-%PHP_DISPLAY_VER%\lib\ call :pm-echo "Copying artifacts..." cd /D "%outpath%" -mkdir bin +mkdir bin bin\grpc +move "%DEPS_DIR%\grpc\cmake\build\grpc_php_plugin.exe" "bin\grpc\grpc_php_plugin.exe" +move "%DEPS_DIR%\grpc\cmake\build\third_party\protobuf\protoc.exe" "bin\grpc\protoc.exe" move "%SOURCES_PATH%\php-src\%ARCH%\%OUT_PATH_REL%_TS\php-%PHP_DISPLAY_VER%" bin\php cd /D bin\php @@ -366,6 +477,10 @@ if "%PM_VERSION_MAJOR%" geq "5" ( (echo ;Optional extensions, supplied for plugin use)>>"%php_ini%" (echo extension=php_fileinfo.dll)>>"%php_ini%" (echo extension=php_gd.dll)>>"%php_ini%" +(echo extension=php_grpc.dll)>>"%php_ini%" +(echo extension=php_protobuf.dll)>>"%php_ini%" +(echo extension=php_vanillagenerator.dll)>>"%php_ini%" +(echo extension=php_rdkafka.dll)>>"%php_ini%" (echo extension=php_mysqli.dll)>>"%php_ini%" (echo extension=php_sqlite3.dll)>>"%php_ini%" (echo ;Optional extensions, supplied for debugging)>>"%php_ini%"