]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Support libzstd compiled with compressor disabled 1649/head
authorPetr Malat <oss@malat.biz>
Thu, 23 Dec 2021 10:47:04 +0000 (11:47 +0100)
committerPetr Malat <oss@malat.biz>
Thu, 23 Dec 2021 11:23:16 +0000 (12:23 +0100)
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.

CMakeLists.txt
build/cmake/config.h.in
configure.ac
libarchive/archive_write_add_filter_zstd.c

index 6dfdf966b8fb69a12e166fbbd9f637621f7fc024..1b38ffabc4acd3ad9c96236dcfdcb1482ce01542 100644 (file)
@@ -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.
   #
index 5ddd2f33833704ca84a0b1fee92bcae12f6610f3..ad799c02e9c331792c6723949b2e5a9c5d2a40ba 100644 (file)
@@ -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 <limits.h> header file. */
 #cmakedefine HAVE_LIMITS_H 1
 
index cb89c3ee81530e63e18f12aec2bbf04e8c0a1a34..bd92e2cc44949c4b7de55eb16be2e433debeca13 100644 (file)
@@ -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],
index 41e4c520e13612a7f67fd05f10c2d46e70766f52..e85b7669c50d6549d26287353c7e47d3a0748f1e 100644 (file)
@@ -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 */