Subject: bug#50617: [core-updates-frozen] CMake fails to build on i686-linux

From: Ludovic Courtès <[email-masked]>
Date: Thu, 16 Sep 2021 17:20:15 +0200

Hi,

Guillaume Le Vaillant <[email-masked]> skribis:

> Ludovic Courtès <[email-masked]> skribis:
>
>> On ‘core-updates-frozen’, CMake has one test failure on i686-linux when
>> building on berlin (e.g., <https://ci.guix.gnu.org/build/790602/log/raw>):
>>
>> --8<---------------cut here---------------start------------->8---
>> 545/558 Test #518: RunCMake.CPack_TXZ ................................***Failed    3.79 sec
>> [...]
>> --8<---------------cut here---------------end--------------->8---
>>
>> I cannot reproduce it on hardware with 32 cores.  I suspect it has to do
>> with the number of threads used for xz compression, which defaults to
>> the number of cores, and some of the build machines on berlin have way
>> more cores.
>>
>> Ludo’.
>
> I tried a few times on a machine with 16 cores, and I can't reproduce
> either. The build succeeded every time.

My latest attempt is to go as far as setting the number of threads used
by libarchive to 1 (patch attached).  However, that still fails
systematically on berlin’s 32-core build machines.

The Internet doesn’t seem to have much to say about this problem.

Ideas anyone?

Ludo’.

diff --git a/gnu/packages/cmake.scm b/gnu/packages/cmake.scm
index f76ee3ff3a..a235d922e0 100644
--- a/gnu/packages/cmake.scm
+++ b/gnu/packages/cmake.scm
@@ -92,7 +92,7 @@ using the CMake build system.")
 
 ;;; Build phases shared between 'cmake-bootstrap' and the later variants
 ;;; that use cmake-build-system.
-(define %common-build-phases
+(define (%common-build-phases)
   `((add-after 'unpack 'split-package
       ;; Remove files that have been packaged in other package recipes.
       (lambda _
@@ -100,6 +100,18 @@ using the CMake build system.")
         (substitute* "Auxiliary/CMakeLists.txt"
           ((".*cmake-mode.el.*") ""))
         #t))
+    ,@(let ((system (or (%current-target-system) (%current-system))))
+        (if (or (string-prefix? "i686-" system)
+                (string-prefix? "i586-" system))
+            '((add-after 'unpack 'clamp-xz-thread-number
+                (lambda _
+                  ;; By default, 'CPack' would use as many threads as the
+                  ;; number of available cores for xz compression.
+                  ;; However, this leads to test failures: <XXX>.
+                  (substitute* "Source/cmArchiveWrite.cxx"
+                    (("case CompressXZ:")
+                     "case CompressXZ: numThreads = 1;\n")))))
+            '()))
     (add-before 'configure 'patch-bin-sh
       (lambda _
         ;; Replace "/bin/sh" by the right path in... a lot of
@@ -188,7 +200,7 @@ using the CMake build system.")
            " --exclude-regex ^\\(" (string-join skipped-tests "\\|") "\\)$")))
        #:phases
        (modify-phases %standard-phases
-         ,@%common-build-phases
+         ,@(%common-build-phases)
          (add-before 'configure 'set-paths
            (lambda _
              ;; Help cmake's bootstrap process to find system libraries
@@ -295,7 +307,7 @@ and workspaces that can be used in the compiler environment of your choice.")
        #:build-type "Release"
        #:phases
        (modify-phases %standard-phases
-         ,@%common-build-phases
+         ,@(%common-build-phases)
          (add-after 'install 'delete-help-documentation
            (lambda* (#:key outputs #:allow-other-keys)
              (delete-file-recursively