From 295153fa648dfb2bc9ce36ac65d16bf42d2d66e1 Mon Sep 17 00:00:00 2001 From: chn Date: Fri, 23 Aug 2024 09:31:33 +0800 Subject: [PATCH] packages.ufo: fix build --- flake.lock | 7 ++-- flake.nix | 2 +- packages/biu/CMakeLists.txt | 4 ++ packages/biu/fmt.patch | 57 +++++++++++++++++++++++++++++ packages/biu/include/biu/common.hpp | 1 + packages/biu/include/biu/format.hpp | 30 +++++++-------- packages/biu/include/biu/format.tpp | 31 +++++++++------- packages/biu/test/format.cpp | 14 +++++++ packages/default.nix | 7 +++- 9 files changed, 117 insertions(+), 36 deletions(-) create mode 100644 packages/biu/fmt.patch create mode 100644 packages/biu/test/format.cpp diff --git a/flake.lock b/flake.lock index a7307417..e07e5600 100644 --- a/flake.lock +++ b/flake.lock @@ -1157,16 +1157,17 @@ "openxlsx": { "flake": false, "locked": { - "lastModified": 1722960074, - "narHash": "sha256-KaexHI/Bl3aChkt2glN2oRJREYqFSOAO0Qn6pPccSXw=", + "lastModified": 1716560554, + "narHash": "sha256-Aqn1830lG4g7BbwEeePhvGawLarmrIMnF2MXROTUBCw=", "owner": "troldal", "repo": "OpenXLSX", - "rev": "06425d541d09907799e93a4226691126bd60af5e", + "rev": "f85f7f1bd632094b5d78d4d1f575955fc3801886", "type": "github" }, "original": { "owner": "troldal", "repo": "OpenXLSX", + "rev": "f85f7f1bd632094b5d78d4d1f575955fc3801886", "type": "github" } }, diff --git a/flake.nix b/flake.nix index ffd4bdb2..f203a361 100644 --- a/flake.nix +++ b/flake.nix @@ -61,7 +61,7 @@ kylin-virtual-keyboard = { url = "git+https://gitee.com/openkylin/kylin-virtual-keyboard.git"; flake = false; }; cjktty = { url = "github:CHN-beta/cjktty-patches"; flake = false; }; zxorm = { url = "github:CHN-beta/zxorm"; flake = false; }; - openxlsx = { url = "github:troldal/OpenXLSX"; flake = false; }; + openxlsx = { url = "github:troldal/OpenXLSX?rev=f85f7f1bd632094b5d78d4d1f575955fc3801886"; flake = false; }; sqlite-orm = { url = "github:fnc12/sqlite_orm"; flake = false; }; sockpp = { url = "github:fpagliughi/sockpp"; flake = false; }; git-lfs-transfer = { url = "github:charmbracelet/git-lfs-transfer"; flake = false; }; diff --git a/packages/biu/CMakeLists.txt b/packages/biu/CMakeLists.txt index e5560a74..7fb6ddc0 100644 --- a/packages/biu/CMakeLists.txt +++ b/packages/biu/CMakeLists.txt @@ -53,3 +53,7 @@ add_executable(test-common test/common.cpp) target_link_libraries(test-common PRIVATE biu) set_property(TARGET test-common PROPERTY CXX_STANDARD 23 CXX_STANDARD_REQUIRED ON) add_test(NAME test-common COMMAND test-common) +add_executable(test-format test/format.cpp) +target_link_libraries(test-format PRIVATE biu) +set_property(TARGET test-format PROPERTY CXX_STANDARD 23 CXX_STANDARD_REQUIRED ON) +add_test(NAME test-format COMMAND test-format) diff --git a/packages/biu/fmt.patch b/packages/biu/fmt.patch new file mode 100644 index 00000000..10e2cca1 --- /dev/null +++ b/packages/biu/fmt.patch @@ -0,0 +1,57 @@ +diff --git a/include/fmt/std.h b/include/fmt/std.h +index 1e69b8b2..ae485344 100644 +--- a/include/fmt/std.h ++++ b/include/fmt/std.h +@@ -211,7 +211,7 @@ template + struct formatter : basic_ostream_formatter {}; + FMT_END_NAMESPACE + +-#ifdef __cpp_lib_optional ++#ifdef __cpp_lib_optional_ + FMT_BEGIN_NAMESPACE + FMT_EXPORT + template +diff --git a/test/std-test.cc b/test/std-test.cc +index bcc7bd5f..24981d87 100644 +--- a/test/std-test.cc ++++ b/test/std-test.cc +@@ -56,7 +56,7 @@ TEST(ranges_std_test, format_quote_path) { + std::vector{"path1/file1.txt", "path2/file2.txt"}; + EXPECT_EQ(fmt::format("{}", vec), + "[\"path1/file1.txt\", \"path2/file2.txt\"]"); +-# ifdef __cpp_lib_optional ++# ifdef __cpp_lib_optional_ + auto o = std::optional("path/file.txt"); + EXPECT_EQ(fmt::format("{}", o), "optional(\"path/file.txt\")"); + EXPECT_EQ(fmt::format("{:?}", o), "optional(\"path/file.txt\")"); +@@ -109,7 +109,7 @@ TEST(std_test, source_location) { + #endif + + TEST(std_test, optional) { +-#ifdef __cpp_lib_optional ++#ifdef __cpp_lib_optional_ + EXPECT_EQ(fmt::format("{}", std::optional{}), "none"); + EXPECT_EQ(fmt::format("{}", std::pair{1, "second"}), "(1, \"second\")"); + EXPECT_EQ(fmt::format("{}", std::vector{std::optional{1}, std::optional{2}, +@@ -184,7 +184,7 @@ class my_class { + }; + } // namespace my_nso + TEST(std_test, optional_format_as) { +-#ifdef __cpp_lib_optional ++#ifdef __cpp_lib_optional_ + EXPECT_EQ(fmt::format("{}", std::optional{}), "none"); + EXPECT_EQ(fmt::format("{}", std::optional{my_nso::my_number::one}), + "optional(\"first\")"); +diff --git a/test/xchar-test.cc b/test/xchar-test.cc +index 312e632b..6210e244 100644 +--- a/test/xchar-test.cc ++++ b/test/xchar-test.cc +@@ -590,7 +590,7 @@ TEST(std_test_xchar, complex) { + } + + TEST(std_test_xchar, optional) { +-# ifdef __cpp_lib_optional ++# ifdef __cpp_lib_optional_ + EXPECT_EQ(fmt::format(L"{}", std::optional{L'C'}), L"optional(\'C\')"); + EXPECT_EQ(fmt::format(L"{}", std::optional{std::wstring{L"wide string"}}), + L"optional(\"wide string\")"); diff --git a/packages/biu/include/biu/common.hpp b/packages/biu/include/biu/common.hpp index 63df04a6..b9822184 100644 --- a/packages/biu/include/biu/common.hpp +++ b/packages/biu/include/biu/common.hpp @@ -3,6 +3,7 @@ # include # include # include +# include # include # include diff --git a/packages/biu/include/biu/format.hpp b/packages/biu/include/biu/format.hpp index 48e6d941..17b89fd2 100644 --- a/packages/biu/include/biu/format.hpp +++ b/packages/biu/include/biu/format.hpp @@ -1,16 +1,12 @@ # pragma once # include +# include # include -# include # include # include namespace biu { - namespace concepts - { template concept Formattable = fmt::is_formattable::value; } - using concepts::Formattable; - namespace detail_ { template struct FormatLiteralHelper : protected BasicStaticString @@ -32,14 +28,14 @@ namespace biu template requires requires() {typename Wrap::element_type;} struct UnderlyingTypeOfOptionalWrap {using Type = std::remove_cvref_t;}; - template struct FormatterReuseProxy + template struct FormatterReuseProxy { - constexpr auto parse(fmt::format_parse_context& ctx) - -> std::invoke_result_t; + constexpr auto parse(fmt::basic_format_parse_context& ctx) + -> typename fmt::basic_format_parse_context::iterator; }; - template + template requires (!SpecializationOf && std::default_initializable>) - struct FormatterReuseProxy : fmt::formatter {}; + struct FormatterReuseProxy : fmt::formatter {}; } inline namespace stream_operators { @@ -51,19 +47,19 @@ namespace biu namespace fmt { template struct formatter - : biu::detail_::FormatterReuseProxy::Type> + : biu::detail_::FormatterReuseProxy::Type, Char> { - template auto format(const Wrap& wrap, FormatContext& ctx) - -> std::invoke_result_t; + template auto format(const Wrap& wrap, FormatContext& ctx) const + -> typename FormatContext::iterator; }; template struct formatter { bool full = false; - constexpr auto parse(fmt::format_parse_context& ctx) - -> std::invoke_result_t; - template auto format(const T& value, FormatContext& ctx) - -> std::invoke_result_t; + constexpr auto parse(fmt::basic_format_parse_context& ctx) + -> typename fmt::basic_format_parse_context::iterator; + template auto format(const T& value, FormatContext& ctx) const + -> typename FormatContext::iterator; }; template struct formatter, Char> diff --git a/packages/biu/include/biu/format.tpp b/packages/biu/include/biu/format.tpp index bb8b25a0..86acbefd 100644 --- a/packages/biu/include/biu/format.tpp +++ b/packages/biu/include/biu/format.tpp @@ -1,9 +1,11 @@ # pragma once -# include -# include # include # include # include +# include +# include +# include +# include namespace biu { @@ -14,9 +16,9 @@ namespace biu detail_::FormatLiteralHelper literals::operator""_f() { return {}; } - template constexpr - auto detail_::FormatterReuseProxy::parse(fmt::format_parse_context& ctx) - -> std::invoke_result_t + template constexpr + auto detail_::FormatterReuseProxy::parse(fmt::basic_format_parse_context& ctx) + -> typename fmt::basic_format_parse_context::iterator { if (ctx.begin() != ctx.end() && *ctx.begin() != '}') throw fmt::format_error @@ -35,7 +37,8 @@ namespace biu { if (holds_alternative(value)) { - if constexpr (biu::Formattable) os << "({}: {})"_f(nameof::nameof_full_type(), get(value)); + if constexpr (fmt::is_formattable::value) + os << "({}: {})"_f(nameof::nameof_full_type(), get(value)); else os << "({}: {})"_f(nameof::nameof_full_type(), "non-null unformattable value"); } }; @@ -47,15 +50,16 @@ namespace biu namespace fmt { template template - auto formatter::format(const Wrap& wrap, FormatContext& ctx) - -> std::invoke_result_t + auto formatter::format(const Wrap& wrap, FormatContext& ctx) const + -> typename FormatContext::iterator { using value_t = biu::detail_::UnderlyingTypeOfOptionalWrap::Type; auto format_value_type = [&, this](const value_t& value) { - if constexpr (!biu::Formattable) return fmt::format_to(ctx.out(), "non-null unformattable value"); + if constexpr (!fmt::is_formattable::value) + return fmt::format_to(ctx.out(), "non-null unformattable value"); else if constexpr (std::default_initializable>) - biu::detail_::FormatterReuseProxy::format(value, ctx); + biu::detail_::FormatterReuseProxy::format(value, ctx); else fmt::format_to(ctx.out(), "{}", value); }; fmt::format_to(ctx.out(), "("); @@ -75,8 +79,8 @@ namespace fmt return fmt::format_to(ctx.out(), ")"); } - template constexpr auto formatter::parse(format_parse_context& ctx) - -> std::invoke_result_t + template constexpr auto formatter::parse + (fmt::basic_format_parse_context& ctx) -> typename fmt::basic_format_parse_context::iterator { auto it = ctx.begin(); if (it != ctx.end() && *it == 'f') { full = true; it++; } @@ -85,8 +89,7 @@ namespace fmt } template template - auto formatter::format(const T& value, FormatContext& ctx) - -> std::invoke_result_t + auto formatter::format(const T& value, FormatContext& ctx) const -> typename FormatContext::iterator { if (full) return fmt::format_to(ctx.out(), "{}::{}", nameof::nameof_type(), nameof::nameof_enum(value)); else return fmt::format_to(ctx.out(), "{}", nameof::nameof_enum(value)); diff --git a/packages/biu/test/format.cpp b/packages/biu/test/format.cpp new file mode 100644 index 00000000..915acbc4 --- /dev/null +++ b/packages/biu/test/format.cpp @@ -0,0 +1,14 @@ +# include + +int main() +{ + using namespace biu::literals; + + std::optional a = 3; + using b = biu::detail_::UnderlyingTypeOfOptionalWrap::Type; + std::cout << "{}\n"_f(nameof::nameof_full_type()); + std::cout << "{}\n"_f(biu::concepts::CompletedType>); + std::cout << "{}\n"_f(biu::concepts::CompletedType, char>>); + std::cout << "{}\n"_f(fmt::is_formattable::value); + std::cout << "{}\n"_f(a); +} diff --git a/packages/default.nix b/packages/default.nix index f2545052..b285db2e 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -58,7 +58,12 @@ inputs: rec mumax = inputs.pkgs.callPackage ./mumax.nix { src = inputs.topInputs.mumax; }; kylin-virtual-keyboard = inputs.pkgs.libsForQt5.callPackage ./kylin-virtual-keyboard.nix { src = inputs.topInputs.kylin-virtual-keyboard; }; - biu = inputs.pkgs.callPackage ./biu { inherit nameof zpp-bits; stdenv = inputs.pkgs.gcc14Stdenv; }; + biu = inputs.pkgs.callPackage ./biu + { + inherit nameof zpp-bits; + stdenv = inputs.pkgs.gcc14Stdenv; + fmt = inputs.pkgs.fmt_11.overrideAttrs (prev: { patches = prev.patches or [] ++ [ ./biu/fmt.patch ]; }); + }; zxorm = inputs.pkgs.callPackage ./zxorm.nix { src = inputs.topInputs.zxorm; }; hpcstat = inputs.pkgs.callPackage ./hpcstat { inherit sqlite-orm date biu openxlsx; stdenv = inputs.pkgs.gcc14Stdenv; };