Obliterate Boost #25

pull vasild wants to merge 2 commits into bitcoin-core:master from vasild:std_optional changing 5 files +22 −21
  1. vasild commented at 1:22 PM on February 21, 2020: contributor
    • While it may be possible to refactor the code in a way that it does not use any optional types, like in a616312, fb73b81, 138ad67, 5724a2c, that would be error prone and would require bigger changes. Switch from C++14 to C++17 instead and replace boost::optional with std::optional.

    • Removing boost::current_exception_diagnostic_information() - if the caught exception is an instance of std::exception, use its what() method. Otherwise don't provide extra diagnostic information. After all boost::current_exception_diagnostic_information() would return "No diagnostic information available." if it is not std::exception or boost::exception.

    • Clean up any mentions of Boost from README.md and CMakeLists.txt.

  2. Sjors commented at 6:41 PM on February 27, 2020: member

    I'm a fan of obliterating boost. @ryanofsky does this also let you drop native_boost from https://github.com/bitcoin/bitcoin/pull/16367? Since libmultiprocess is an optional dependency anyway, it's probably acceptable to depend on C++17.

  3. ryanofsky commented at 7:11 PM on February 27, 2020: collaborator

    Yep, it'd allow dropping native_boost

  4. vasild commented at 7:42 PM on February 27, 2020: contributor

    I was not sure about the switch from C++14 to 17, but thought "Why not, given its already different than bitcoin core's C++11?". Worst case - this PR waits until bitcoin core switches to C++17.

  5. ryanofsky commented at 7:56 PM on February 27, 2020: collaborator

    This makes sense. Maybe C++14 would be compatible with more systems than 17, but I enabled 14 here before the bitcoin discussion turned to skipping 14 and going right to 17.

    If 17 won't work for some reason, Jeremy Rubin recently linked to two small optional<> replacements in IRC which could also be used here

  6. ryanofsky commented at 3:10 AM on March 4, 2020: collaborator

    I ran into some issues trying to use this with bitcoin. The biggest problem is that boost::optional is used in many bitcoin interfaces (example findFork), so even if libmultiprocess is going to stop using boost::optional internally, something has to be done to support it externally. I think I can do it in https://github.com/bitcoin/bitcoin/pull/10102, but it will require some more work.

    I also needed two tweaks to fix some simpler errors:

    diff --git a/include/mp/proxy-io.h b/include/mp/proxy-io.h
    index 8cfb87a..ec5d00a 100644
    --- a/include/mp/proxy-io.h
    +++ b/include/mp/proxy-io.h
    @@ -12,6 +12,7 @@
     
     #include <capnp/rpc-twoparty.h>
     
    +#include <assert.h>
     #include <functional>
     #include <map>
     #include <memory>
    diff --git a/pkgconfig/libmultiprocess.pc.in b/pkgconfig/libmultiprocess.pc.in
    index 506e356..d8bda42 100644
    --- a/pkgconfig/libmultiprocess.pc.in
    +++ b/pkgconfig/libmultiprocess.pc.in
    @@ -9,4 +9,4 @@ Description: Multiprocess IPC library
     Version: 0.0
     
     Libs: -L${libdir} -lmultiprocess -L${capnp_prefix}/lib -lcapnp-rpc -lcapnp -lkj-async -lkj -pthread -lpthread
    -Cflags: -std=c++14 -I${includedir} -I${capnp_prefix}/include -pthread
    +Cflags: -std=c++17 -I${includedir} -I${capnp_prefix}/include -pthread
    
  7. Switch from C++14 to C++17
    This would help replace boost::optional with std::optional and
    completely remove Boost as a dependency of this project.
    f4112b7966
  8. Obliterate Boost
    * While it may be possible to refactor the code in a way that it does
      not use any `optional` types, like in a616312, fb73b81, 138ad67,
      5724a2c, that would be error prone and would require bigger changes.
      Instead replace `boost::optional` with `std::optional`, now that we
      are using C++17.
    
    * Removing `boost::current_exception_diagnostic_information()` - if the
      caught exception is an instance of `std::exception`, use its `what()`
      method. Otherwise don't provide extra diagnostic information. After
      all `boost::current_exception_diagnostic_information()` would return
      "No diagnostic information available." if it is not `std::exception`
      or `boost::exception`.
    
    * Clean up any mentions of Boost from README.md and CMakeLists.txt.
    10b5c69dbc
  9. vasild force-pushed on Mar 4, 2020
  10. Sjors commented at 8:50 AM on March 4, 2020: member

    @ryanofsky alternatively you could add c++17 support to Bitcoin Core's Optional wrapper?

  11. vasild commented at 10:26 AM on March 4, 2020: contributor

    I tried some things that did not work, need to study this more but I feel like it should be possible to resolve the issue solely on the libmultiprocess side and still not have any traces of boost in it.

    In the meantime I added the fix for libmultiprocess.pc.in, split in two commits (C++17 switch + boost removal) and rebased.

  12. ryanofsky commented at 12:11 PM on March 4, 2020: collaborator

    Thanks! I should be able to merge this soon. I just need to add ReadField/BuildField overloads for boost::optional in https://github.com/bitcoin/bitcoin/pull/10102 before merging this

  13. ryanofsky commented at 9:36 PM on March 4, 2020: collaborator

    I was able to get ReadField/BuildField overloads working, so "Obliterate Boost" commit 10b5c69dbc13282ac3f6d95b77e5ab59fe3990aa no longer causes compile errors.

    But it turns out this problem was masking another problem: some really confusing link errors caused by the earlier "Switch from C++14 to C++17" commit f4112b79666ca09d044360840d2068f42792771a. This problem is also fixable, but will require doing more work on the https://github.com/bitcoin/bitcoin/pull/16367 build system, adding a new library for c++17 files instead of using the existing libbitcoin_common.a library.

    The problem happens when linking executables such as bitcoin-tx or bitcoin_bench that link against libbitcoin_common.a but don't link against libmultiprocess.a. It turns out that compiling with c++17 causes some standard library symbols to be weakly defined instead of undefined. For example the string::size() symbol is compiled as

    0000000000000000 W _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv
    

    with c++17, and

                     U _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEv
    

    with c++11.

    This makes it impossible to include c++11 and unused c++17 object files in the same library unless all the dependencies of the c++17 objects are fully satisfied, because even when the c++17 objects are unused and unneeded, the linker will think they are needed because of the weak definitions they contain. So the result is a flood of link errors with f4112b79666ca09d044360840d2068f42792771a when the linker fails to fully link all the unneeded c++17 object files.

    I should be able to fix this in https://github.com/bitcoin/bitcoin/pull/16367 by splitting up the libbitcoin_common.a library. Just wanted to note the issue here.

  14. ryanofsky commented at 9:52 PM on March 4, 2020: collaborator

    @ryanofsky alternatively you could add c++17 support to Bitcoin Core's Optional wrapper?

    Yes, another approach could extend the --enable-multiprocess option make the Optional wrapper use std::optional instead of boost::optional. But this would require extending scope of --enable-multiprocess in awkward ways: either making it compile the whole project with c++17 or building two copies of each library in c++17 and c++11 modes for multiprocess and non-multiprocess binaries, which would be slow and also awkward to do with autotools.

  15. Sjors commented at 8:27 AM on March 5, 2020: member

    It's also not ideal for deterministic building if --enable-multiprocess changes the bitcoind binary in any way.

  16. ryanofsky merged this on Mar 5, 2020
  17. ryanofsky closed this on Mar 5, 2020

  18. vasild deleted the branch on Mar 5, 2020
  19. ryanofsky commented at 6:30 PM on March 31, 2020: collaborator

    I should be able to fix this in bitcoin/bitcoin#16367 by splitting up the libbitcoin_common.a library. Just wanted to note the issue here.

    Forgot to write an update, but this was the approach I took to resolve the problem. All the c++17 objects are now isolated into a libbitcoin_ipc.a library instead of being part of libbitcoin_common.a, so they don't interfere when linking the c++11 objects in libbitcoin_common.a

  20. fanquake referenced this in commit 6c084ac5cc on Feb 18, 2022
  21. fanquake referenced this in commit 07dcf1a76e on Feb 18, 2022
  22. maflcko referenced this in commit 28aa0e3ca0 on Feb 19, 2022
  23. hmel referenced this in commit 7ab17fd1c5 on Feb 20, 2022
  24. janus referenced this in commit 1174e7e27c on Jul 24, 2022
  25. hebasto referenced this in commit 6902bfd40e on Aug 26, 2022
  26. ryanofsky referenced this in commit c6849de823 on Aug 29, 2022
  27. backpacker69 referenced this in commit 5227149dbd on Jan 18, 2023
  28. PastaPastaPasta referenced this in commit a90cf2a643 on Jan 17, 2024
  29. PastaPastaPasta referenced this in commit 9938697fb3 on Feb 20, 2024
  30. PastaPastaPasta referenced this in commit 200d2d58dc on Feb 23, 2024
  31. bitcoin-core locked this on Jun 25, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-18 13:30 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me