diff options
| author | bdunahu <bdunahu@operationnull.com> | 2026-04-23 19:54:32 -0400 |
|---|---|---|
| committer | Liliana Marie Prikler <liliana.prikler@gmail.com> | 2026-05-29 20:40:42 +0200 |
| commit | 0853a1671f74f9869ca6c75d6086092354783a99 (patch) | |
| tree | 51c1b4c82f60da9f47e1d6a97d78af268f1c7286 /gnu | |
| parent | 54d29defe0979636abe06e712d1adabb1d17f795 (diff) | |
gnu: Add nlohmann-json-no-char8-t.
* gnu/packages/patches/nlohmann_json_fix_char8_t.patch: New file.
* gnu/local.mk: (dist_patch_DATA): Register it.
* gnu/packages/cpp.scm (nlohmann-json-no-char8-t): New variable.
Change-Id: I8b47d345cd82718d1a2bd40009c480aca7c2c5b3
Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/local.mk | 1 | ||||
| -rw-r--r-- | gnu/packages/cpp.scm | 43 | ||||
| -rw-r--r-- | gnu/packages/patches/nlohmann_json_fix_char8_t.patch | 141 |
3 files changed, 185 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk index e48b5bf29c0..289d8461cd9 100644 --- a/gnu/local.mk +++ b/gnu/local.mk | |||
| @@ -1993,6 +1993,7 @@ dist_patch_DATA = \ | |||
| 1993 | %D%/packages/patches/nhc98-c-update.patch \ | 1993 | %D%/packages/patches/nhc98-c-update.patch \ |
| 1994 | %D%/packages/patches/nheko-0-12-1-fix-rendering-replies.patch \ | 1994 | %D%/packages/patches/nheko-0-12-1-fix-rendering-replies.patch \ |
| 1995 | %D%/packages/patches/nix-dont-build-html-doc.diff \ | 1995 | %D%/packages/patches/nix-dont-build-html-doc.diff \ |
| 1996 | %D%/packages/patches/nlohmann_json_fix_char8_t.patch \ | ||
| 1996 | %D%/packages/patches/nfs4-acl-tools-0.3.7-fixpaths.patch \ | 1997 | %D%/packages/patches/nfs4-acl-tools-0.3.7-fixpaths.patch \ |
| 1997 | %D%/packages/patches/neovim-tree-sitter-grammar-path.patch \ | 1998 | %D%/packages/patches/neovim-tree-sitter-grammar-path.patch \ |
| 1998 | %D%/packages/patches/network-manager-plugin-ownership.patch \ | 1999 | %D%/packages/patches/network-manager-plugin-ownership.patch \ |
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm index 40d16fc5dc7..d2a86bfc97a 100644 --- a/gnu/packages/cpp.scm +++ b/gnu/packages/cpp.scm | |||
| @@ -1434,6 +1434,9 @@ data transfer object.") | |||
| 1434 | (define-public nlohmann-json | 1434 | (define-public nlohmann-json |
| 1435 | (package | 1435 | (package |
| 1436 | (name "nlohmann-json") | 1436 | (name "nlohmann-json") |
| 1437 | ;; XXX: Merge related package `nlohmann-json-no-char8-t' back into here when | ||
| 1438 | ;; updating from 3.12.0, as the unique patch it applies will already be | ||
| 1439 | ;; incorporated in. | ||
| 1437 | (version "3.12.0") | 1440 | (version "3.12.0") |
| 1438 | (home-page "https://github.com/nlohmann/json") | 1441 | (home-page "https://github.com/nlohmann/json") |
| 1439 | (source | 1442 | (source |
| @@ -1507,6 +1510,46 @@ intuitive syntax and trivial integration.") | |||
| 1507 | (define-deprecated-package json-modern-cxx | 1510 | (define-deprecated-package json-modern-cxx |
| 1508 | nlohmann-json) | 1511 | nlohmann-json) |
| 1509 | 1512 | ||
| 1513 | (define-public nlohmann-json-no-char8-t | ||
| 1514 | (package | ||
| 1515 | ;; XXX: Version 3.12.0 does not work without char8_t support. | ||
| 1516 | ;; OpenRCT2 compiles with -fno-char8_t, and thus requires this patch. | ||
| 1517 | ;; See https://github.com/nlohmann/json/pull/4736 | ||
| 1518 | (inherit nlohmann-json) | ||
| 1519 | (name "nlohmann-json-no-char8-t") | ||
| 1520 | (version "3.12.0") | ||
| 1521 | (source | ||
| 1522 | (origin | ||
| 1523 | (method git-fetch) | ||
| 1524 | (uri (git-reference (url "https://github.com/nlohmann/json") | ||
| 1525 | (commit (string-append "v" version)))) | ||
| 1526 | (sha256 | ||
| 1527 | (base32 "09nqq56ighr3lghhn3fs399lkllghz717j0xyp87x0giw86ayh3h")) | ||
| 1528 | (file-name (git-file-name name version)) | ||
| 1529 | (modules '((guix build utils))) | ||
| 1530 | (snippet | ||
| 1531 | #~(begin | ||
| 1532 | ;; Delete bundled software. Preserve doctest_compatibility.h, which | ||
| 1533 | ;; is a wrapper library added by this package. | ||
| 1534 | (install-file "./tests/thirdparty/doctest/doctest_compatibility.h" | ||
| 1535 | "/tmp") | ||
| 1536 | (delete-file-recursively "./tests/thirdparty") | ||
| 1537 | (install-file "/tmp/doctest_compatibility.h" | ||
| 1538 | "./tests/thirdparty/doctest") | ||
| 1539 | |||
| 1540 | ;; Adjust for the unbundled fifo_map and doctest. | ||
| 1541 | (substitute* (find-files "./tests/" "\\.h(pp)?") | ||
| 1542 | (("#include \"doctest\\.h\"") "#include <doctest/doctest.h>") | ||
| 1543 | (("#include <doctest\\.h>") "#include <doctest/doctest.h>")) | ||
| 1544 | (with-directory-excursion "tests/src" | ||
| 1545 | (let ((files (find-files "." "\\.cpp$"))) | ||
| 1546 | (substitute* files | ||
| 1547 | (("#include ?\"(fifo_map.hpp)\"" all fifo-map-hpp) | ||
| 1548 | (string-append | ||
| 1549 | "#include <fifo_map/" fifo-map-hpp ">"))))))) | ||
| 1550 | (patches | ||
| 1551 | (search-patches "nlohmann_json_fix_char8_t.patch")))))) | ||
| 1552 | |||
| 1510 | (define-public jthread | 1553 | (define-public jthread |
| 1511 | (let ((commit "0fa8d394254886c555d6faccd0a3de819b7d47f8") | 1554 | (let ((commit "0fa8d394254886c555d6faccd0a3de819b7d47f8") |
| 1512 | (revision "0")) | 1555 | (revision "0")) |
diff --git a/gnu/packages/patches/nlohmann_json_fix_char8_t.patch b/gnu/packages/patches/nlohmann_json_fix_char8_t.patch new file mode 100644 index 00000000000..014a328dfe9 --- /dev/null +++ b/gnu/packages/patches/nlohmann_json_fix_char8_t.patch | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | From 756ca22ec5b0d89b5d107b4c30891d1293650c87 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Sergiu Deitsch <sergiud@users.noreply.github.com> | ||
| 3 | Date: Wed, 23 Apr 2025 18:36:41 +0200 | ||
| 4 | Subject: [PATCH] Provide fallback for missing `char8_t` support (#4736) | ||
| 5 | |||
| 6 | --- | ||
| 7 | .../nlohmann/detail/conversions/from_json.hpp | 5 +++- | ||
| 8 | .../nlohmann/detail/conversions/to_json.hpp | 21 ++++++++++----- | ||
| 9 | single_include/nlohmann/json.hpp | 26 +++++++++++++------ | ||
| 10 | tests/src/unit-deserialization.cpp | 5 ++-- | ||
| 11 | 4 files changed, 39 insertions(+), 18 deletions(-) | ||
| 12 | |||
| 13 | diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp | ||
| 14 | index 797f714dfae1dcc7fd8d2435ae7015023da76b97..3a24a6f4d26c0162531d8100a99a05291d8a2090 100644 | ||
| 15 | --- a/include/nlohmann/detail/conversions/from_json.hpp | ||
| 16 | +++ b/include/nlohmann/detail/conversions/from_json.hpp | ||
| 17 | @@ -539,7 +539,10 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p) | ||
| 18 | JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); | ||
| 19 | } | ||
| 20 | const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); | ||
| 21 | -#ifdef JSON_HAS_CPP_20 | ||
| 22 | + // Checking for C++20 standard or later can be insufficient in case the | ||
| 23 | + // library support for char8_t is either incomplete or was disabled | ||
| 24 | + // altogether. Use the __cpp_lib_char8_t feature test instead. | ||
| 25 | +#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L) | ||
| 26 | p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size())); | ||
| 27 | #else | ||
| 28 | p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20 | ||
| 29 | diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp | ||
| 30 | index f8413850d5d7f8dd4bd6d2f174959a8ddd5c233a..8b910dd1615b710308392eed4999d3b7533a26e7 100644 | ||
| 31 | --- a/include/nlohmann/detail/conversions/to_json.hpp | ||
| 32 | +++ b/include/nlohmann/detail/conversions/to_json.hpp | ||
| 33 | @@ -15,7 +15,8 @@ | ||
| 34 | |||
| 35 | #include <algorithm> // copy | ||
| 36 | #include <iterator> // begin, end | ||
| 37 | -#include <string> // string | ||
| 38 | +#include <memory> // allocator_traits | ||
| 39 | +#include <string> // basic_string, char_traits | ||
| 40 | #include <tuple> // tuple, get | ||
| 41 | #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type | ||
| 42 | #include <utility> // move, forward, declval, pair | ||
| 43 | @@ -440,15 +441,21 @@ inline void to_json(BasicJsonType& j, const T& t) | ||
| 44 | } | ||
| 45 | |||
| 46 | #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM | ||
| 47 | +#if defined(__cpp_lib_char8_t) | ||
| 48 | +template<typename BasicJsonType, typename Tr, typename Allocator> | ||
| 49 | +inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s) | ||
| 50 | +{ | ||
| 51 | + using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>; | ||
| 52 | + j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator()); | ||
| 53 | +} | ||
| 54 | +#endif | ||
| 55 | + | ||
| 56 | template<typename BasicJsonType> | ||
| 57 | inline void to_json(BasicJsonType& j, const std_fs::path& p) | ||
| 58 | { | ||
| 59 | -#ifdef JSON_HAS_CPP_20 | ||
| 60 | - const std::u8string s = p.u8string(); | ||
| 61 | - j = std::string(s.begin(), s.end()); | ||
| 62 | -#else | ||
| 63 | - j = p.u8string(); // returns std::string in C++17 | ||
| 64 | -#endif | ||
| 65 | + // Returns either a std::string or a std::u8string depending whether library | ||
| 66 | + // support for char8_t is enabled. | ||
| 67 | + j = p.u8string(); | ||
| 68 | } | ||
| 69 | #endif | ||
| 70 | |||
| 71 | diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp | ||
| 72 | index 13b07c0fbc87e5c24127922fb2ef45fc3ea2bff5..93e5983cf1b1cdbe0452d89dcfa487c7b18dd4df 100644 | ||
| 73 | --- a/single_include/nlohmann/json.hpp | ||
| 74 | +++ b/single_include/nlohmann/json.hpp | ||
| 75 | @@ -5324,7 +5324,10 @@ inline void from_json(const BasicJsonType& j, std_fs::path& p) | ||
| 76 | JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j)); | ||
| 77 | } | ||
| 78 | const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>(); | ||
| 79 | -#ifdef JSON_HAS_CPP_20 | ||
| 80 | + // Checking for C++20 standard or later can be insufficient in case the | ||
| 81 | + // library support for char8_t is either incomplete or was disabled | ||
| 82 | + // altogether. Use the __cpp_lib_char8_t feature test instead. | ||
| 83 | +#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L) | ||
| 84 | p = std_fs::path(std::u8string_view(reinterpret_cast<const char8_t*>(s.data()), s.size())); | ||
| 85 | #else | ||
| 86 | p = std_fs::u8path(s); // accepts UTF-8 encoded std::string in C++17, deprecated in C++20 | ||
| 87 | @@ -5379,7 +5382,8 @@ NLOHMANN_JSON_NAMESPACE_END | ||
| 88 | |||
| 89 | #include <algorithm> // copy | ||
| 90 | #include <iterator> // begin, end | ||
| 91 | -#include <string> // string | ||
| 92 | +#include <memory> // allocator_traits | ||
| 93 | +#include <string> // basic_string, char_traits | ||
| 94 | #include <tuple> // tuple, get | ||
| 95 | #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type | ||
| 96 | #include <utility> // move, forward, declval, pair | ||
| 97 | @@ -6086,15 +6090,21 @@ inline void to_json(BasicJsonType& j, const T& t) | ||
| 98 | } | ||
| 99 | |||
| 100 | #if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM | ||
| 101 | +#if defined(__cpp_lib_char8_t) | ||
| 102 | +template<typename BasicJsonType, typename Tr, typename Allocator> | ||
| 103 | +inline void to_json(BasicJsonType& j, const std::basic_string<char8_t, Tr, Allocator>& s) | ||
| 104 | +{ | ||
| 105 | + using OtherAllocator = typename std::allocator_traits<Allocator>::template rebind_alloc<char>; | ||
| 106 | + j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator()); | ||
| 107 | +} | ||
| 108 | +#endif | ||
| 109 | + | ||
| 110 | template<typename BasicJsonType> | ||
| 111 | inline void to_json(BasicJsonType& j, const std_fs::path& p) | ||
| 112 | { | ||
| 113 | -#ifdef JSON_HAS_CPP_20 | ||
| 114 | - const std::u8string s = p.u8string(); | ||
| 115 | - j = std::string(s.begin(), s.end()); | ||
| 116 | -#else | ||
| 117 | - j = p.u8string(); // returns std::string in C++17 | ||
| 118 | -#endif | ||
| 119 | + // Returns either a std::string or a std::u8string depending whether library | ||
| 120 | + // support for char8_t is enabled. | ||
| 121 | + j = p.u8string(); | ||
| 122 | } | ||
| 123 | #endif | ||
| 124 | |||
| 125 | diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp | ||
| 126 | index 84a970a183e4392166a8fe9bf76b582a53b76dd5..5c450c23d3042991cfc8959d4632208cfb21f400 100644 | ||
| 127 | --- a/tests/src/unit-deserialization.cpp | ||
| 128 | +++ b/tests/src/unit-deserialization.cpp | ||
| 129 | @@ -1134,9 +1134,10 @@ TEST_CASE("deserialization") | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | -// select the types to test - char8_t is only available in C++20 | ||
| 134 | +// select the types to test - char8_t is only available since C++20 if and only | ||
| 135 | +// if __cpp_char8_t is defined. | ||
| 136 | #define TYPE_LIST(...) __VA_ARGS__ | ||
| 137 | -#ifdef JSON_HAS_CPP_20 | ||
| 138 | +#if defined(__cpp_char8_t) && (__cpp_char8_t >= 201811L) | ||
| 139 | #define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t) | ||
| 140 | #else | ||
| 141 | #define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t) | ||
