From a2be5154bc7213de1462cf4d366ef10f578841cb Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 30 Jan 2018 10:13:38 +0100 Subject: new package --- .gitignore | 8 ++ 7.patch | 177 +++++++++++++++++++++++++++++++++++++++++ Makefile | 4 + REFLECTION | 128 ++++++++++++++++++++++++++++++ makesrc.sh | 27 +++++++ php-zstd.spec | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 593 insertions(+) create mode 100644 .gitignore create mode 100644 7.patch create mode 100644 Makefile create mode 100644 REFLECTION create mode 100755 makesrc.sh create mode 100644 php-zstd.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc9aa8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +clog +package-*.xml +*.tgz +*.tar.gz +*.tar.xz +*.tar.xz.asc +*.src.rpm +*/*rpm diff --git a/7.patch b/7.patch new file mode 100644 index 0000000..3bc5393 --- /dev/null +++ b/7.patch @@ -0,0 +1,177 @@ +From 049d21d1865db4355a4b8598aa705ba2c3f3e7f1 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Tue, 30 Jan 2018 09:24:02 +0100 +Subject: [PATCH 1/3] fix build warning [-Wunused-variable] + +--- + zstd.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/zstd.c b/zstd.c +index c382c83..2257280 100644 +--- a/zstd.c ++++ b/zstd.c +@@ -294,7 +294,6 @@ ZEND_FUNCTION(zstd_uncompress_dict) + + ZEND_MINFO_FUNCTION(zstd) + { +- char buffer[128]; + php_info_print_table_start(); + php_info_print_table_row(2, "Zstd support", "enabled"); + php_info_print_table_row(2, "Extension Version", PHP_ZSTD_EXT_VERSION); + +From 1bec6a0eb38159148e447b8126745d85a3a222e1 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Tue, 30 Jan 2018 09:26:19 +0100 +Subject: [PATCH 2/3] add --with-libzstd option to use system library + +--- + .gitignore | 2 ++ + config.m4 | 35 +++++++++++++++++++++++++++++------ + 2 files changed, 31 insertions(+), 6 deletions(-) + +diff --git a/.gitignore b/.gitignore +index b732353..c4bbefa 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -22,3 +22,5 @@ run-tests.php + /build + /include + /modules ++ltmain.sh.backup ++tmp-php.ini +diff --git a/config.m4 b/config.m4 +index 5a117e1..de86242 100644 +--- a/config.m4 ++++ b/config.m4 +@@ -24,16 +24,39 @@ fi + PHP_ARG_ENABLE(zstd, whether to enable zstd support, + [ --enable-zstd Enable zstd support]) + ++PHP_ARG_WITH(libzstd, whether to use system zstd library, ++[ --with-libzsd Use system zstd library], no, no) ++ + if test "$PHP_ZSTD" != "no"; then + +- ZSTD_COMMON_SOURCES="zstd/lib/common/entropy_common.c zstd/lib/common/error_private.c zstd/lib/common/fse_decompress.c zstd/lib/common/pool.c zstd/lib/common/threading.c zstd/lib/common/xxhash.c zstd/lib/common/zstd_common.c" +- ZSTD_COMPRESS_SOURCES="zstd/lib/compress/fse_compress.c zstd/lib/compress/huf_compress.c zstd/lib/compress/zstd_compress.c zstd/lib/compress/zstdmt_compress.c" +- ZSTD_DECOMPRESS_SOURCES="zstd/lib/decompress/huf_decompress.c zstd/lib/decompress/zstd_decompress.c" ++ if test "$PHP_LIBZSTD" != "no"; then ++ AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + +- PHP_ADD_INCLUDE(zstd/lib/common) +- PHP_ADD_INCLUDE(zstd/lib) ++ AC_MSG_CHECKING(for libzstd) ++ if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libzstd; then ++ if $PKG_CONFIG libzstd --atleast-version 1; then ++ LIBZSTD_CFLAGS=`$PKG_CONFIG libzstd --cflags` ++ LIBZSTD_LIBDIR=`$PKG_CONFIG libzstd --libs` ++ LIBZSTD_VERSON=`$PKG_CONFIG libzstd --modversion` ++ AC_MSG_RESULT(from pkgconfig: version $LIBZSTD_VERSON) ++ else ++ AC_MSG_ERROR(system libzstd is too old) ++ fi ++ else ++ AC_MSG_ERROR(pkg-config not found) ++ fi ++ PHP_EVAL_LIBLINE($LIBZSTD_LIBDIR, ZSTD_SHARED_LIBADD) ++ PHP_EVAL_INCLINE($LIBZSTD_CFLAGS) ++ else ++ ZSTD_COMMON_SOURCES="zstd/lib/common/entropy_common.c zstd/lib/common/error_private.c zstd/lib/common/fse_decompress.c zstd/lib/common/pool.c zstd/lib/common/threading.c zstd/lib/common/xxhash.c zstd/lib/common/zstd_common.c" ++ ZSTD_COMPRESS_SOURCES="zstd/lib/compress/fse_compress.c zstd/lib/compress/huf_compress.c zstd/lib/compress/zstd_compress.c zstd/lib/compress/zstdmt_compress.c" ++ ZSTD_DECOMPRESS_SOURCES="zstd/lib/decompress/huf_decompress.c zstd/lib/decompress/zstd_decompress.c" + ++ PHP_ADD_INCLUDE(zstd/lib/common) ++ PHP_ADD_INCLUDE(zstd/lib) ++ fi + PHP_NEW_EXTENSION(zstd, zstd.c $ZSTD_COMMON_SOURCES $ZSTD_COMPRESS_SOURCES $ZSTD_DECOMPRESS_SOURCES, $ext_shared) ++ PHP_SUBST(ZSTD_SHARED_LIBADD) + + ifdef([PHP_INSTALL_HEADERS], + [ +@@ -45,7 +68,7 @@ fi + + dnl coverage + PHP_ARG_ENABLE(coverage, whether to enable coverage support, +-[ --enable-coverage Enable coverage support], no, no) ++[ --enable-coverage Enable coverage support], no, no) + + if test "$PHP_COVERAGE" != "no"; then + EXTRA_CFLAGS="--coverage" + +From 297f3761d19189c1abc4ad5975013fb459bf796d Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Tue, 30 Jan 2018 09:27:01 +0100 +Subject: [PATCH 3/3] relax test (few char diff across libzstd versions) + +--- + tests/008.phpt | 44 ++++++++++++++++++++++---------------------- + tests/dictionary.phpt | 2 +- + 2 files changed, 23 insertions(+), 23 deletions(-) + +diff --git a/tests/008.phpt b/tests/008.phpt +index 7b74976..0ab3666 100644 +--- a/tests/008.phpt ++++ b/tests/008.phpt +@@ -30,28 +30,28 @@ check_compress($data, 0); + *** Data size *** + 3547 + *** Compression Level *** +-1 -- 1874 -- true +-2 -- 1847 -- true +-3 -- 1840 -- true +-4 -- 1815 -- true +-5 -- 1805 -- true +-6 -- 1803 -- true +-7 -- 1803 -- true +-8 -- 1803 -- true +-9 -- 1803 -- true +-10 -- 1803 -- true +-11 -- 1800 -- true +-12 -- 1796 -- true +-13 -- 1796 -- true +-14 -- 1796 -- true +-15 -- 1796 -- true +-16 -- 1796 -- true +-17 -- 1796 -- true +-18 -- 1796 -- true +-19 -- 1796 -- true +-20 -- 1796 -- true +-21 -- 1796 -- true +-22 -- 1796 -- true ++1 -- 1%d -- true ++2 -- 1%d -- true ++3 -- 1%d -- true ++4 -- 1%d -- true ++5 -- 1%d -- true ++6 -- 1%d -- true ++7 -- 1%d -- true ++8 -- 1%d -- true ++9 -- 1%d -- true ++10 -- 1%d -- true ++11 -- 1%d -- true ++12 -- 1%d -- true ++13 -- 1%d -- true ++14 -- 1%d -- true ++15 -- 1%d -- true ++16 -- 1%d -- true ++17 -- 1%d -- true ++18 -- 1%d -- true ++19 -- 1%d -- true ++20 -- 1%d -- true ++21 -- 1%d -- true ++22 -- 1%d -- true + *** Invalid Compression Level *** + + Warning: zstd_compress: compression level (100) must be within 1..22 in %s on line %d +diff --git a/tests/dictionary.phpt b/tests/dictionary.phpt +index c5c2ab6..b3455b6 100644 +--- a/tests/dictionary.phpt ++++ b/tests/dictionary.phpt +@@ -24,5 +24,5 @@ check_compress_dict($data, $dictionary); + *** Data size *** + 3547 + *** Dictionary Compression *** +-142 -- 1924 -- true ++142 -- 1%d -- true + ===Done=== diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..91b0fd5 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SRCDIR := $(shell pwd) +NAME := $(shell basename $(SRCDIR)) +include ../../common/Makefile + diff --git a/REFLECTION b/REFLECTION new file mode 100644 index 0000000..0e32f52 --- /dev/null +++ b/REFLECTION @@ -0,0 +1,128 @@ +Extension [ extension #176 zstd version 0.4.11 ] { + + - Functions { + Function [ function zstd_compress ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $level ] + } + } + Function [ function zstd_uncompress ] { + + - Parameters [1] { + Parameter #0 [ $data ] + } + } + Function [ function zstd_decompress ] { + + - Parameters [1] { + Parameter #0 [ $data ] + } + } + Function [ function zstd_compress_dict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function zstd_uncompress_dict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function zstd_compress_usingcdict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function zstd_decompress_dict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function zstd_uncompress_usingcdict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function zstd_decompress_usingcdict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function Zstd\compress ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $level ] + } + } + Function [ function Zstd\uncompress ] { + + - Parameters [1] { + Parameter #0 [ $data ] + } + } + Function [ function Zstd\decompress ] { + + - Parameters [1] { + Parameter #0 [ $data ] + } + } + Function [ function Zstd\compress_dict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function Zstd\compress_usingcdict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function Zstd\uncompress_dict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function Zstd\decompress_dict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function Zstd\uncompress_usingcdict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + Function [ function Zstd\decompress_usingcdict ] { + + - Parameters [2] { + Parameter #0 [ $data ] + Parameter #1 [ $dictBuffer ] + } + } + } +} + diff --git a/makesrc.sh b/makesrc.sh new file mode 100755 index 0000000..ea1e7e8 --- /dev/null +++ b/makesrc.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +NAME=$(basename $PWD) +OWNER=$(sed -n '/^%global gh_owner/{s/.* //;p}' $NAME.spec) +PROJECT=$(sed -n '/^%global gh_project/{s/.* //;p}' $NAME.spec) +VERSION=$(sed -n '/^Version:/{s/.* //;p}' $NAME.spec) +COMMIT=$(sed -n '/^%global gh_commit/{s/.* //;p}' $NAME.spec) +SHORT=${COMMIT:0:7} + +echo -e "\nCreate git snapshot\nName=$NAME, Owner=$OWNER, Project=$PROJECT, Version=$VERSION\n" + +echo "Cloning..." +rm -rf $PROJECT-$COMMIT +git clone --recursive https://github.com/$OWNER/$PROJECT.git $PROJECT-$COMMIT + +echo "Getting commit..." +pushd $PROJECT-$COMMIT +git checkout $COMMIT +popd + +echo "Archiving..." +tar czf $NAME-$VERSION-$SHORT.tgz --exclude .git $PROJECT-$COMMIT + +echo "Cleaning..." +rm -rf $PROJECT-$COMMIT + +echo "Done." diff --git a/php-zstd.spec b/php-zstd.spec new file mode 100644 index 0000000..8a88b43 --- /dev/null +++ b/php-zstd.spec @@ -0,0 +1,249 @@ +# remirepo spec file for php-zstd +# +# Copyright (c) 2018 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/4.0/ +# +# Please, preserve the changelog entries +# +%if 0%{?scl:1} +%global sub_prefix %{scl_prefix} +%scl_package php-zstd +%else +%global pkg_name %{name} +%endif + +%if 0%{?fedora} >= 24 || 0%{?rhel} >= 6 +%global with_libzstd 1 +%else +%global with_libzstd 0 +%endif + + +%global gh_commit 8ca4cf45c200bcfa80469703d2f3a2ab46918a45 +%global gh_short %(c=%{gh_commit}; echo ${c:0:7}) +%global gh_owner kjdev +%global gh_project php-ext-zstd +#global gh_date 20160608 +%global pecl_name zstd +%global with_zts 0%{!?_without_zts:%{?__ztsphp:1}} +%global ini_name 40-%{pecl_name}.ini + +Summary: Zstd Extension for PHP +Name: %{?sub_prefix}php-%{pecl_name} +Version: 0.4.11 +%if 0%{?gh_date:1} +Release: 0.3.%{gh_date}git%{gh_short}%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +%else +Release: 1%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +%endif +%if %{?with_libzstd} +License: MIT +%else +# bundled library is BSD +License: MIT and BSD +%endif +Group: Development/Languages +URL: https://github.com/%{gh_owner}/%{gh_project} +Source0: %{pkg_name}-%{version}-%{gh_short}.tgz +# retrieve a recursive git snapshot with submodule +Source1: makesrc.sh + +# https://github.com/kjdev/php-ext-zstd/pull/7 +Patch0: https://patch-diff.githubusercontent.com/raw/kjdev/php-ext-zstd/pull/7.patch + +BuildRequires: %{?scl_prefix}php-devel +%if %{?with_libzstd} +BuildRequires: libzstd-devel >= 1.3 +%else +Provides: bundled(libstd) = 1.3.1 +%endif + +Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} +Requires: %{?scl_prefix}php(api) = %{php_core_api} +%{?_sclreq:Requires: %{?scl_prefix}runtime%{?_sclreq}%{?_isa}} + +%if "%{?vendor}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} +%if "%{php_version}" > "5.6" +Obsoletes: php56u-%{pecl_name} <= %{version} +Obsoletes: php56w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.0" +Obsoletes: php70u-%{pecl_name} <= %{version} +Obsoletes: php70w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.1" +Obsoletes: php71u-%{pecl_name} <= %{version} +Obsoletes: php71w-%{pecl_name} <= %{version} +%endif +%if "%{php_version}" > "7.2" +Obsoletes: php72u-%{pecl_name} <= %{version} +Obsoletes: php72w-%{pecl_name} <= %{version} +%endif +%endif + +%if 0%{?fedora} < 20 && 0%{?rhel} < 7 +# Filter shared private +%{?filter_provides_in: %filter_provides_in %{_libdir}/.*\.so$} +%{?filter_setup} +%endif + + +%description +This extension allows Zstd compression. + +Package built for PHP %(%{__php} -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')%{?scl: as Software Collection (%{scl} by %{?scl_vendor}%{!?scl_vendor:rh})}. + + +%package devel +Summary: %{name} developer files (header) +Group: Development/Libraries +Requires: %{name}%{?_isa} = %{version}-%{release} +Requires: %{?scl_prefix}php-devel%{?_isa} +Provides: %{?scl_prefix}php-%{pecl_name}-devel = %{version}-%{release} +Provides: %{?scl_prefix}php-%{pecl_name}-devel%{?_isa} = %{version}-%{release} + +%description devel +These are the files needed to compile programs using %{name}. + + +%prep +%setup -qc +mv %{gh_project}-%{gh_commit} NTS + +cd NTS +%patch0 -p1 + +# replace symlink +rm LICENSE-zstd +mv zstd/LICENSE LICENSE-zstd + +%if %{?with_libzstd} +# Use the system library +rm -r zstd +%endif + +# Sanity check, really often broken +extver=$(sed -n '/#define PHP_ZSTD_EXT_VERSION/{s/.* "//;s/".*$//;p}' php_zstd.h) +if test "x${extver}" != "x%{version}%{?gh_date:-dev}"; then + : Error: Upstream extension version is ${extver}, expecting %{version}%{?gh_date:-dev}. + exit 1 +fi +cd .. + +%if %{with_zts} +# duplicate for ZTS build +cp -pr NTS ZTS +%endif + +# Drop in the bit of configuration +cat << 'EOF' | tee %{ini_name} +; Enable '%{summary}' extension module +extension = %{pecl_name}.so +EOF + + +%build +%{?dtsenable} + +cd NTS +%{_bindir}/phpize +%configure \ + --with-php-config=%{_bindir}/php-config \ +%if %{?with_libzstd} + --with-libzstd \ +%endif + --with-libdir=%{_lib} \ + --enable-zstd +make %{?_smp_mflags} + +%if %{with_zts} +cd ../ZTS +%{_bindir}/zts-phpize +%configure \ + --with-php-config=%{_bindir}/zts-php-config \ +%if %{?with_libzstd} + --with-libzstd \ +%endif + --with-libdir=%{_lib} \ + --enable-zstd +make %{?_smp_mflags} +%endif + + +%install +%{?dtsenable} + +# Install the NTS stuff +make -C NTS install INSTALL_ROOT=%{buildroot} +install -D -m 644 %{ini_name} %{buildroot}%{php_inidir}/%{ini_name} + +%if %{with_zts} +# Install the ZTS stuff +make -C ZTS install INSTALL_ROOT=%{buildroot} +install -D -m 644 %{ini_name} %{buildroot}%{php_ztsinidir}/%{ini_name} +%endif + + + +%check +cd NTS +: Minimal load test for NTS extension +%{__php} --no-php-ini \ + --define extension=%{buildroot}%{php_extdir}/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for NTS extension +TEST_PHP_EXECUTABLE=%{__php} \ +TEST_PHP_ARGS="-n -d extension=%{buildroot}%{php_extdir}/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__php} -n run-tests.php --show-diff || : ignore + +%if %{with_zts} +cd ../ZTS +: Minimal load test for ZTS extension +%{__ztsphp} --no-php-ini \ + --define extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for ZTS extension +TEST_PHP_EXECUTABLE=%{__ztsphp} \ +TEST_PHP_ARGS="-n -d extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__ztsphp} -n run-tests.php --show-diff +%endif + + +%files +%{!?_licensedir:%global license %%doc} +%license NTS/LICENSE +%if ! %{?with_libzstd} +%license NTS/LICENSE-zstd +%endif +%doc NTS/README.md + +%config(noreplace) %{php_inidir}/%{ini_name} +%{php_extdir}/%{pecl_name}.so + +%if %{with_zts} +%config(noreplace) %{php_ztsinidir}/%{ini_name} +%{php_ztsextdir}/%{pecl_name}.so +%endif + + +%files devel +%doc NTS/tests +%{php_incldir}/ext/%{pecl_name} + +%if %{with_zts} +%{php_ztsincldir}/ext/%{pecl_name} +%endif + + +%changelog +* Tue Jan 30 2018 Remi Collet - 0.4.11-1 +- new package, version 0.4.11 +- add patch to build with system libzstd from + https://github.com/kjdev/php-ext-zstd/pull/7 -- cgit