From 29f63129be470e44b99f498576e311111648a620 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Feb 2022 15:31:37 -0500 Subject: CPack: Format CPACK_THREADS compression methods as a definition list Prepare to add more entries beyond `xz`. --- Modules/CPack.cmake | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index 6650f7c..e267ed0 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -304,14 +304,19 @@ installers. The most commonly-used variables are: By default ``CPACK_THREADS`` is set to ``1``. - Currently only ``xz`` compression *may* take advantage of multiple cores. - Other compression methods ignore this value and use only one thread. + The following compression methods may take advantage of multiple cores: + + ``xz`` + Supported if CMake is built with a ``liblzma`` that supports + parallel compression. - .. versionadded:: 3.21 + .. versionadded:: 3.21 - Official CMake binaries available on ``cmake.org`` now ship - with a ``liblzma`` that supports parallel compression. - Older versions did not. + Official CMake binaries available on ``cmake.org`` now ship + with a ``liblzma`` that supports parallel compression. + Older versions did not. + + Other compression methods ignore this value and use only one thread. Variables for Source Package Generators ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- cgit v0.12 From 215c4efd3ef620233c42530d4b237f60e9876958 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Fri, 18 Feb 2022 12:00:19 -0600 Subject: cmArchiveWrite: Factor out thread count selection Prepare to use it for more than one compression method. --- Source/cmArchiveWrite.cxx | 50 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 9e0d80c..31a2a5a 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -95,6 +95,19 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, , Verbose(false) , Format(format) { + // Upstream fixed an issue with their integer parsing in 3.4.0 + // which would cause spurious errors to be raised from `strtoull`. + + if (numThreads < 1) { + int upperLimit = (numThreads == 0) ? std::numeric_limits::max() + : std::abs(numThreads); + + numThreads = + cm::clamp(std::thread::hardware_concurrency(), 1, upperLimit); + } + + std::string sNumThreads = std::to_string(numThreads); + switch (c) { case CompressNone: if (archive_write_add_filter_none(this->Archive) != ARCHIVE_OK) { @@ -150,36 +163,23 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, return; } - { #if ARCHIVE_VERSION_NUMBER >= 3004000 - // Upstream fixed an issue with their integer parsing in 3.4.0 - // which would cause spurious errors to be raised from `strtoull`. - - if (numThreads < 1) { - int upperLimit = (numThreads == 0) ? std::numeric_limits::max() - : std::abs(numThreads); - - numThreads = - cm::clamp(std::thread::hardware_concurrency(), 1, upperLimit); - } # ifdef _AIX - // FIXME: Using more than 2 threads creates an empty archive. - // Enforce this limit pending further investigation. - numThreads = std::min(numThreads, 2); + // FIXME: Using more than 2 threads creates an empty archive. + // Enforce this limit pending further investigation. + if (numThreads > 2) { + numThreads = 2; + sNumThreads = std::to_string(numThreads); + } # endif - - std::string sNumThreads = std::to_string(numThreads); - - if (archive_write_set_filter_option(this->Archive, "xz", "threads", - sNumThreads.c_str()) != - ARCHIVE_OK) { - this->Error = cmStrCat("archive_compressor_xz_options: ", - cm_archive_error_string(this->Archive)); - return; - } -#endif + if (archive_write_set_filter_option(this->Archive, "xz", "threads", + sNumThreads.c_str()) != ARCHIVE_OK) { + this->Error = cmStrCat("archive_compressor_xz_options: ", + cm_archive_error_string(this->Archive)); + return; } +#endif break; case CompressZstd: -- cgit v0.12 From 525faec4e9d7a25431504d6fe47313f1478b26e9 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 17 Feb 2022 16:12:16 -0600 Subject: CPack: Add parallel zstd compression --- Help/release/dev/cpack-zstd-parallel.rst | 6 ++++++ Modules/CPack.cmake | 6 ++++++ Source/cmArchiveWrite.cxx | 9 +++++++++ 3 files changed, 21 insertions(+) create mode 100644 Help/release/dev/cpack-zstd-parallel.rst diff --git a/Help/release/dev/cpack-zstd-parallel.rst b/Help/release/dev/cpack-zstd-parallel.rst new file mode 100644 index 0000000..da22625 --- /dev/null +++ b/Help/release/dev/cpack-zstd-parallel.rst @@ -0,0 +1,6 @@ +cpack-zstd-parallel +------------------- + +* CPack now supports the :variable:`CPACK_THREADS` option for ``zstd`` + compression when compiled with libarchive 3.6 or higher. It is + supported by official CMake binaries available on ``cmake.org``. diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index e267ed0..5a22be5 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -316,6 +316,12 @@ installers. The most commonly-used variables are: with a ``liblzma`` that supports parallel compression. Older versions did not. + ``zstd`` + .. versionadded:: 3.24 + + Supported if CMake is built with libarchive 3.6 or higher. + Official CMake binaries available on ``cmake.org`` support it. + Other compression methods ignore this value and use only one thread. Variables for Source Package Generators diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 31a2a5a..cfde37c 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -188,6 +188,15 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, cm_archive_error_string(this->Archive)); return; } + +#if ARCHIVE_VERSION_NUMBER >= 3006000 + if (archive_write_set_filter_option(this->Archive, "zstd", "threads", + sNumThreads.c_str()) != ARCHIVE_OK) { + this->Error = cmStrCat("archive_compressor_zstd_options: ", + cm_archive_error_string(this->Archive)); + return; + } +#endif break; } -- cgit v0.12