Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade using fmt library up to latest version #3

Open
Saigut opened this issue Jul 16, 2021 · 9 comments
Open

Upgrade using fmt library up to latest version #3

Saigut opened this issue Jul 16, 2021 · 9 comments

Comments

@Saigut
Copy link

Saigut commented Jul 16, 2021

I tried fmt 3.0.0, 3.0.2, and 8.0.1, all failed to compiled.

@Saigut Saigut changed the title Which version of fmt this project denpend? Which version of fmt this project denpend on? Jul 16, 2021
@saurik
Copy link

saurik commented Mar 8, 2022

soralog requires a version of fmt before fmtlib/fmt@841aad9, which removed the fmt_internal::data::reset_color that soralog is awkwardly relying on in sink_to_console.cpp; using git describe --tags, I think that means 7.1.3 is OK (if you want a release)?

const auto &style = fmt_internal::data::reset_color;

However, I'll also note that fmt broke on iOS between fmtlib/fmt@15c10b0 and fmtlib/fmt@69bdc20 due to fmtlib/fmt#2248 (which I had actually filed), and so I actually use fmtlib/fmt@308510e for soralog (which is depressing, as it is now a year old).

@Saigut
Copy link
Author

Saigut commented Mar 9, 2022

I am using fmt-7.1.2, which works well. And I have not tried 7.1.3.

@xDimon
Copy link
Owner

xDimon commented Mar 10, 2022

Sorry for delay.
Now fmt version 6.1.2 is used. It is default version in current using hunter package manager.
You might try to use other version by modifying Hunter/config.cmake. It will override default version from hunter.

hunter_config(
    fmt
    URL https://github.com/..../archive.tar.gz
    SHA1 hash-of-provided-archive
)

@saurik
Copy link

saurik commented Mar 10, 2022

@xDimon FWIW, if you stop using that one variable from fmt_internal (which I would imagine projects aren't "supposed" to be using at all) we can all upgrade to the latest version of fmt. (I am definitely not building with Hunter, btw: it seems to be riddled with ancient versions of packages? I always do a build system bypass of imported libraries so I can correctly manage all the dependencies and do what I can to force them to master. I might try adding a hack to just disable color or whatever soralog is needing this for so I can make sure to be on the latest fmt code.)

@xDimon
Copy link
Owner

xDimon commented Mar 10, 2022

Any hacks is bad way. I'll try to switch to last version of fmt (8.1.1) for next version soralog.

@xDimon xDimon changed the title Which version of fmt this project denpend on? Upgrade using fmt library up to latest version Mar 10, 2022
@xDimon
Copy link
Owner

xDimon commented Mar 10, 2022

Oh, it was really easy. =)
@Saigut @saurik, look at soralog v0.1.1. I hope it is so what you needed.

@Saigut
Copy link
Author

Saigut commented Mar 11, 2022

@xDimon That looks good :)
In fact I don't care if fmt is the newest version. The real problem for me is that I don't know the dependencies of soralog.
I am not using Hunter package manager in my own project. I have trouble to look out what version packages soralog is depending on when I first time look at soralog.

@saurik
Copy link

saurik commented Mar 12, 2022

@xDimon Thanks!! This did, in fact, allow me to upgrade to a much newer version of fmt :D.

That said, I'm now ("still"? I feel like I didn't have this before, though? I'm confused a bit ;P) running into two issues preventing me from fully upgrading fmt, but I don't know if these issues are in soralog itself or are in the library that I'm compiling (cpp-libp2p) which is using soralog. Maybe you'd be willing to comment? (I'd appreciate if you don't want to, but the reason I ask is because the code using soralog naively looks reasonable to me and the issues both happen on the "other side" of soralog and seem to be fixable in soralog.)


  1. In fmtlib/fmt@4b8bda2 from Aug 23 2021, fmt replaced a const reference with a forwarding reference in the definition of forward_to_n, supposedly as a fix for Should format_to_n has the same detection as format and format_to? fmtlib/fmt#2462; and then in cpp-libp2p, there is a use of SL_DEBUG that is triggering a static_assert in fmt "detail::count() == 0" "passing views as lvalues is disallowed" when soralog attempts to call fmt::v8::basic_format_string.

https://github.com/libp2p/cpp-libp2p/blob/890b53dd73452a555a5c7feaa9f73c5bdca1a9af/src/protocol_muxer/multiselect/multiselect_instance.cpp#L347-L348

      SL_DEBUG(log(), "Failed to negotiate protocols: {}",
               fmt::join(protocols_.begin(), protocols_.end(), ", "));
In file included from cpp-libp2p/src/protocol_muxer/multiselect/multiselect_instance.cpp:11:
In file included from ./cpp-libp2p/include/libp2p/common/trace.hpp:9:
In file included from ./cpp-libp2p/include/libp2p/log/logger.hpp:10:
In file included from ./soralog/include/soralog/logger.hpp:13:
In file included from ./soralog/include/soralog/sink.hpp:14:
In file included from ./soralog/include/soralog/event.hpp:14:
In file included from ./p2p/fmt/include/fmt/format.h:49:
./p2p/fmt/include/fmt/core.h:3067:5: error: static_assert failed due to requirement 'detail::count() == 0' "passing views as lvalues is disallowed"
    static_assert(
    ^
./soralog/include/soralog/event.hpp:62:65: note: in instantiation of function template specialization 'fmt::v8::basic_format_string<char, const fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char> &>::basic_format_string<FMT_COMPILE_STRING, 0>' requested here
            fmt::format_to_n(message_data_, max_message_length, format, args...)
                                                                ^
./soralog/include/soralog/circular_buffer.hpp:41:28: note: in instantiation of function template specialization 'soralog::Event::Event<soralog::Sink::ThreadInfoType, FMT_COMPILE_STRING, fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char>>' requested here
        new (data_.data()) T(args...);
                           ^
./soralog/include/soralog/circular_buffer.hpp:161:21: note: in instantiation of function template specialization 'soralog::CircularBuffer<soralog::Event>::Node::Node<std::__1::basic_string_view<char, std::__1::char_traits<char>>, soralog::Sink::ThreadInfoType, soralog::Level, FMT_COMPILE_STRING, unsigned long, fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char>>' requested here
        new (&node) Node(args...);
                    ^
./soralog/include/soralog/sink.hpp:88:31: note: in instantiation of function template specialization 'soralog::CircularBuffer<soralog::Event>::put<std::__1::basic_string_view<char, std::__1::char_traits<char>>, soralog::Sink::ThreadInfoType, soralog::Level, FMT_COMPILE_STRING, unsigned long, fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char>>' requested here
          auto node = events_.put(name, thread_info_type_, level, format,
                              ^
./soralog/include/soralog/logger.hpp:44:16: note: in instantiation of function template specialization 'soralog::Sink::push<FMT_COMPILE_STRING, fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char>>' requested here
        sink_->push(name_, level, format, args...);
               ^
./soralog/include/soralog/logger.hpp:65:7: note: in instantiation of function template specialization 'soralog::Logger::push<FMT_COMPILE_STRING, fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char>>' requested here
      push(level, std::forward<Format>(format), args...);
      ^
./soralog/include/soralog/macro.hpp:30:12: note: in instantiation of function template specialization 'soralog::Logger::log<FMT_COMPILE_STRING, fmt::v8::join_view<boost::container::vec_iterator<std::__1::basic_string<char> *, false>, boost::container::vec_iterator<std::__1::basic_string<char> *, false>, char>>' requested here
      log->log(level, std::forward<Format>(fmt), std::move(args)()...);
           ^
cpp-libp2p/src/protocol_muxer/multiselect/multiselect_instance.cpp:347:7: note: in instantiation of function template specialization 'soralog::macro::proxy<soralog::Logger, FMT_COMPILE_STRING, (lambda at cpp-libp2p/src/protocol_muxer/multiselect/multiselect_instance.cpp:347:7)>' requested here
      SL_DEBUG(log(), "Failed to negotiate protocols: {}",
      ^
./soralog/include/soralog/macro.hpp:122:3: note: expanded from macro 'SL_DEBUG'
  _SL_LOG((LOG), soralog::Level::DEBUG, (FMT), ##__VA_ARGS__, Z)
  ^
./soralog/include/soralog/macro.hpp:75:19: note: expanded from macro '_SL_LOG'
  soralog::macro::proxy(            \
                  ^
1 error generated.

I actually managed to "fix" this one by going through the entire stack of functions on the failed call stack and replacing every const Args &...args with Args &&...args and then using std::forward<Args>(args)... instead of args... or (in the one place) std::move(args)... (check saurik@0e2abb9 to see what I did), but one function--in soralog::Sink::push--uses its arguments multiple times (which means that I would think I can't safely forward r-values through it, as they might end up getting used after they are moved).

while (true) {
auto node = events_.put(name, thread_info_type_, level, format,
max_message_length_, args...);

for (const auto &sink : underlying_sinks_) {
sink->push(name, level, format, args...);


  1. In fmtlib/fmt@f055ebb from Feb 4 2022, fmt made some "ostream operators opt in to reduce the risk of ODR violations", whcih is now causing a static_assert on "formattable" "Cannot format an argument. To make type T formattable provide a formatter specialization: https://fmt.dev/latest/api.html#udt" while trying to format an std::error_code. This is fixable if I #define FMT_DEPRECATED_OSTREAM, but I don't know if this needs to be done by cpp-libp2p or soralog.

https://github.com/libp2p/cpp-libp2p/blob/890b53dd73452a555a5c7feaa9f73c5bdca1a9af/src/protocol/identify/identify_msg_processor.cpp#L144-L145

      log_->error("cannot read an identify message from peer {}, {}: {}",
                  peer_id_str, peer_addr_str, msg_res.error());
In file included from cpp-libp2p/src/protocol/identify/identify_msg_processor.cpp:6:
In file included from ./cpp-libp2p/include/libp2p/protocol/identify/identify_msg_processor.hpp:16:
In file included from ./cpp-libp2p/include/libp2p/host/host.hpp:14:
In file included from ./cpp-libp2p/include/libp2p/event/bus.hpp:17:
In file included from ./cpp-libp2p/include/libp2p/log/logger.hpp:10:
In file included from ./soralog/include/soralog/logger.hpp:13:
In file included from ./soralog/include/soralog/sink.hpp:14:
In file included from ./soralog/include/soralog/event.hpp:14:
In file included from ./p2p/fmt/include/fmt/format.h:49:
./p2p/fmt/include/fmt/core.h:1711:3: error: static_assert failed due to requirement 'formattable' "Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt"
  static_assert(
  ^
./p2p/fmt/include/fmt/core.h:1837:23: note: in instantiation of function template specialization 'fmt::v8::detail::make_arg<true, fmt::v8::basic_format_context<fmt::v8::appender, char>, fmt::v8::detail::type::custom_type, const std::__1::error_code &, 0>' requested here
        data_{detail::make_arg<
                      ^
./p2p/fmt/include/fmt/core.h:1856:10: note: in instantiation of function template specialization 'fmt::v8::format_arg_store<fmt::v8::basic_format_context<fmt::v8::appender, char>, std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>::format_arg_store<const std::__1::basic_string<char> &, const std::__1::basic_string<char> &, const std::__1::error_code &>' requested here
  return {std::forward<Args>(args)...};
         ^
./p2p/fmt/include/fmt/core.h:3189:41: note: in instantiation of function template specialization 'fmt::v8::make_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char>, const std::__1::basic_string<char> &, const std::__1::basic_string<char> &, const std::__1::error_code &>' requested here
  return vformat_to_n(out, n, fmt, fmt::make_format_args(args...));
                                        ^
./soralog/include/soralog/event.hpp:62:18: note: in instantiation of function template specialization 'fmt::v8::format_to_n<char *, const std::__1::basic_string<char> &, const std::__1::basic_string<char> &, const std::__1::error_code &, 0>' requested here
            fmt::format_to_n(message_data_, max_message_length, format, args...)
                 ^
./soralog/include/soralog/circular_buffer.hpp:41:28: note: in instantiation of function template specialization 'soralog::Event::Event<soralog::Sink::ThreadInfoType, std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>' requested here
        new (data_.data()) T(args...);
                           ^
./soralog/include/soralog/circular_buffer.hpp:161:21: note: in instantiation of function template specialization 'soralog::CircularBuffer<soralog::Event>::Node::Node<std::__1::basic_string_view<char, std::__1::char_traits<char>>, soralog::Sink::ThreadInfoType, soralog::Level, std::__1::basic_string_view<char, std::__1::char_traits<char>>, unsigned long, std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>' requested here
        new (&node) Node(args...);
                    ^
./soralog/include/soralog/sink.hpp:88:31: note: in instantiation of function template specialization 'soralog::CircularBuffer<soralog::Event>::put<std::__1::basic_string_view<char, std::__1::char_traits<char>>, soralog::Sink::ThreadInfoType, soralog::Level, std::__1::basic_string_view<char, std::__1::char_traits<char>>, unsigned long, std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>' requested here
          auto node = events_.put(name, thread_info_type_, level, format,
                              ^
./soralog/include/soralog/logger.hpp:44:16: note: in instantiation of function template specialization 'soralog::Sink::push<std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>' requested here
        sink_->push(name_, level, format, args...);
               ^
./soralog/include/soralog/logger.hpp:153:7: note: in instantiation of function template specialization 'soralog::Logger::push<std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>' requested here
      push(Level::ERROR, format, args...);
      ^
cpp-libp2p/src/protocol/identify/identify_msg_processor.cpp:144:13: note: in instantiation of function template specialization 'soralog::Logger::error<std::__1::basic_string<char>, std::__1::basic_string<char>, std::__1::error_code>' requested here
      log_->error("cannot read an identify message from peer {}, {}: {}",
            ^
1 error generated.

@saurik
Copy link

saurik commented Jun 29, 2022

I am now running into another issue with newer versions of soralog (with libp2p). :/

In file included from cpp-libp2p/src/basic/scheduler/asio_scheduler_backend.cpp:8:
In file included from ./cpp-libp2p/include/libp2p/log/logger.hpp:10:
In file included from ./soralog/include/soralog/logger.hpp:13:
In file included from ./soralog/include/soralog/sink.hpp:14:
./soralog/include/soralog/event.hpp:62:65: error: call to consteval function 'fmt::basic_format_string<char, const std::basic_string<char> &>::basic_format_string<std::basic_string_view<char>, 0>' is not a constant expression
            fmt::format_to_n(message_data_, max_message_length, format, args...)
                                                                ^
./soralog/include/soralog/circular_buffer.hpp:41:28: note: in instantiation of function template specialization 'soralog::Event::Event<soralog::Sink::ThreadInfoType, std::basic_string_view<char>, std::basic_string<char>>' requested here
        new (data_.data()) T(args...);
                           ^
./soralog/include/soralog/circular_buffer.hpp:161:21: note: in instantiation of function template specialization 'soralog::CircularBuffer<soralog::Event>::Node::Node<std::basic_string_view<char>, soralog::Sink::ThreadInfoType, soralog::Level, std::basic_string_view<char>, unsigned long, std::basic_string<char>>' requested here
        new (&node) Node(args...);
                    ^
./soralog/include/soralog/sink.hpp:88:31: note: in instantiation of function template specialization 'soralog::CircularBuffer<soralog::Event>::put<std::basic_string_view<char>, soralog::Sink::ThreadInfoType, soralog::Level, std::basic_string_view<char>, unsigned long, std::basic_string<char>>' requested here
          auto node = events_.put(name, thread_info_type_, level, format,
                              ^
./soralog/include/soralog/logger.hpp:44:16: note: in instantiation of function template specialization 'soralog::Sink::push<std::basic_string_view<char>, std::basic_string<char>>' requested here
        sink_->push(name_, level, format, args...);
               ^
./soralog/include/soralog/logger.hpp:170:7: note: in instantiation of function template specialization 'soralog::Logger::push<std::basic_string_view<char>, std::basic_string<char>>' requested here
      push(Level::CRITICAL, format, args...);
      ^
cpp-libp2p/src/basic/scheduler/asio_scheduler_backend.cpp:40:12: note: in instantiation of function template specialization 'soralog::Logger::critical<std::basic_string<char>>' requested here
      log->critical("cannot set timer: {}", ec.message());
           ^
./soralog/include/soralog/event.hpp:62:65: note: function parameter 'format' with unknown value cannot be used in a constant expression
            fmt::format_to_n(message_data_, max_message_length, format, args...)
                                                                ^
./soralog/include/soralog/event.hpp:46:25: note: declared here
          const Format &format, size_t max_message_length, const Args &...args)
                        ^
1 error generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants