From: Petr Malat Date: Thu, 23 Dec 2021 10:47:04 +0000 (+0100) Subject: Support libzstd compiled with compressor disabled X-Git-Tag: v3.6.0~28^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1649%2Fhead;p=thirdparty%2Flibarchive.git Support libzstd compiled with compressor disabled ZSTD library can be compiled with the compressor disabled, which is handy on space restricted systems as the compressor accounts for more than two thirds of the library size. Detect this case and use libzstd for the decompression only. Compression will be done using zstd binary if it's available. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dfdf966b..1b38ffabc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -618,7 +618,8 @@ IF(ZSTD_FOUND) CMAKE_PUSH_CHECK_STATE() SET(CMAKE_REQUIRED_LIBRARIES ${ZSTD_LIBRARY}) SET(CMAKE_REQUIRED_INCLUDES ${ZSTD_INCLUDE_DIR}) - CHECK_FUNCTION_EXISTS(ZSTD_compressStream HAVE_LIBZSTD) + CHECK_FUNCTION_EXISTS(ZSTD_decompressStream HAVE_LIBZSTD) + CHECK_FUNCTION_EXISTS(ZSTD_compressStream HAVE_LIBZSTD_COMPRESSOR) # # TODO: test for static library. # diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 5ddd2f338..ad799c02e 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -738,6 +738,10 @@ typedef uint64_t uintmax_t; /* Define to 1 if you have the `zstd' library (-lzstd). */ #cmakedefine HAVE_LIBZSTD 1 +/* Define to 1 if you have the `zstd' library (-lzstd) with compression + support. */ +#cmakedefine HAVE_LIBZSTD_COMPRESSOR 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LIMITS_H 1 diff --git a/configure.ac b/configure.ac index cb89c3ee8..bd92e2cc4 100644 --- a/configure.ac +++ b/configure.ac @@ -400,7 +400,9 @@ AC_ARG_WITH([zstd], if test "x$with_zstd" != "xno"; then AC_CHECK_HEADERS([zstd.h]) - AC_CHECK_LIB(zstd,ZSTD_compressStream) + AC_CHECK_LIB(zstd,ZSTD_decompressStream) + AC_CHECK_LIB(zstd,ZSTD_compressStream, + AC_DEFINE([HAVE_LIBZSTD_COMPRESSOR], [1], [Define to 1 if you have the `zstd' library (-lzstd) with compression support.])) fi AC_ARG_WITH([lzma], diff --git a/libarchive/archive_write_add_filter_zstd.c b/libarchive/archive_write_add_filter_zstd.c index 41e4c520e..e85b7669c 100644 --- a/libarchive/archive_write_add_filter_zstd.c +++ b/libarchive/archive_write_add_filter_zstd.c @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); struct private_data { int compression_level; int threads; -#if HAVE_ZSTD_H && HAVE_LIBZSTD +#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR ZSTD_CStream *cstream; int64_t total_in; ZSTD_outBuffer out; @@ -77,7 +77,7 @@ static int archive_compressor_zstd_write(struct archive_write_filter *, const void *, size_t); static int archive_compressor_zstd_close(struct archive_write_filter *); static int archive_compressor_zstd_free(struct archive_write_filter *); -#if HAVE_ZSTD_H && HAVE_LIBZSTD +#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR static int drive_compressor(struct archive_write_filter *, struct private_data *, int, const void *, size_t); #endif @@ -109,7 +109,7 @@ archive_write_add_filter_zstd(struct archive *_a) f->name = "zstd"; data->compression_level = CLEVEL_DEFAULT; data->threads = 0; -#if HAVE_ZSTD_H && HAVE_LIBZSTD +#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR data->cstream = ZSTD_createCStream(); if (data->cstream == NULL) { free(data); @@ -136,7 +136,7 @@ static int archive_compressor_zstd_free(struct archive_write_filter *f) { struct private_data *data = (struct private_data *)f->data; -#if HAVE_ZSTD_H && HAVE_LIBZSTD +#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR ZSTD_freeCStream(data->cstream); free(data->out.dst); #else @@ -189,7 +189,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, if (string_is_numeric(value) != ARCHIVE_OK) { return (ARCHIVE_WARN); } -#if HAVE_ZSTD_H && HAVE_LIBZSTD +#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR maximum = ZSTD_maxCLevel(); #if ZSTD_VERSION_NUMBER >= MINVER_MINCLEVEL if (ZSTD_versionNumber() >= MINVER_MINCLEVEL) { @@ -228,7 +228,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key, return (ARCHIVE_WARN); } -#if HAVE_ZSTD_H && HAVE_LIBZSTD +#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR /* * Setup callback. */ @@ -353,7 +353,7 @@ drive_compressor(struct archive_write_filter *f, } } -#else /* HAVE_ZSTD_H && HAVE_LIBZSTD */ +#else /* HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR */ static int archive_compressor_zstd_open(struct archive_write_filter *f) @@ -415,4 +415,4 @@ archive_compressor_zstd_close(struct archive_write_filter *f) return __archive_write_program_close(f, data->pdata); } -#endif /* HAVE_ZSTD_H && HAVE_LIBZSTD */ +#endif /* HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR */