Skip to content

Commit 3ace3a1

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#20744: Use std::filesystem. Remove Boost Filesystem & System
0726932 build: remove Boost::system usage (fanquake) b87f9c5 build: remove boost::filesystem usage (Kiminuo) 41d7166 refactor: replace boost::filesystem with std::filesystem (Kiminuo) ffc89d1 build: add support for std::filesystem (fanquake) Pull request description: This PR replaces our Boost Filesystem usage with [`std::filesystem`](https://en.cppreference.com/w/cpp/filesystem) and includes dropping Boost System as a dependency. It includes a squashed down version of the changes from #19245. [A macro has been added](bitcoin/bitcoin@7002c4a), modelling how we check for `-latomic` to facilitate linking with `-lstdc++fs` when required. This is ~GCC < 9.1 & ~Clang < 9.0, however not always. i.e you could be using Clang 7 on top of a GCC 9 installation (i.e Ubuntu Focal) and use `<filesystem>` without passing any additional arguments. I've tested this with GCC 8 on Bionic, Clang 7 on Focal & with Apple Clang 12.0.0 on macOS. Guix build: ```bash bash-5.1# find guix-build-$(git rev-parse --short=12 HEAD)/output/ -type f -print0 | env LC_ALL=C sort -z | xargs -r0 sha256sum c1f9b326f9be4140f00cebeae5ff8de428a2fb8ecced539fcc36c53f53bfecf4 guix-build-07269321f38e/output/aarch64-linux-gnu/SHA256SUMS.part b44aca3bcf5ea92a3a6c48c24d6f85576f425f59b73528d4d00c20e950cf2128 guix-build-07269321f38e/output/aarch64-linux-gnu/bitcoin-07269321f38e-aarch64-linux-gnu-debug.tar.gz 27a5553f7bd14797293fc40c5fb131c91e98a61d5481a283f13a1d0497eb5ed8 guix-build-07269321f38e/output/aarch64-linux-gnu/bitcoin-07269321f38e-aarch64-linux-gnu.tar.gz 99e55a88823f6095864a09c9eaa824e24d9ec527380eb394f751c7205b930f69 guix-build-07269321f38e/output/arm-linux-gnueabihf/SHA256SUMS.part b720b2724fa47fde584f58ed3b587f1d1183523540777fd367ab7e582605cfea guix-build-07269321f38e/output/arm-linux-gnueabihf/bitcoin-07269321f38e-arm-linux-gnueabihf-debug.tar.gz c19c247f4e9e0d7f888ac8ba9de1c12d382f48fa828a685d4fe02818a18abd1f guix-build-07269321f38e/output/arm-linux-gnueabihf/bitcoin-07269321f38e-arm-linux-gnueabihf.tar.gz 55b49ccb38de03bb95101354a16fd8d2190abede5ccc0d9b00b40c0cd526a2f6 guix-build-07269321f38e/output/arm64-apple-darwin/SHA256SUMS.part baa44752470a6be9acae1c2f8fd1b9bc37afb00971787ea11fbaeddc9ab7c4aa guix-build-07269321f38e/output/arm64-apple-darwin/bitcoin-07269321f38e-arm64-apple-darwin.tar.gz ad7df4d8026d5bcce1321cdccc2e1820e8a8bb7e1064ed16e20a7ea354057fd2 guix-build-07269321f38e/output/arm64-apple-darwin/bitcoin-07269321f38e-osx-unsigned.dmg f342066dc34a14d67c47779a2413a14633a996e8e7ddca89ae0184e23ef99efd guix-build-07269321f38e/output/arm64-apple-darwin/bitcoin-07269321f38e-osx-unsigned.tar.gz f6905346a5d48f57805fb062d0247ab5007c89047070a0b3125941dd1a2b8aa6 guix-build-07269321f38e/output/dist-archive/bitcoin-07269321f38e.tar.gz a1f6c4b2b118dbd89770801f0bcffd2218b82df408cd227e34c40493469bb7a2 guix-build-07269321f38e/output/powerpc64-linux-gnu/SHA256SUMS.part ba8359426e523bf013d93579c1bedc57380214c8170a9743b64ec1a8a3bbccbf guix-build-07269321f38e/output/powerpc64-linux-gnu/bitcoin-07269321f38e-powerpc64-linux-gnu-debug.tar.gz b0bb500c274a683ea28ecbc1e8f18c618a9f8acb00045f80ae43c515288402c0 guix-build-07269321f38e/output/powerpc64-linux-gnu/bitcoin-07269321f38e-powerpc64-linux-gnu.tar.gz 38c85e9589e092cd3aa08996aa383c0ccd5c73208943389741355a6eb7f72537 guix-build-07269321f38e/output/powerpc64le-linux-gnu/SHA256SUMS.part 50fcba7942ff48d91e84c093fda0affc17e46167fe1d5137c6e14c5c41f289d1 guix-build-07269321f38e/output/powerpc64le-linux-gnu/bitcoin-07269321f38e-powerpc64le-linux-gnu-debug.tar.gz fa08ef1ceca072e014faa95ffee945954b2976fa28f90926b87ab0e5f15f8ca5 guix-build-07269321f38e/output/powerpc64le-linux-gnu/bitcoin-07269321f38e-powerpc64le-linux-gnu.tar.gz e52dd80a9c306d6aeb544acaa1f4ed560b6b92b5184764a05026d45451aa2e94 guix-build-07269321f38e/output/riscv64-linux-gnu/SHA256SUMS.part 864e0a16c485b4159cec3ee0a83b046f1b1c3bc821670011c5ac5cd09ddfb91f guix-build-07269321f38e/output/riscv64-linux-gnu/bitcoin-07269321f38e-riscv64-linux-gnu-debug.tar.gz 4a061172181322e7ad0cf06405bf74f4c8683eaba3a67ecfd46158cba7627f62 guix-build-07269321f38e/output/riscv64-linux-gnu/bitcoin-07269321f38e-riscv64-linux-gnu.tar.gz 876d82251853205420dffe7237523fc6ee3d09f78bf74cc03dc71f548446f335 guix-build-07269321f38e/output/x86_64-apple-darwin/SHA256SUMS.part 3f82b2e62c60eee68e7b8fc28e4792e069e3c2cd780ee2d67290ca422cdbc47c guix-build-07269321f38e/output/x86_64-apple-darwin/bitcoin-07269321f38e-osx-unsigned.dmg 4ccdd4c410cac9d627e54ce83ee4816608681735da3cb93c60c5eb70ca86337a guix-build-07269321f38e/output/x86_64-apple-darwin/bitcoin-07269321f38e-osx-unsigned.tar.gz 2179d36b2f60e28c15262d4e51f27465b5ae077f60e550345e125683ca611066 guix-build-07269321f38e/output/x86_64-apple-darwin/bitcoin-07269321f38e-osx64.tar.gz b377e72fe84b6a982b8d414d60c85e6319523dff50dc852a0ba907f6d850ddd0 guix-build-07269321f38e/output/x86_64-linux-gnu/SHA256SUMS.part 8547e2f582ce05ae6a6224793b64efb2eb63f2816bf0bed5d53fcc4786274597 guix-build-07269321f38e/output/x86_64-linux-gnu/bitcoin-07269321f38e-x86_64-linux-gnu-debug.tar.gz 83b64805aa39f31a6fa4c2ed41e029c3be084e6dea06b90fac1ebca5c95bce29 guix-build-07269321f38e/output/x86_64-linux-gnu/bitcoin-07269321f38e-x86_64-linux-gnu.tar.gz ``` ACKs for top commit: laanwj: Code review ACK 0726932 MarcoFalke: Concept ACK 0726932 🎀 hebasto: ACK 0726932 Tree-SHA512: 1f11614467d2013ed799f23c1c14716570f4c798f231671c731a69c7773ef32a0aa2acc69d4ac2f1f176ef6f160f56566c6bd75c9c059a0e82ab4c58d2b2a750
2 parents c194293 + 0726932 commit 3ace3a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+252
-563
lines changed

build-aux/m4/ax_boost_filesystem.m4

Lines changed: 0 additions & 118 deletions
This file was deleted.

build-aux/m4/ax_boost_system.m4

Lines changed: 0 additions & 121 deletions
This file was deleted.

build-aux/m4/l_filesystem.m4

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
dnl Copyright (c) 2022 The Bitcoin Core developers
2+
dnl Distributed under the MIT software license, see the accompanying
3+
dnl file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
# GCC 8.1 and earlier requires -lstdc++fs
6+
# Clang 8.0.0 (libc++) and earlier requires -lc++fs
7+
8+
m4_define([_CHECK_FILESYSTEM_testbody], [[
9+
#include <filesystem>
10+
11+
namespace fs = std::filesystem;
12+
13+
int main() {
14+
(void)fs::current_path().root_name();
15+
return 0;
16+
}
17+
]])
18+
19+
AC_DEFUN([CHECK_FILESYSTEM], [
20+
21+
AC_LANG_PUSH(C++)
22+
23+
AC_MSG_CHECKING([whether std::filesystem can be used without link library])
24+
25+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_FILESYSTEM_testbody])],[
26+
AC_MSG_RESULT([yes])
27+
],[
28+
AC_MSG_RESULT([no])
29+
SAVED_LIBS="$LIBS"
30+
LIBS="$SAVED_LIBS -lstdc++fs"
31+
AC_MSG_CHECKING([whether std::filesystem needs -lstdc++fs])
32+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_FILESYSTEM_testbody])],[
33+
AC_MSG_RESULT([yes])
34+
],[
35+
AC_MSG_RESULT([no])
36+
AC_MSG_CHECKING([whether std::filesystem needs -lc++fs])
37+
LIBS="$SAVED_LIBS -lc++fs"
38+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_FILESYSTEM_testbody])],[
39+
AC_MSG_RESULT([yes])
40+
],[
41+
AC_MSG_FAILURE([cannot figure out how to use std::filesystem])
42+
])
43+
])
44+
])
45+
46+
AC_LANG_POP
47+
])

build_msvc/bitcoin_config.h.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,9 @@
4444
/* define if the Boost library is available */
4545
#define HAVE_BOOST /**/
4646

47-
/* define if the Boost::Filesystem library is available */
48-
#define HAVE_BOOST_FILESYSTEM /**/
49-
5047
/* define if external signer support is enabled (requires Boost::Process) */
5148
#define ENABLE_EXTERNAL_SIGNER /**/
5249

53-
/* define if the Boost::System library is available */
54-
#define HAVE_BOOST_SYSTEM /**/
55-
5650
/* define if the Boost::Unit_Test_Framework library is available */
5751
#define HAVE_BOOST_UNIT_TEST_FRAMEWORK /**/
5852

build_msvc/vcpkg.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version-string": "1",
44
"dependencies": [
55
"berkeleydb",
6-
"boost-filesystem",
76
"boost-multi-index",
87
"boost-process",
98
"boost-signals2",

ci/test/00_setup_env_native_asan.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
export LC_ALL=C.UTF-8
88

99
export CONTAINER_NAME=ci_native_asan
10-
export PACKAGES="clang llvm python3-zmq qtbase5-dev qttools5-dev-tools libevent-dev bsdmainutils libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libqrencode-dev libsqlite3-dev"
10+
export PACKAGES="clang llvm python3-zmq qtbase5-dev qttools5-dev-tools libevent-dev bsdmainutils libboost-dev libboost-test-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libqrencode-dev libsqlite3-dev"
1111
export DOCKER_NAME_TAG=ubuntu:22.04
1212
export NO_DEPENDS=1
1313
export GOAL="install"

ci/test/00_setup_env_native_fuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export LC_ALL=C.UTF-8
88

99
export DOCKER_NAME_TAG="ubuntu:20.04"
1010
export CONTAINER_NAME=ci_native_fuzz
11-
export PACKAGES="clang llvm python3 libevent-dev bsdmainutils libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libsqlite3-dev"
11+
export PACKAGES="clang llvm python3 libevent-dev bsdmainutils libboost-dev libboost-test-dev libsqlite3-dev"
1212
export NO_DEPENDS=1
1313
export RUN_UNIT_TESTS=false
1414
export RUN_FUNCTIONAL_TESTS=false

ci/test/00_setup_env_native_fuzz_with_valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export LC_ALL=C.UTF-8
88

99
export DOCKER_NAME_TAG="ubuntu:20.04"
1010
export CONTAINER_NAME=ci_native_fuzz_valgrind
11-
export PACKAGES="clang llvm python3 libevent-dev bsdmainutils libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libsqlite3-dev valgrind"
11+
export PACKAGES="clang llvm python3 libevent-dev bsdmainutils libboost-dev libboost-test-dev libsqlite3-dev valgrind"
1212
export NO_DEPENDS=1
1313
export RUN_UNIT_TESTS=false
1414
export RUN_FUNCTIONAL_TESTS=false

ci/test/00_setup_env_native_valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export LC_ALL=C.UTF-8
88

99
export DOCKER_NAME_TAG="ubuntu:20.04"
1010
export CONTAINER_NAME=ci_native_valgrind
11-
export PACKAGES="valgrind clang llvm python3-zmq libevent-dev bsdmainutils libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libsqlite3-dev"
11+
export PACKAGES="valgrind clang llvm python3-zmq libevent-dev bsdmainutils libboost-dev libboost-test-dev libdb5.3++-dev libminiupnpc-dev libnatpmp-dev libzmq3-dev libsqlite3-dev"
1212
export USE_VALGRIND=1
1313
export NO_DEPENDS=1
1414
export TEST_RUNNER_EXTRA="--nosandbox --exclude rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547

configure.ac

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
8383
dnl Check if -latomic is required for <std::atomic>
8484
CHECK_ATOMIC
8585

86+
dnl check if additional link flags are required for std::filesystem
87+
CHECK_FILESYSTEM
88+
8689
dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
8790
dnl that we get the same -std flags for both.
8891
m4_ifdef([AC_PROG_OBJCXX],[
@@ -1404,14 +1407,12 @@ if test "$use_boost" = "yes"; then
14041407
if test "$want_boost" = "no"; then
14051408
AC_MSG_ERROR([only libbitcoinconsensus can be built without Boost])
14061409
fi
1407-
AX_BOOST_SYSTEM
1408-
AX_BOOST_FILESYSTEM
14091410

14101411
if test "$suppress_external_warnings" != "no"; then
14111412
BOOST_CPPFLAGS=SUPPRESS_WARNINGS($BOOST_CPPFLAGS)
14121413
fi
14131414

1414-
BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB"
1415+
BOOST_LIBS="$BOOST_LDFLAGS"
14151416
fi
14161417

14171418
if test "$use_external_signer" != "no"; then

0 commit comments

Comments
 (0)