websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Compatibility fixes for Boost 1.87

Open amini-allight opened this issue 9 months ago • 7 comments
trafficstars

On December 12th 2024 Boost 1.87 was released. This release finally removed support for a number of pieces of Boost.ASIO functionality that had been deprecated since roughly Boost 1.66 back in 2017. Most importantly boost::asio::io_service is no longer available, replaced by boost::asio::io_context. This version of Boost was pushed into the Arch Linux repositories on January 19th 2025 and, once I updated my system, caused builds to fail in a project of mine that depends upon WebSocket++.

I investigated the cause of these failed builds and found that WebSocket++ makes heavy use of this long-deprecated Boost.ASIO functionality, so I authored changes for my own use that rectify this problem. I am unsure if you will want to accept this pull request because the changes are numerous and wide-ranging but I thought I should bring it to your attention. As the developer of a dependent project on a bleeding-edge rolling-release distro I am probably one of the first people to be impacted by this, but the impact will spread as Boost 1.87 begins to be included in regular releases of other distros.

I have tested that this code allows my project to compile, all examples and tests compile and it passes all existing tests. I have not tested whether or not this impacts compatibility with the standalone ASIO backend.

I also have a very similar version of these changes that fix this issue for the master branch which I can make a pull request for upon request.

amini-allight avatar Feb 12 '25 05:02 amini-allight

I've made minor modifications to the build script as well as to the examples and tests to allow me to compile them with ASIO standalone and I can confirm these changes do not break ASIO standalone: they are compatible with both backend options.

amini-allight avatar Feb 14 '25 07:02 amini-allight

@toonetown Thanks for the feedback, I've implemented almost all of your suggestions!

I left two out:

  • I didn't change the roadmap because I'm honestly unsure if that line should be in the roadmap to begin with. There is an example called external_io_service (hopefully soon to be called external_io_context) which seems to demonstrate exactly that feature in use.
  • I didn't change the name of websocketpp::transport::asio::endpoint<config>::reset because this is a public function on the public base class of websocketpp::client. As I understand it that makes it part of the user-facing API so renaming it might break somebody's downstream project and I think we should aim for a drop-in replacement for the broken version.

Let me know if there's any other work that needs doing.

amini-allight avatar Feb 14 '25 23:02 amini-allight

@amini-allight Tried your changes and it worked well with plain boost 1.87. Thanks a lot!

In order to check for expected future problems I tried to build with BOOST_ASIO_NO_DEPRECATED defined, sadly no I got new errors.

Any chance to fix the remaining references on deprecated asio features?

Kinokin avatar Feb 20 '25 05:02 Kinokin

@Kinokin

Any chance to fix the remaining references on deprecated asio features?

I certainly can, if you could detail what errors you've experienced that would be a big help. I tried compiling the examples and tests with BOOST_ASIO_NO_DEPRECATED and the only errors I experienced were caused by use of boost::asio::deadline_timer within the test code itself. I have made a commit that replaces those with the correct boost::asio::system_timer and all tests and examples compile and the tests pass. I didn't find any problem with the headers themselves.

Have you experienced other errors besides these when using BOOST_ASIO_NO_DEPRECATED e.g. in your own downstream project?

amini-allight avatar Feb 20 '25 06:02 amini-allight

@amini-allight

problems I see in my project are about strand::wrap .../websocketpp/transport/asio/connection.hpp:327:45: error: no member named 'wrap' in 'boost::asio::io_context::strand' 327 | new_timer->async_wait(m_strand->wrap(lib::bind( | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:638:27: error: no member named 'wrap' in 'boost::asio::io_context::strand' 638 | m_strand->wrap(lib::bind( | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:721:27: error: no member named 'wrap' in 'boost::asio::io_context::strand' 721 | m_strand->wrap(lib::bind( | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:859:27: error: no member named 'wrap' in 'boost::asio::io_context::strand' 859 | m_strand->wrap(make_custom_alloc_handler( | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:928:27: error: no member named 'wrap' in 'boost::asio::io_context::strand' 928 | m_strand->wrap(make_custom_alloc_handler( | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:968:27: error: no member named 'wrap' in 'boost::asio::io_context::strand' 968 | m_strand->wrap(make_custom_alloc_handler( | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:1033:69: error: no member named 'wrap' in 'boost::asio::io_context::strand' 1033 | lib::asio::post(m_io_context->get_executor(), m_strand->wrap(handler)); | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/connection.hpp:1042:69: error: no member named 'wrap' in 'boost::asio::io_context::strand' 1042 | lib::asio::post(m_io_context->get_executor(), m_strand->wrap(handler)); | ~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/endpoint.hpp:933:37: error: no member named 'wrap' in 'boost::asio::io_context::strand' 933 | tcon->get_strand()->wrap(lib::bind( | ~~~~~~~~~~~~~~~~~~~~^ .../websocketpp/websocketpp/transport/asio/endpoint.hpp:805:37: error: no member named 'wrap' in 'boost::asio::io_context::strand' 805 | tcon->get_strand()->wrap(lib::bind( | ~~~~~~~~~~~~~~~~~~~~^ My application looks fine except of three errors. Didn't check if application uses deprecated feature or errors are caused by above errors

Kinokin avatar Feb 20 '25 06:02 Kinokin

@Kinokin I've added a new commit which addresses this. Let me know if you find any other deprecations which need fixing.

amini-allight avatar Feb 20 '25 17:02 amini-allight

@amini-allight Got build success using the lastest commits using boost 1.87.0 and BOOST_ASIO_NO_DEPRECATED

Most failures in my test application went away and I managed to fix the last one. And the test was successful!

Again, thanks a lot!

Kinokin avatar Feb 21 '25 05:02 Kinokin

Thanks for these fixes! Added it to our application, compiles and works just fine.

MGraefe avatar Mar 10 '25 09:03 MGraefe

@amini-allight should the version check for boost in CMakeLists.txt not have its version increased from 1.39.0 and a version check added to SConstruct? Similarly if the minimum version of boost is now above 1.43.0 then should https://github.com/zaphoyd/websocketpp/blob/master/websocketpp/common/random.hpp#L58 be changed?

loqs avatar Mar 16 '25 16:03 loqs

@loqs Hi, sorry for the delay.

I've bumped the version in the CMakeLists.txt and fixed the use of FindBoost and an ancient CMake version, both of which were also deprecated. I also removed the preprocessor macros for compatibility with old Boost versions from common/random.hpp.

I didn't change the SConstruct file because honestly I'm not familiar with that kind of build script and I couldn't see anywhere the version check would obviously go. If anyone would like to weigh in with advice on how to fix the SConstruct file I'll be happy to integrate it.

amini-allight avatar Apr 09 '25 05:04 amini-allight

I assume this change removes compatibility with the older versions of Asio?

zaphoyd avatar Apr 19 '25 14:04 zaphoyd

@zaphoyd - yeah - will break if using versions of asio that are more than 8 years old. Versions that old are very unlikely to be encountered in the wild…and this change is required to support current asio and boost.

There has been an 8-year deprecation time window - seems a change like this is just in keeping up with the times. If you have a requirement to use 8-year-old asio, you can use older websocket++ as well.

toonetown avatar Apr 19 '25 15:04 toonetown

Noted. As I review I am trying to assess whether some sort of fallback is needed. I think I agree that at this point falling back to an older version of WebSocket++ is likely to be the best solution for that narrow case.

Also, thanks for your (and others here) work on this. Going to try and get this reviewed and packaged up into an official release.

zaphoyd avatar Apr 19 '25 15:04 zaphoyd

@zaphoyd To expand on what toonetown said compatibility with boost 1.66.0 and onwards should be preserved but I have not tested this extensively (I can do so if you like). Any version before that will not work because, at a minimum, boost::asio::io_context didn't exist yet, which we are now using in place of boost::asio::io_service all throughout the project. Examining the Boost compatibility preprocessor macros in random.hpp (which were removed) it appears that the current develop branch doesn't support versions earlier than 1.43.0 anyway, so 1.43.0 — 1.65.1 inclusive is all we're losing.

The CMake version bump probably also introduces incompatibility with some old CMake versions but I'm not sure it's possible to win with CMake: an older specified version causes incompatibility with newer executables just as much as a newer specified version causes incompatibility with older executables.

Great to hear you're looking to merge this!

amini-allight avatar Apr 19 '25 17:04 amini-allight

@zaphoyd Are there any plans to merge this pull request? One more question - are there any plans to release the next version (0.8.3)? Thank you.

maxoodf avatar May 05 '25 11:05 maxoodf

Any progress on getting this back into vcpkg?

Nick7K avatar Jun 24 '25 05:06 Nick7K

Any progress on getting this back into vcpkg?

This request need to be reviewed and merged so we can open an issue on vcpkg, see:

https://github.com/microsoft/vcpkg/pull/42678#issuecomment-2902780101

@zaphoyd @toonetown could you please, review it?

cricri32 avatar Jul 02 '25 02:07 cricri32

I'm also coming here from the vcpkg repo, @zaphoyd will youmerge this request?

enelielz avatar Jul 12 '25 05:07 enelielz

I'm also coming here from the vcpkg repo, @zaphoyd will youmerge this request?

Hey have you succeeded on compiling it?

cricri32 avatar Jul 20 '25 08:07 cricri32

Everyone coming here from the vcpkg issue D:

erikpaulo22 avatar Aug 12 '25 19:08 erikpaulo22

+1

sidarnnt avatar Aug 25 '25 20:08 sidarnnt

bump

Wiminii avatar Sep 13 '25 23:09 Wiminii

Everyone coming here from the vcpkg issue D:

:D

sergnejk2 avatar Oct 12 '25 09:10 sergnejk2

@zaphoyd will you merge it?

utopyap avatar Oct 19 '25 15:10 utopyap

bump

garbanrd09 avatar Nov 14 '25 10:11 garbanrd09