[bug#67755,v5,2/9] gnu: Add jthread.

Message ID 9fa60d241a95a1f991c3e69950571f9840ed2ef8.1741720525.git.sergio.pastorperez@gmail.com
State New
Headers
Series [bug#67755,v5,1/9] gnu: Add edlib. |

Commit Message

Sergio Pastor Pérez March 11, 2025, 7:15 p.m. UTC
  From: Sergio Pastor Pérez <sergio.pastorperez@outlook.es>

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

Change-Id: I163ab0f8dbd9bc5ed0250612938f82926b07bc92
---
 gnu/packages/cpp.scm | 95 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
  

Patch

diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 338455b9fb..e0c6be7905 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)
@@ -1145,6 +1146,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
+       "C++ class for a joining and cooperative interruptible thread
+(std::jthread) with stop_token helper.")
+      (license license:cc-by4.0))))
+
 (define-public tomlplusplus
   (package
    (name "tomlplusplus")