Subject: [bug#61724] [PATCH 1/3] gnu: Add nlohmann-json.

From: jgart <[email-masked]>
Date: Thu, 23 Feb 2023 06:11:59 +0100

* gnu/packages/cpp.scm (nlohmann-json): New variable.
---
 gnu/packages/cpp.scm | 98 +++++++++++++++++---------------------------
 1 file changed, 37 insertions(+), 61 deletions(-)

diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index ed6ae69198..7091459d97 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -22,7 +22,7 @@
 ;;; Copyright © 2021 Nicolò Balzarotti <[email-masked]>
 ;;; Copyright © 2021 Guillaume Le Vaillant <[email-masked]>
 ;;; Copyright © 2021 Nikolay Korotkiy <[email-masked]>
-;;; Copyright © 2021 jgart <[email-masked]>
+;;; Copyright © 2021, 2023 jgart <[email-masked]>
 ;;; Copyright © 2021 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2021 Disseminate Dissent <[email-masked]>
 ;;; Copyright © 2022 Efraim Flashner <[email-masked]>
@@ -595,74 +595,50 @@ (define-public json-dto
 data transfer object.")
     (license license:bsd-3)))
 
-(define-public json-modern-cxx
+(define-public nlohmann-json
   (package
-    (name "json-modern-cxx")
-    (version "3.10.5")
-    (home-page "https://github.com/nlohmann/json")
+    (name "nlohmann-json")
+    (version "3.11.2")
     (source
      (origin
        (method git-fetch)
-       (uri (git-reference (url home-page)
-                           (commit (string-append "v" version))))
-       (sha256
-        (base32 "1f9mi45ilwjc2w92grjc53sw038840bjpn8yjf6wc6bxs2nijfqd"))
+       (uri (git-reference
+             (url "https://github.com/nlohmann/json")
+             (commit (string-append "v" version))))
        (file-name (git-file-name name version))
-       (modules '((guix build utils)))
-       (snippet
-        '(begin
-           ;; Delete bundled software.  Preserve doctest_compatibility.h, which
-           ;; is a wrapper library added by this package.
-           (install-file "./test/thirdparty/doctest/doctest_compatibility.h" "/tmp")
-           (for-each delete-file-recursively
-                     '("./third_party" "./test/thirdparty"))
-           (install-file "/tmp/doctest_compatibility.h" "./test/thirdparty/doctest")
-
-           ;; Adjust for the unbundled fifo_map and doctest.
-           (substitute* "./test/thirdparty/doctest/doctest_compatibility.h"
-             (("#include \"doctest\\.h\"")
-              "#include <doctest/doctest.h>"))
-           (with-directory-excursion "test/src"
-             (let ((files (find-files "." "\\.cpp$")))
-               (substitute* files
-                 (("#include ?\"(fifo_map.hpp)\"" all fifo-map-hpp)
-                  (string-append
-                   "#include <fifo_map/" fifo-map-hpp ">")))))))))
+       (sha256
+        (base32 "0g6rfsbkvrxmacchz4kbr741yybj7mls3r4hgyfdd3pdbqhn2is9"))))
     (build-system cmake-build-system)
     (arguments
-     '(#:configure-flags
-       (list "-DJSON_MultipleHeaders=ON" ; For json_fwd.hpp.
-             (string-append "-DJSON_TestDataDirectory="
-                            (dirname
-                             (search-input-directory %build-inputs
-                                                     "json_nlohmann_tests"))))
-       #:phases (modify-phases %standard-phases
-                  (replace 'check
-                    (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
-                      (if tests?
-                          ;; Some tests need git and a full checkout, skip those.
-                          (invoke "ctest" "-LE" "git_required"
-                                  "-j" (if parallel-tests?
-                                           (number->string (parallel-job-count))
-                                           "1"))
-                          (format #t "test suite not run~%")))))))
+      (list #:out-of-source? #t
+            #:configure-flags
+            #~(list "-DJSON_FastTests=ON"
+                    "-DJSON_MultipleHeaders=ON"
+                    "-DJSON_BuildTests=ON"
+                    (string-append "-DJSON_TestDataDirectory="
+                                   #$(this-package-native-input "json-test-data")))
+            #:phases
+            #~(modify-phases %standard-phases
+                (replace 'check
+                  (lambda* (#:key tests? #:allow-other-keys)
+                    ;; Skip tests that require git or modify “installed files”.
+                    (when tests?
+                      (invoke "make" "ARGS=-LE 'not_reproducible|git_required' --verbose")))))))
     (native-inputs
-     (list amalgamate
-           (let ((version "3.0.0"))
-             (origin
-               (method git-fetch)
-               (uri (git-reference
-                     (url "https://github.com/nlohmann/json_test_data")
-                     (commit (string-append "v" version))))
-               (file-name (git-file-name "json_test_data" version))
-               (sha256
-                (base32
-                 "0nzsjzlvk14dazwh7k2jb1dinb0pv9jbx5jsyn264wvva0y7daiv"))))))
-    (inputs
-     (list doctest fifo-map))
-    (synopsis "JSON parser and printer library for C++")
-    (description "JSON for Modern C++ is a C++ JSON library that provides
-intuitive syntax and trivial integration.")
+      `(("json-test-data"
+         ,(origin
+            (method git-fetch)
+            (uri (git-reference
+                  (url "https://github.com/nlohmann/json_test_data")
+                  (commit "v3.1.0")))
+            (sha256
+             (base32 "0nbirc428qx0lpi940p7y24fzdjbwl6xig3h5rdbihyymmdzhvbc"))
+            (file-name (git-file-name "vis-test" version))))))
+    (home-page "https://json.nlohmann.me/")
+    (synopsis "JSON for Modern C++")
+    (description "This package provides a JSON implementation with an
+intuitive syntax for C++, a single include header file, and with a
+codebase that has 100% code coverage.")
     (license license:expat)))
 
 (define-public xtl
-- 
2.39.1