Subject: [bug#67755] [PATCH v6 1/8] gnu: Add jthread.

From: "Sergio Pastor Pérez" <[email-masked]>
Date: Wed, 19 Mar 2025 18:00:06 +0100

* gnu/packages/cpp.scm (jthread): New variable.

Change-Id: I163ab0f8dbd9bc5ed0250612938f82926b07bc92
---
Note: this package appears unused in the rest of the series.

 gnu/packages/cpp.scm | 95 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 595ec82ccae..9673d607db1 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -118,6 +118,7 @@ (define-module (gnu packages cpp)
   #:use-module (gnu packages pretty-print)
   #:use-module (gnu packages pulseaudio)
   #:use-module (gnu packages tls)
+  #:use-module (gnu packages tex)
   #:use-module (gnu packages web)
   #:use-module (gnu packages webkit)
   #:use-module (gnu packages xdisorg)
@@ -1146,6 +1147,100 @@ (define-public nlohmann-json
 (define-public json-modern-cxx
   (deprecated-package "json-modern-cxx" nlohmann-json))
 
+(define-public jthread
+  (let ((commit "0fa8d394254886c555d6faccd0a3de819b7d47f8")
+        (revision "0"))
+    (package
+      (name "jthread")
+      (version (git-version "0.0.0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/josuttis/jthread")
+               (commit commit)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "11cq4zh7pv86c62ah5im00gxr4cw6d396dp9117z8s271j4lrp6f"))
+         (snippet
+          ;; NOTE: remove precompiled PDFs.
+          #~(begin
+              (use-modules (guix build utils))
+              (for-each (lambda (file)
+                          (delete-file file))
+                        (find-files "." ".pdf"))
+              (delete-file-recursively "doc")))))
+      (outputs '("out" "doc"))
+      (build-system cmake-build-system)
+      (arguments
+       (list
+        #:phases
+        #~(modify-phases %standard-phases
+            (delete 'configure)
+            (delete 'build)
+            (add-after 'unpack 'cd-and-generate-makefile
+              (lambda _
+                (call-with-output-file "source/Makefile.h"
+                  (lambda (port)
+                    ;; GCC 2.95 fails to deal with anonymous unions in glibc's
+                    ;; 'struct_rusage.h', so skip that.
+                    (display "CXX17 := c++ -std=c++17 -pthread\n" port)))))
+            (replace 'check
+              (lambda* (#:key tests? #:allow-other-keys)
+                (when tests?
+                  (invoke "make" "-C" "source"))))
+            (add-after 'check 'build-docs
+              (lambda _
+                (with-directory-excursion "tex"
+                  ;; NOTE: remove strict versioning.
+                  (substitute* "styles.tex"
+                    (("lst@CheckVersion\\{1.6\\}")
+                     "lst@CheckVersion{1.10}"))
+                  (invoke "pdflatex" "std")
+                  (invoke "pdflatex" "std")))) ;Rerun to update references.
+            (replace 'install
+              (lambda _
+                (for-each (lambda (file)
+                            (install-file file
+                                          (string-append #$output "/include")))
+                          '("source/condition_variable_any2.hpp"
+                            "source/stop_token.hpp" "source/jthread.hpp"))))
+            (add-after 'install 'install-doc
+              (lambda _
+                (let ((out (string-append #$output:doc "/share/doc/")))
+                  (mkdir-p out)
+                  (copy-file "tex/std.pdf"
+                             (string-append out
+                                            #$name "-"
+                                            #$version ".pdf"))))))))
+      (native-inputs
+       (list perl
+             (texlive-updmap.cfg
+              (list texlive-ulem
+                    texlive-rsfs
+                    texlive-memoir
+                    texlive-substr
+                    texlive-xcolor
+                    texlive-isodate
+                    texlive-caption
+                    texlive-relsize
+                    texlive-extract
+                    texlive-xpatch
+                    texlive-xkeyval
+                    texlive-jknapltx
+                    texlive-booktabs
+                    texlive-enumitem
+                    texlive-etoolbox
+                    texlive-listings
+                    texlive-microtype
+                    texlive-underscore))))
+      (home-page "https://github.com/josuttis/jthread")
+      (synopsis "C++ class for a joining and cooperative interruptible thread")
+      (description
+       "This package provides a reference implementation of @code{std::jthread},
+a cooperatively interruptible thread that is joined upon destruction.")
+      (license license:cc-by4.0))))
+
 (define-public tomlplusplus
   (package
    (name "tomlplusplus")
-- 
2.48.1