While it may be possible to refactor the code in a way that it does not use any
optionaltypes, 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 replaceboost::optionalwithstd::optional.Removing
boost::current_exception_diagnostic_information()- if the caught exception is an instance ofstd::exception, use itswhat()method. Otherwise don't provide extra diagnostic information. After allboost::current_exception_diagnostic_information()would return "No diagnostic information available." if it is notstd::exceptionorboost::exception.Clean up any mentions of Boost from README.md and CMakeLists.txt.
Obliterate Boost #25
pull vasild wants to merge 2 commits into bitcoin-core:master from vasild:std_optional changing 5 files +22 −21-
vasild commented at 1:22 PM on February 21, 2020: contributor
-
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.
-
ryanofsky commented at 7:11 PM on February 27, 2020: collaborator
Yep, it'd allow dropping native_boost
-
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.
-
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 -
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::optionalis used in many bitcoin interfaces (examplefindFork), so even if libmultiprocess is going to stop usingboost::optionalinternally, 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 -
f4112b7966
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.
-
10b5c69dbc
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.
- vasild force-pushed on Mar 4, 2020
-
Sjors commented at 8:50 AM on March 4, 2020: member
@ryanofsky alternatively you could add c++17 support to Bitcoin Core's
Optionalwrapper? -
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. -
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
-
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.alibrary.The problem happens when linking executables such as
bitcoin-txorbitcoin_benchthat link againstlibbitcoin_common.abut don't link againstlibmultiprocess.a. It turns out that compiling with c++17 causes some standard library symbols to be weakly defined instead of undefined. For example thestring::size()symbol is compiled as0000000000000000 W _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEvwith c++17, and
U _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE4sizeEvwith 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.alibrary. Just wanted to note the issue here. -
ryanofsky commented at 9:52 PM on March 4, 2020: collaborator
@ryanofsky alternatively you could add c++17 support to Bitcoin Core's
Optionalwrapper?Yes, another approach could extend the
--enable-multiprocessoption make theOptionalwrapper usestd::optionalinstead ofboost::optional. But this would require extending scope of--enable-multiprocessin 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. -
Sjors commented at 8:27 AM on March 5, 2020: member
It's also not ideal for deterministic building if
--enable-multiprocesschanges thebitcoindbinary in any way. - ryanofsky merged this on Mar 5, 2020
- ryanofsky closed this on Mar 5, 2020
- vasild deleted the branch on Mar 5, 2020
-
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.alibrary. 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.alibrary instead of being part oflibbitcoin_common.a, so they don't interfere when linking the c++11 objects inlibbitcoin_common.a - fanquake referenced this in commit 6c084ac5cc on Feb 18, 2022
- fanquake referenced this in commit 07dcf1a76e on Feb 18, 2022
- maflcko referenced this in commit 28aa0e3ca0 on Feb 19, 2022
- hmel referenced this in commit 7ab17fd1c5 on Feb 20, 2022
- janus referenced this in commit 1174e7e27c on Jul 24, 2022
- hebasto referenced this in commit 6902bfd40e on Aug 26, 2022
- ryanofsky referenced this in commit c6849de823 on Aug 29, 2022
- backpacker69 referenced this in commit 5227149dbd on Jan 18, 2023
- PastaPastaPasta referenced this in commit a90cf2a643 on Jan 17, 2024
- PastaPastaPasta referenced this in commit 9938697fb3 on Feb 20, 2024
- PastaPastaPasta referenced this in commit 200d2d58dc on Feb 23, 2024
- bitcoin-core locked this on Jun 25, 2025