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

build: Add CMake-based build system (2 of N) #6

Merged
merged 6 commits into from
Feb 23, 2023

Conversation

hebasto
Copy link
Owner

@hebasto hebasto commented Feb 16, 2023

The parent PR: bitcoin#25797.
The previous PR in the staging branch: #5.

This PR details:

  1. Added project-wide system introspection.
Autoconf macro Symbols in bitcoin-config.h CMake implementation
AC_INIT PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT PACKAGE_URL Done in #5, except for PACKAGE_TARNAME and PACKAGE_STRING, which are not currently used
AX_CXX_COMPILE_STDCXX HAVE_CXX17 HAVE_CXX20 CMake uses its own implementation
AC_C_BIGENDIAN AC_APPLE_UNIVERSAL_BUILD WORDS_BIGENDIAN and C headers CMake uses its own implementation
AX_PTHREAD HAVE_PTHREAD HAVE_PTHREAD_PRIO_INHERIT PTHREAD_CREATE_JOINABLE CMake uses its own implementation
AC_SYS_LARGEFILE _FILE_OFFSET_BITS _LARGE_FILES Not implemented yet
AC_FUNC_STRERROR_R HAVE_DECL_STRERROR_R HAVE_STRERROR_R STRERROR_R_CHAR_P and C headers Implemented STRERROR_R_CHAR_P, others are not used
C headers HAVE_INTTYPES_H HAVE_STDINT_H HAVE_STDIO_H HAVE_STDLIB_H HAVE_STRINGS_H HAVE_STRING_H HAVE_SYS_STAT_H HAVE_SYS_TYPES_H HAVE_UNISTD_H STDC_HEADERS Only HAVE_STRING_H, HAVE_SYS_TYPES_H and HAVE_UNISTD_H are evaluated for internal needs

  1. Added the leveldb build target (including its crc32c dependency):
  • on Linux / *BSD / macOS:
cmake -S . -B build
cmake --build build --target leveldb
  • on Windows:
cmake -G "Visual Studio 17 2022" -A x64 -S . -B build
cmake --build build --config Debug --target leveldb  # or --config Release

NOTE. On Windows (MSVC), the leveldb library now uses crc32c one. That is not the case when using the current build system from the build_msvc directory:

<PreprocessorDefinitions>HAVE_CRC32C=0;HAVE_SNAPPY=0;LEVELDB_IS_BIG_ENDIAN=0;_UNICODE;UNICODE;_CRT_NONSTDC_NO_DEPRECATE;LEVELDB_PLATFORM_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>

@hebasto hebasto changed the title build: Add CMake-based build system (1 of N) build: Add CMake-based build system (2 of N) Feb 17, 2023
@hebasto
Copy link
Owner Author

hebasto commented Feb 17, 2023

The PR description has been updated with details about CMake's implementation of Autoconf's system introspection macros.

@theuni wrote:

and have the next PR be the big one that brings in the structure and at least one build target.

This PR delivers a few build targets. But I couldn't move to actual building without tiding up system introspection. Sorry if it didn't meet your expectations. But I promise the next PR will deliver bitcoind target.

@hebasto
Copy link
Owner Author

hebasto commented Feb 17, 2023

Friendly ping (as GitHub, probably, won't) people who showed some interest in CMake:

@achow101 @adam2k @dongcarl @fanquake @jarolrod @luke-jr @MarcoFalke @ryanofsky @sipsorcery @TheCharlatan @theStack @theuni @vasild @willcl-ark

@theuni
Copy link

theuni commented Feb 17, 2023

At a high-level, I think we need some temporary place to stash autotools parity checks like introspection_compat.cmake.

Reason being: autoconf includes lots of ancient checks that aren't worth the time and effort anymore. Good example is HAVE_STRING_H.

So imo, it'd be helpful for you to be able to make the distinction of "I'm adding this to keep parity with autotools and keep the cmake/bitcoin-config.h identical, but it's not longer necessary and we can remove it all at some point after CMake is merged"

@fanquake
Copy link

autoconf includes lots of ancient checks that aren't worth the time and effort anymore. Good example is HAVE_STRING_H.

Yep. I see little reason to port all of this cruft over into CMake (or keep it for the long term), especially when we don't even do anything based on the output of most tests.

@theuni
Copy link

theuni commented Feb 17, 2023

Yep. I see little reason to port all of this cruft over into CMake (or keep it for the long term), especially when we don't even do anything based on the output of most tests.

I suspect @hebasto's motivation here is trying to exactly re-create bitcoin-config.h exactly as before. IMO that's quite reasonable, as without that we'd never be able to compare object output before/after.

But yes, I very much agree that keeping it for the long term is unnecessary and/or harmful.

@hebasto
Copy link
Owner Author

hebasto commented Feb 17, 2023

@theuni

At a high-level, I think we need some temporary place to stash autotools parity checks like introspection_compat.cmake.

Reason being: autoconf includes lots of ancient checks that aren't worth the time and effort anymore. Good example is HAVE_STRING_H.

So imo, it'd be helpful for you to be able to make the distinction of "I'm adding this to keep parity with autotools and keep the cmake/bitcoin-config.h identical, but it's not longer necessary and we can remove it all at some point after CMake is merged"

Agree. For now, only required / used in our code definitions are evaluated and passed into the bitcoin-config.h header.

HAVE_STRING_H is used just internally for evaluating of STRERROR_R_CHAR_P:

CHECK_INCLUDE_FILE_CXX(string.h HAVE_STRING_H)
if(HAVE_STRING_H)
check_cxx_source_compiles("
#include <string.h>
int main()
{
char buf[100];
char x = *strerror_r(0, buf, sizeof buf);
char* p = strerror_r(0, buf, sizeof buf);
return !p || x;
}
" STRERROR_R_CHAR_P)
endif()

The same way, internally only, some other definitions are used.

@hebasto
Copy link
Owner Author

hebasto commented Feb 17, 2023

I suspect @hebasto's motivation here is trying to exactly re-create bitcoin-config.h exactly as before.

Exactly, as it was explicitly requested.

But I'm not going to pull unused crap. That is why a table in the PR description explains which definition is absent and why.

@theuni
Copy link

theuni commented Feb 17, 2023

I suspect @hebasto's motivation here is trying to exactly re-create bitcoin-config.h exactly as before.

Exactly, as it was explicitly requested.

But I'm not going to pull unused crap. That is why a table in the PR description explains which definition is absent and why.

Yes, this is very helpful and I appreciate the approach. A diff between the old/new bitcoin-config.h looks as expected for me given the chart above.

CHECK_INCLUDE_FILE_CXX(unistd.h HAVE_UNISTD_H)
if(HAVE_UNISTD_H)
check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
check_cxx_symbol_exists(fork "unistd.h" HAVE_DECL_FORK)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other reviewers: this is correctly under the if(HAVE_UNISTD_H) condition, even though it doesn't appear that way in autotools.

There, AC_CHECK_DECLS sets some defaults, including:

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

cmake/introspection.cmake Outdated Show resolved Hide resolved
check_cxx_source_compiles("${check_socket_source}" IFADDR_NEEDS_LINK_TO_SOCKET)
set(CMAKE_REQUIRED_LIBRARIES)
if(IFADDR_NEEDS_LINK_TO_SOCKET)
link_libraries(socket)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gross global :P

I see it matches what we do currently though. Also gross :)

cmake/introspection.cmake Outdated Show resolved Hide resolved
cmake/introspection.cmake Show resolved Hide resolved
cmake/introspection.cmake Outdated Show resolved Hide resolved
cmake/introspection.cmake Outdated Show resolved Hide resolved
cmake/introspection.cmake Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
@theuni
Copy link

theuni commented Feb 17, 2023

Another high-level comment: it might be easier to copy our existing way of building crc32/leveldb (basically reinventing their buildsystem internally) than to battle all of the new changes that using the upstream CMake buildsystem drags in.

In fact, yeah, thinking about it some more I'd much prefer it that way for our initial CMake merge. Then we could switch to the upstream buildsystems at a later date and with more review scrutiny.

@theuni
Copy link

theuni commented Feb 17, 2023

Another high-level comment: it might be easier to copy our existing way of building crc32/leveldb (basically reinventing their buildsystem internally) than to battle all of the new changes that using the upstream CMake buildsystem drags in.

I'm currently working on converting leveldb to be like this to see how it looks, I'll push it up when done.

@hebasto
Copy link
Owner Author

hebasto commented Feb 17, 2023

Another high-level comment: it might be easier to copy our existing way of building crc32/leveldb (basically reinventing their buildsystem internally) than to battle all of the new changes that using the upstream CMake buildsystem drags in.

I'm currently working on converting leveldb to be like this to see how it looks, I'll push it up when done.

Maybe my old branch can be helpful:

?

@hebasto
Copy link
Owner Author

hebasto commented Feb 17, 2023

@furszy @0xB10C @w0xlt

Mind joining us here for testing and reviewing?

@theuni
Copy link

theuni commented Feb 17, 2023

Maybe my old branch can be helpful:

Hah, thanks but too late. Here's my attempt:
https://github.com/theuni/bitcoin/commits/cmake2-selfleveldb

I like this approach MUCH better for now. I think we should work on switching to the upstream buildsystem eventually, but this is such a simpler change to deal with.

@hebasto
Copy link
Owner Author

hebasto commented Feb 18, 2023

@theuni

Maybe my old branch can be helpful:

Hah, thanks but too late. Here's my attempt: https://github.com/theuni/bitcoin/commits/cmake2-selfleveldb

I like this approach MUCH better for now. I think we should work on switching to the upstream buildsystem eventually, but this is such a simpler change to deal with.

Thank you very much for your suggestion! It has been implemented now with a few differences as follows:

  • a structure of a target follows the pattern used in the parent build: Add CMake-based build system bitcoin/bitcoin#25797. i.e, source files, with no headers - definitions - include directories - compile options - link libraries - link options
  • added a missed src/leveldb/util/histogram.cc source file
  • generator expressions are used for brevity
  • adjusted for MSVC
  • include() command has been moved into the top CMakeLists.txt to avoid unneeded contamination by project-wide definitions and options which are set in the src/CMakeLists.txt
  • check for HAVE_O_CLOEXEC is a part of cmake/introspection.cmake as it is used in src/util/tokenpipe.cpp

Other @theuni's comments have been addressed as well.

The PR description has been updated with MSVC-related details.

@hebasto
Copy link
Owner Author

hebasto commented Feb 18, 2023

A note for reviewers.

Consider compiling:

  • with CMake:
cmake -S . -B build -DCMAKE_CXX_FLAGS="-g -O2"
cmake --build build --target leveldb

and

  • with Autotools:
./autogen.sh
./configure --disable-hardening
make clean
make -C src leveldb/libleveldb.la leveldb/libmemenv.la

The resulted CMake's build/libleveldb.a is essentially the same as the combined Autotools' src/leveldb/.libs/libleveldb.a and src/leveldb/.libs/libmemenv.a.

cmake/introspection.cmake Outdated Show resolved Hide resolved
cmake/introspection.cmake Outdated Show resolved Hide resolved
)

#TODO: figure out how to filter out:
# -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we atleast just turn off -Werror, there's no need to have that enabled.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can return to this comment when introducing default warnings and -DWERROR option.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This is ugly for now, but I'm ok punting on this until we see how warning/error handling is intended to be... handled :)

src/CMakeLists.txt Outdated Show resolved Hide resolved
@theuni
Copy link

theuni commented Feb 19, 2023

I'd strongly prefer to integrate crc32c into our buildsystem like this instead for now: https://github.com/hebasto/bitcoin/blob/cmake/0615.4/cmake/subtree-crc32c.cmake (unreviewed in detail, but concept ACK :)

Again, I'm NOT advocating for keeping it that way long-term, I think your approach here is the way to go eventually. But for now, it's effectively forcing reviewers to review the entire crc32c buildsystem as well, leading to questions like: #6 (comment)

@hebasto
Copy link
Owner Author

hebasto commented Feb 20, 2023

@theuni

I'd strongly prefer to integrate crc32c into our buildsystem like this instead for now: https://github.com/hebasto/bitcoin/blob/cmake/0615.4/cmake/subtree-crc32c.cmake (unreviewed in detail, but concept ACK :)

Again, I'm NOT advocating for keeping it that way long-term, I think your approach here is the way to go eventually. But for now, it's effectively forcing reviewers to review the entire crc32c buildsystem as well, leading to questions like: #6 (comment)

Done.

Also addressed @fanquake's comments:

@hebasto
Copy link
Owner Author

hebasto commented Feb 20, 2023

@theuni

These are actually behavioral changes because CMake (surprisingly imo) invokes the linker for check_cxx_source_compiles.

We may want to investigate set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) at the top-level to disable that, then opting-in to linking as necessary (like for the socket check above).

Thanks! A dedicated check_cxx_source_links macro has been added.

@hebasto
Copy link
Owner Author

hebasto commented Feb 20, 2023

@theuni wrote:

and have the next PR be the big one that brings in the structure and at least one build target.

... I promise the next PR will deliver bitcoind target.

See #7 :)

hebasto added a commit that referenced this pull request Feb 23, 2023
Github-Pull: #6
Rebased-From: 2e2ce85
hebasto added a commit that referenced this pull request Feb 23, 2023
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>

Github-Pull: #6
Rebased-From: df89945
hebasto added a commit that referenced this pull request Feb 24, 2023
hebasto added a commit that referenced this pull request Feb 24, 2023
Github-Pull: #6
Rebased-From: 64b1fd4
hebasto added a commit that referenced this pull request Feb 24, 2023
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>

Github-Pull: #6
Rebased-From: 89be42f
hebasto added a commit that referenced this pull request Feb 24, 2023
Github-Pull: #6
Rebased-From: 4cd5efd
hebasto added a commit that referenced this pull request Feb 24, 2023
Github-Pull: #6
Rebased-From: 2e2ce85
hebasto added a commit that referenced this pull request Feb 24, 2023
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>

Github-Pull: #6
Rebased-From: df89945
hebasto added a commit that referenced this pull request Mar 2, 2023
a80fb45 cmake: Build `bitcoind` executable (Hennadii Stepanov)
ffd10d1 cmake: Build `bitcoin_consensus` library (Hennadii Stepanov)
d028a49 cmake: Build `bitcoin_util` static library (Hennadii Stepanov)
318dd82 cmake: Build `bitcoin_crypto` library (Hennadii Stepanov)
e990724 cmake: Build `univalue` static library (Hennadii Stepanov)
eb3546f cmake: Build `secp256k1` static library (Hennadii Stepanov)
0e2287c cmake: Build `minisketch` static library (Hennadii Stepanov)
a06290e cmake: Add `CheckStdFilesystem` module (Hennadii Stepanov)
6317164 cmake: Add essential platform-specific definitions and options (Hennadii Stepanov)

Pull request description:

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6.

  This PR adds the `bitcoind` build target with its dependencies.

  To get comparable binaries, one can use the following commands:
  - with CMake:
  ```
  cmake -S . -B build -DCMAKE_CXX_FLAGS="-g -O2"
  cmake --build build
  ```
  - with Autotools:
  ```
  ./autogen.sh
  ./configure --disable-hardening --disable-wallet --disable-zmq --without-miniupnpc --without-natpmp --disable-usdt
  make clean
  make -C src bitcoind
  ```
  ---

  **Windows-specific notes for reviewers**

  Windows MSVC builds use dependencies provided by the [vcpkg](https://vcpkg.io) package manager. To install them, run:
  ```cmd
  vcpkg --triplet=x64-windows-static install boost-multi-index boost-signals2 libevent
  ```

  To configure, a toolchain file and a triplet must be specified:
  ```cmd
  cmake -G "Visual Studio 17 2022" -A x64 --toolchain C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -S . -B build
  ```

  Then, build the `all` target as usual:
  ```cmd
  cmake --build build --config Debug
  ```

ACKs for top commit:
  TheCharlatan:
    ACK a80fb45
  theuni:
    ACK a80fb45

Tree-SHA512: c37af3bf3975128acba0ef2ff0b13aab1fc44a5ec96b15bcbed1b42f1cc91c533c515762417becc31384839c3408ddafb567b7f9dd53c525e71070e78150d812
hebasto pushed a commit that referenced this pull request Mar 13, 2023
05eeba2 [test] Add manual prune startup test case (dergoegge)
4517419 [util] Avoid integer overflow in CheckDiskSpace (dergoegge)

Pull request description:

  Starting a fresh node with `-prune=1` causes an integer overflow to happen in `CheckDiskSpace` ([here](https://github.com/bitcoin/bitcoin/blob/f7bdcfc83f5753349018be3b5a663c8923d1a5eb/src/init.cpp#L1633-L1648)) because `nPruneTarget` is to the max `uint64_t` value.
  ```
   node1 stderr util/system.cpp:138:51: runtime error: unsigned integer overflow: 52428800 + 18446744073709551615 cannot be represented in type 'unsigned long'
      #0 0x564a482b5088 in CheckDiskSpace(fs::path const&, unsigned long) src/./src/util/system.cpp:138:51
      #1 0x564a4728dc59 in AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*) src/./src/init.cpp:1639:14
      #2 0x564a47256e6a in AppInit(node::NodeContext&, int, char**) src/./src/bitcoind.cpp:221:43
      #3 0x564a47256087 in main src/./src/bitcoind.cpp:265:13
      #4 0x7fcb7cbffd8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
      #5 0x7fcb7cbffe3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
      #6 0x564a471957f4 in _start (/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/bitcoind+0xca07f4) (BuildId: 035cb22302d37317a630900a15a26ecb326d395c)
  SUMMARY: UndefinedBehaviorSanitizer: unsigned-integer-overflow util/system.cpp:138:51 in
  ```

  I think side stepping the overflow for this specific case, is better than adding an exception to the UB suppresions file.

ACKs for top commit:
  MarcoFalke:
    ACK 05eeba2 🥝
  john-moffett:
    ACK 05eeba2

Tree-SHA512: 1d8e6bcb49818139f04b5ab2cbef7f9b422bf0c38a804cd532b6bd0ba4c4fd07f959ba977e59896343f213086c8ecc48180f50d006638dc84649c66ec379d58a
hebasto added a commit that referenced this pull request Mar 31, 2023
b0351e3 [FIXUP] cmake: Rework PIC/PIE logic (Hennadii Stepanov)
a8917ab cmake: Add cross-compiling support (Hennadii Stepanov)
e5e6bd3 build: Generate `share/toolchain.cmake` in  depends (Hennadii Stepanov)
d37c9a2 [FIXUP] cmake: Ensure C language is disabled for FindThreads (Hennadii Stepanov)
3bb3448 [FIXUP] cmake: Enable C language for libsecp256k1 (Hennadii Stepanov)
75b9b6c [FIXUP] cmake: Drop C language from the global project (Hennadii Stepanov)

Pull request description:

  #7 (comment):
  > So.. requesting a hookup to depends in the next PR please :)

  Delivered :)

  ---

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7.

  ---

  EXAMPLES:

  Cross-compiling for Windows:
  ```
  make -C depends HOST=x86_64-w64-mingw32 NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1
  cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=depends/x86_64-w64-mingw32/share/toolchain.cmake
  cmake --build build
  ```

  Cross-compiling for macOS, arm64:
  ```
  make -C depends HOST=arm64-apple-darwin NO_QT=1 NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_USDT=1
  cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=depends/arm64-apple-darwin/share/toolchain.cmake
  cmake --build build
  ```

ACKs for top commit:
  theuni:
    ACK b0351e3, with the caveat that I hope we can make _significant_ changes to the `toolchain.cmake.in`. But I'm ok calling that a work-in-progress while the rest of the work is introduced to keep it from holding up review further.

Tree-SHA512: 41e9925fb30766c61eca3506eed4b8a75701d0ba84c3077317266f73771eca50b14b40102e473b15d5f3f8eac7d87a19c5b27889cb6f350d089b3231b57c0991
hebasto added a commit that referenced this pull request Apr 19, 2023
8ee7537 cmake: Add `systemtap-sdt` optional package support (Hennadii Stepanov)
697c397 cmake: Add `libzmq` optional package support (Hennadii Stepanov)
b195c9c cmake: Add `libminiupnpc` optional package support (Hennadii Stepanov)
9587ed7 cmake: Add `libnatpmp` optional package support (Hennadii Stepanov)
ba50cad [FIXUP] cmake: Fix `check_evhttp_connection_get_peer` macro (Hennadii Stepanov)
9412a2e [FIXUP] cmake: Cleanup `AddBoostIfNeeded` module (Hennadii Stepanov)
15bcb8e cmake: Add `ccache` support (Hennadii Stepanov)
480c8cb cmake: Add `TristateOption` module (Hennadii Stepanov)

Pull request description:

  It was [suggested](#10 (comment)):

  > It might be helpful to get some more of the depends interactions hooked up as a next step

  Done in this PR.

  ---

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7, #10.

  ---

  EXAMPLES:

  1. Cross-compiling for Windows:
  ```
  make -C depends HOST=x86_64-w64-mingw32 NO_QT=1 NO_WALLET=1
  cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=depends/x86_64-w64-mingw32/share/toolchain.cmake
  cmake --build build
  ```

  2. Cross-compiling for macOS (`arm64`, `x86_64`):
  ```
  make -C depends HOST=arm64-apple-darwin NO_QT=1 NO_WALLET=1
  cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=depends/arm64-apple-darwin/share/toolchain.cmake
  cmake --build build
  ```

  3. Building on macOS, arm64:
  - essential build tools:
  ```
  brew install cmake pkg-config
  ```
  - optional build tools:
  ```
  brew install ccache
  ```
  - essential dependencies:
  ```
  brew install boost libevent
  ```
  - optional dependencies:
  ```
  brew install libnatpmp miniupnpc zeromq
  ```
  - configure and build:
  ```
  cmake -S . -B build
  cmake --build build
  ```

  4. Building on Windows:

  - `ccache` is available [here](https://community.chocolatey.org/packages/ccache) or [here](https://ccache.dev/download.html) (also see a [note](#13 (comment))):
  ```
  choco install ccache --version=4.7.4
  ```

  - the [`vcpkg`](https://vcpkg.io) package manager is used to provide other dependencies:
  ```
  vcpkg --triplet=x64-windows-static install boost-multi-index boost-signals2 libevent miniupnpc zeromq
  ```

  - configure and build:
  ```
  cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
  cmake --build build -- -property:UseMultiToolTask=true -maxCpuCount
  ```

  ---

  **NOTE**

  As always, make sure your build tree is clean :)

ACKs for top commit:
  vasild:
    ACK 8ee7537
  theuni:
    ACK 8ee7537

Tree-SHA512: 36ebc63e73d507d86b154121b9bc5b8216554fd63f31808f257cefff7a1a104ce066f2b2cf9fdfc1828066d33cdc0b9ede4a81d8e6a7932de3adcb1f14674796
hebasto pushed a commit that referenced this pull request May 2, 2023
f952e67 ci: remove usage of untrusted bpfcc-tools (fanquake)
1232c2f ci: use LLVM/clang-16 in native_asan job (fanquake)

Pull request description:

  Similar to bitcoin#27298. Working for me on `x86_64` and solves the issue I currently see with TSAN on `aarch64` with master (6882828):
  ```bash
  crc32c/src/crc32c_arm64.cc:101:26: runtime error: load of misaligned address 0xffff84400406 for type 'uint64_t' (aka 'unsigned long'), which requires 8 byte alignment
  0xffff84400406: note: pointer points here
   b9 c5 22 00 01 01  1a 6c 65 76 65 6c 64 62  2e 42 79 74 65 77 69 73  65 43 6f 6d 70 61 72 61  74 6f
               ^
      #0 0xaaaaaddaf0b4 in crc32c::ExtendArm64(unsigned int, unsigned char const*, unsigned long) src/./src/crc32c/src/crc32c_arm64.cc:101:26
      #1 0xaaaaadd2c838 in leveldb::crc32c::Value(char const*, unsigned long) src/./leveldb/util/crc32c.h:20:60
      #2 0xaaaaadd2c838 in leveldb::log::Reader::ReadPhysicalRecord(leveldb::Slice*) src/./src/leveldb/db/log_reader.cc:246:29
      #3 0xaaaaadd2ba9c in leveldb::log::Reader::ReadRecord(leveldb::Slice*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) src/./src/leveldb/db/log_reader.cc:72:38
      #4 0xaaaaadd41710 in leveldb::VersionSet::Recover(bool*) src/./src/leveldb/db/version_set.cc:910:19
      #5 0xaaaaadcf9fec in leveldb::DBImpl::Recover(leveldb::VersionEdit*, bool*) src/./src/leveldb/db/db_impl.cc:320:18
      #6 0xaaaaadd12068 in leveldb::DB::Open(leveldb::Options const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, leveldb::DB**) src/./src/leveldb/db/db_impl.cc:1487:20
      #7 0xaaaaad314e80 in CDBWrapper::CDBWrapper(DBParams const&) src/./src/dbwrapper.cpp:156:30
      #8 0xaaaaace94880 in CBlockTreeDB::CBlockTreeDB(DBParams const&) src/./txdb.h:89:23
      #9 0xaaaaace94880 in std::_MakeUniq<CBlockTreeDB>::__single_object std::make_unique<CBlockTreeDB, DBParams>(DBParams&&) /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/bits/unique_ptr.h:962:34
      #10 0xaaaaace94880 in ChainTestingSetup::ChainTestingSetup(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<char const*, std::allocator<char const*> > const&) src/./src/test/util/setup_common.cpp:188:51
      #11 0xaaaaace95da0 in TestingSetup::TestingSetup(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<char const*, std::allocator<char const*> > const&, bool, bool) src/./src/test/util/setup_common.cpp:243:7
      #12 0xaaaaace96730 in TestChain100Setup::TestChain100Setup(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<char const*, std::allocator<char const*> > const&, bool, bool) src/./src/test/util/setup_common.cpp:274:7
      #13 0xaaaaac1ddbc8 in blockfilter_index_tests::BuildChainTestingSetup::BuildChainTestingSetup() src/./src/test/blockfilter_index_tests.cpp:26:8
      #14 0xaaaaac1ddbc8 in blockfilter_index_tests::blockfilter_index_initial_sync::blockfilter_index_initial_sync() src/./src/test/blockfilter_index_tests.cpp:112:1
      #15 0xaaaaac1ddbc8 in blockfilter_index_tests::blockfilter_index_initial_sync_invoker() src/./src/test/blockfilter_index_tests.cpp:112:1
      #16 0xaaaaabf08f7c in boost::function0<void>::operator()() const /usr/include/boost/function/function_template.hpp:763:14
      #17 0xaaaaabf95468 in boost::detail::forward::operator()() /usr/include/boost/test/impl/execution_monitor.ipp:1388:32
      #18 0xaaaaabf95468 in boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:137:18
      #19 0xaaaaabf8e12c in boost::function0<int>::operator()() const /usr/include/boost/function/function_template.hpp:763:14
      #20 0xaaaaabe7be14 in boost::execution_monitor::catch_signals(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:903:16
      #21 0xaaaaabe7c1c0 in boost::execution_monitor::execute(boost::function<int ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1301:16
      #22 0xaaaaabe6f47c in boost::execution_monitor::vexecute(boost::function<void ()> const&) /usr/include/boost/test/impl/execution_monitor.ipp:1397:5
      #23 0xaaaaabe75124 in boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void ()> const&, unsigned long) /usr/include/boost/test/impl/unit_test_monitor.ipp:49:9
      #24 0xaaaaabed19fc in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:815:44
      #25 0xaaaaabed0f6c in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:784:58
      #26 0xaaaaabed0f6c in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /usr/include/boost/test/impl/framework.ipp:784:58
      #27 0xaaaaabe73878 in boost::unit_test::framework::run(unsigned long, bool) /usr/include/boost/test/impl/framework.ipp:1721:29
      #28 0xaaaaabe9d244 in boost::unit_test::unit_test_main(boost::unit_test::test_suite* (*)(int, char**), int, char**) /usr/include/boost/test/impl/unit_test_main.ipp:250:9
      #29 0xffff8f0773f8  (/lib/aarch64-linux-gnu/libc.so.6+0x273f8) (BuildId: f37f3aa07c797e333fd106472898d361f71798f5)
      #30 0xffff8f0774c8 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x274c8) (BuildId: f37f3aa07c797e333fd106472898d361f71798f5)
      #31 0xaaaaabda55ac in _start (/home/fedora/ci_scratch/ci/scratch/build/bitcoin-aarch64-unknown-linux-gnu/src/test/test_bitcoin+0x10e55ac) (BuildId: b7909adaefd9db6cd6a7c4d3d40207cf6bdaf4b3)

  SUMMARY: UndefinedBehaviorSanitizer: misaligned-pointer-use crc32c/src/crc32c_arm64.cc:101:26 in
  ```

ACKs for top commit:
  dergoegge:
    utACK f952e67
  MarcoFalke:
    lgtm ACK f952e67

Tree-SHA512: 9dee2abf73d3f23bb9979bfb453b48e39f0b7a5f58d43824ecf053a53e9800ed413b915382b274d1a84baf2999683e3b485463e377e0455b3f0ead65ed1d1916
hebasto pushed a commit that referenced this pull request Jun 23, 2023
682274a ci: install llvm-symbolizer in MSAN jobs (fanquake)
96527cd ci: use LLVM 16.0.6 in MSAN jobs (fanquake)

Pull request description:

  Fixes: bitcoin#27737 (comment).

  Tested (locally) with bitcoin#27495 that it produces a symbolized backtrace:
  ```bash
  2023-06-20T17:5Uninitialized bytes in __interceptor_strlen at offset 113 inside [0x719000006908, 114)
  ==35429==WARNING: MemorySanitizer: use-of-uninitialized-value
      #0 0x56060fae8c4b in sqlite3Strlen30 /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:32670:28
      #1 0x56060fb0fcf4 in sqlite3PagerOpen /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:57953:17
      #2 0x56060fb0f48b in sqlite3BtreeOpen /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:68679:10
      #3 0x56060fb01384 in openDatabase /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:171911:8
      #4 0x56060fb016ca in sqlite3_open_v2 /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:172034:10
      #5 0x56060e8a94db in wallet::SQLiteDatabase::Open() src/wallet/sqlite.cpp:250:19
      #6 0x56060e8a30fd in wallet::SQLiteDatabase::SQLiteDatabase(fs::path const&, fs::path const&, wallet::DatabaseOptions const&, bool) src/wallet/sqlite.cpp:133:9
      #7 0x56060e8b78f5 in std::__1::__unique_if<wallet::SQLiteDatabase>::__unique_single std::__1::make_unique[abi:v160006]<wallet::SQLiteDatabase, std::__1::__fs::filesystem::path, fs::path&, wallet::DatabaseOptions const&>(std::__1::__fs::filesystem::path&&, fs::path&, wallet::DatabaseOptions const&) /home/ubuntu/ci_scratch/ci/scratch/msan/cxx_build/include/c++/v1/__memory/unique_ptr.h:686:30
      #8 0x56060e8b5240 in wallet::MakeSQLiteDatabase(fs::path const&, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&) src/wallet/sqlite.cpp:641:19
      #9 0x56060e83560b in wallet::MakeDatabase(fs::path const&, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&) src/wallet/walletdb.cpp:1261:16
      #10 0x56060e7546e9 in wallet::MakeWalletDatabase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&) src/wallet/wallet.cpp:2905:12
      #11 0x56060e4bc03f in wallet::TestLoadWallet(wallet::WalletContext&) src/wallet/test/util.cpp:68:21
      #12 0x56060e349ad4 in wallet::wallet_tests::ZapSelectTx::test_method() src/wallet/test/wallet_tests.cpp:897:19
      #13 0x56060e348598 in wallet::wallet_tests::ZapSelectTx_invoker() src/wallet/test/wallet_tests.cpp:891:1
      #14 0x56060cfec325 in boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:117:11
      #15 0x56060ced3a7e in boost::function0<void>::operator()() const /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:763:14
      #16 0x56060ced3a7e in boost::detail::forward::operator()() /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/execution_monitor.ipp:1388:32
      #17 0x56060ced3a7e in boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:137:18
      #18 0x56060cda71c2 in boost::function0<int>::operator()() const /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:763:14
      #19 0x56060cda71c2 in int boost::detail::do_invoke<boost::shared_ptr<boost::detail::translator_holder_base>, boost::function<int ()>>(boost::shared_ptr<boost::detail::translator_holder_base> const&, boost::function<int ()> const&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/execution_monitor.ipp:301:30
      #20 0x56060cda71c2 in boost::execution_monitor::catch_signals(boost::function<int ()> const&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/execution_monitor.ipp:903:16
      #21 0x56060cda784a in boost::execution_monitor::execute(boost::function<int ()> const&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/execution_monitor.ipp:1301:16
      #22 0x56060cd9ec3a in boost::execution_monitor::vexecute(boost::function<void ()> const&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/execution_monitor.ipp:1397:5
      #23 0x56060cd9ec3a in boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void ()> const&, unsigned long) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/unit_test_monitor.ipp:49:9
      #24 0x56060ce1a07b in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/framework.ipp:815:44
      #25 0x56060ce1ad8b in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/framework.ipp:784:58
      #26 0x56060ce1ad8b in boost::unit_test::framework::state::execute_test_tree(unsigned long, unsigned long, boost::unit_test::framework::state::random_generator_helper const*) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/framework.ipp:784:58
      #27 0x56060cd9b8de in boost::unit_test::framework::run(unsigned long, bool) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/framework.ipp:1722:29
      #28 0x56060cdd4fac in boost::unit_test::unit_test_main(boost::unit_test::test_suite* (*)(int, char**), int, char**) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/unit_test_main.ipp:250:9
      #29 0x56060cdd6094 in main /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/unit_test_main.ipp:306:12
      #30 0x7f7379691d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
      #31 0x7f7379691e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
      #32 0x56060cce2e24 in _start (/home/ubuntu/ci_scratch/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/test_bitcoin+0x188e24)

    Uninitialized value was created by a heap allocation
      #0 0x56060cd163f2 in malloc /ci_base_install/ci/scratch/msan/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:934:3
      #1 0x56060fc10069 in sqlite3MemMalloc /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:25163:7
      #2 0x56060fb063bc in mallocWithAlarm /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:28846:7
      #3 0x56060fae4eb9 in sqlite3Malloc /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:28876:5
      #4 0x56060faf9e19 in sqlite3DbMallocRaw /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:29176:7
      #5 0x56060fb0fc67 in sqlite3PagerOpen /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:57938:17
      #6 0x56060fb0f48b in sqlite3BtreeOpen /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:68679:10
      #7 0x56060fb01384 in openDatabase /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:171911:8
      #8 0x56060fb016ca in sqlite3_open_v2 /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:172034:10
      #9 0x56060e8a94db in wallet::SQLiteDatabase::Open() src/wallet/sqlite.cpp:250:19
      #10 0x56060e8a30fd in wallet::SQLiteDatabase::SQLiteDatabase(fs::path const&, fs::path const&, wallet::DatabaseOptions const&, bool) src/wallet/sqlite.cpp:133:9
      #11 0x56060e8b78f5 in std::__1::__unique_if<wallet::SQLiteDatabase>::__unique_single std::__1::make_unique[abi:v160006]<wallet::SQLiteDatabase, std::__1::__fs::filesystem::path, fs::path&, wallet::DatabaseOptions const&>(std::__1::__fs::filesystem::path&&, fs::path&, wallet::DatabaseOptions const&) /home/ubuntu/ci_scratch/ci/scratch/msan/cxx_build/include/c++/v1/__memory/unique_ptr.h:686:30
      #12 0x56060e8b5240 in wallet::MakeSQLiteDatabase(fs::path const&, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&) src/wallet/sqlite.cpp:641:19
      #13 0x56060e83560b in wallet::MakeDatabase(fs::path const&, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&) src/wallet/walletdb.cpp:1261:16
      #14 0x56060e7546e9 in wallet::MakeWalletDatabase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, wallet::DatabaseOptions const&, wallet::DatabaseStatus&, bilingual_str&) src/wallet/wallet.cpp:2905:12
      #15 0x56060e4bc03f in wallet::TestLoadWallet(wallet::WalletContext&) src/wallet/test/util.cpp:68:21
      #16 0x56060e349ad4 in wallet::wallet_tests::ZapSelectTx::test_method() src/wallet/test/wallet_tests.cpp:897:19
      #17 0x56060e348598 in wallet::wallet_tests::ZapSelectTx_invoker() src/wallet/test/wallet_tests.cpp:891:1
      #18 0x56060cfec325 in boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:117:11
      #19 0x56060ced3a7e in boost::function0<void>::operator()() const /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:763:14
      #20 0x56060ced3a7e in boost::detail::forward::operator()() /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/test/impl/execution_monitor.ipp:1388:32
      #21 0x56060ced3a7e in boost::detail::function::function_obj_invoker0<boost::detail::forward, int>::invoke(boost::detail::function::function_buffer&) /home/ubuntu/ci_scratch/depends/x86_64-pc-linux-gnu/include/boost/function/function_template.hpp:137:18

  SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/ubuntu/ci_scratch/depends/work/build/x86_64-pc-linux-gnu/sqlite/3380500-f816a3e2d52/sqlite3.c:32670:28 in sqlite3Strlen30
  ```

  as opposed to unsymbolized: https://cirrus-ci.com/task/6005512018329600?logs=ci#L3245.

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 682274a

Tree-SHA512: 8f3e7636761c956537a472989bf07529f5afbd988c5e7e1f07ece8b2599608fa4fe9e1efdc6e302cf0f7f44dec3cf9a3c1e68b758af81a8a8b476a43d3220807
hebasto added a commit that referenced this pull request Jul 7, 2023
43123cf FIXUP: Same as PR27458 (Hennadii Stepanov)
2d8930e FIXUP: Same as PR27656 (Hennadii Stepanov)
a112470 cmake: Include CTest (Hennadii Stepanov)
cb19814 cmake: Build `test_bitcoin` executable (Hennadii Stepanov)
751453f cmake: Build `bench_bitcoin` executable (Hennadii Stepanov)
a2c3493 cmake: Add test config and runners (Hennadii Stepanov)
cb7dc94 test: Explicitly specify directory where to search tests for (Hennadii Stepanov)
2fd303f test: Make `util/test_runner.py` honor `BITCOINUTIL` and `BITCOINTX` (Hennadii Stepanov)
2e3721e cmake: Add wallet functionality (Hennadii Stepanov)
f944ccd cmake: Build `bitcoin-util` executable (Hennadii Stepanov)
d1c319d cmake: Build `bitcoin-tx` executable (Hennadii Stepanov)
1934755 cmake: Build `bitcoin-cli` executable (Hennadii Stepanov)
5fc2cee [FIXUP] cmake: Add workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20652 (Hennadii Stepanov)
b2bea9f [FIXUP] cmake: Consider `ASM` option when checking for `HAVE_64BIT_ASM` (Hennadii Stepanov)

Pull request description:

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7, #10, #13.

  ---

  What is NEW:
  - `bitcoin-cli`
  - `bitcoin-tx`
  - `bitcoin-util`
  - wallet functionality and `bitcoin-wallet`
  - `bench_bitcoin`
  - `test_bitcoin`

  EXAMPLES:
  ```
  cmake -S . -B build
  cd build
  cmake --build . -j $(nproc)
  ctest -j $(nproc)
  ./test/functional/test_runner.py -j $(nproc)
  ```

  Using a multi-configuration generator (CMake 3.17+ is required):
  ```
  cmake -S . -B build -G "Ninja Multi-Config"
  cd build
  cmake --build . -j $(nproc)
  ctest -j $(nproc) -C Debug
  ```
  ---

  What to test:
  - old CMake versions, for example v3.13
  - multi-config generators, for example `-G "Ninja Multi-Config"`

  ---

  What to consider additionally:
  - is it worth to pull the "[test: Make util/test_runner.py honor BITCOINUTIL and BITCOINTX](268aca3)" commit to the main repo now?

  FWIW, we use the same approach for functional tests providing the `BITCOIND` environment variable when needed.

ACKs for top commit:
  TheCharlatan:
    ACK 43123cf

Tree-SHA512: a04cfca266bcde780528c915cb01f69189f36a0e1beb521fe75e4816ca4f9ab9440646529bbf2cbdfe76275debc5107ee2433e1027405094d3e8a74ec0d1d077
hebasto added a commit that referenced this pull request Jul 20, 2023
a933ddf [FIXUP] Better document a workaround (Hennadii Stepanov)
769633e [FIXUP] for "cmake: Add wallet functionality" (Hennadii Stepanov)
31e4e62 [FIXUP] for "cmake: Build `test_bitcoin` executable" (Hennadii Stepanov)
f2dbb17 [FIXUP] for "cmake: Build `test_bitcoin` executable" (Hennadii Stepanov)
91d7327 [FIXUP] Boost (Hennadii Stepanov)

Pull request description:

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7, #10, #13, #15.

  This PR consists of fixups only to make reviewing easier :)

ACKs for top commit:
  theuni:
    ACK a933ddf

Tree-SHA512: 270869a3bf9b9f2d56b75d169f25032385fa2d1297951a23c0d1900d9668a40b153c7a5d9b51fa87596eec681107c40da8e55f405d28a7ecd2ec0f72f3550bbf
hebasto added a commit that referenced this pull request Jul 20, 2023
ac7bc5b [FIXUP] Rename CCACHE_EXECUTABLE --> CCACHE_COMMAND for consistency (Hennadii Stepanov)
0476509 [FIXUP] Learn to work with recent ccache in MSVC builds (Hennadii Stepanov)
2fd67c7 [FIXUP] Do not disable `TrackFileAccess` in MSVC builds (Hennadii Stepanov)
a53ae12 [FIXUP] Use Multi-ToolTask in MSVC builds by default (Hennadii Stepanov)

Pull request description:

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7, #10, #13, #15, #17, #18.

  This PR consists of fixups related to using [Ccache](https://ccache.dev/) in MSVC builds.

Top commit has no ACKs.

Tree-SHA512: dc01202b054aaeb5b46607bc93126bee0df523df3b4f2df54b566b2e2d6306d784a723fd4a999d0d84fdf31e926a72304790f94b9d57034db0c112ee9f52070e
hebasto added a commit that referenced this pull request Sep 13, 2023
a65da0d cmake: Redefine configuration flags (Hennadii Stepanov)
1a1dda5 [FIXUP] Evaluate flags set in depends _after_ config-specific flags (Hennadii Stepanov)
482e844 cmake: Warn about not encapsulated build properties (Hennadii Stepanov)
3736470 cmake: Add platform-specific flags (Hennadii Stepanov)
e0621e9 cmake: Add `TryAppendLinkerFlag` module (Hennadii Stepanov)
ae430cf cmake: Add `TryAppendCXXFlags` module (Hennadii Stepanov)
7903bd5 [FIXUP] Encapsulate common build flags into `core` interface library (Hennadii Stepanov)

Pull request description:

  The parent PR: bitcoin#25797.
  The previous PRs in the staging branch: #5, #6, #7, #10, #13, #15, #17, #19.

  ---

  What is NEW:
  - functions for checking compiler and linker flags
  - managing flags for different build types (configurations)

  EXAMPLES of configuration output on Ubuntu 22.04:

  -  for a single-config generator:
  ```
  $ cmake .. -G "Unix Makefiles"
  ...
  Cross compiling ....................... FALSE
  Preprocessor defined macros ...........
  C compiler ............................ /usr/bin/cc
  CFLAGS ................................
  C++ compiler .......................... /usr/bin/c++
  CXXFLAGS ..............................
  Common compile options ................
  Common link options ...................
  Linker flags for executables ..........
  Linker flags for shared libraries .....
  Build type (configuration):
   - CMAKE_BUILD_TYPE ................... RelWithDebInfo
   - Preprocessor defined macros ........
   - CFLAGS ............................. -O2 -g
   - CXXFLAGS ........................... -O2 -g
   - LDFLAGS for executables ............
   - LDFLAGS for shared libraries .......
  Use assembly routines ................. ON
  Use ccache for compiling .............. ON
  ...
  ```

  - for a multi-config generator:
  ```
  $ cmake .. -G "Ninja Multi-Config"
  ...
  Cross compiling ....................... FALSE
  Preprocessor defined macros ...........
  C compiler ............................ /usr/bin/cc
  CFLAGS ................................
  C++ compiler .......................... /usr/bin/c++
  CXXFLAGS ..............................
  Common compile options ................
  Common link options ...................
  Linker flags for executables ..........
  Linker flags for shared libraries .....
  Available build types (configurations)  RelWithDebInfo Debug Release
  'RelWithDebInfo' build type (configuration):
   - Preprocessor defined macros ........
   - CFLAGS ............................. -O2 -g
   - CXXFLAGS ........................... -O2 -g
   - LDFLAGS for executables ............
   - LDFLAGS for shared libraries .......
  'Debug' build type (configuration):
   - Preprocessor defined macros ........ DEBUG DEBUG_LOCKORDER DEBUG_LOCKCONTENTION RPC_DOC_CHECK ABORT_ON_FAILED_ASSUME
   - CFLAGS ............................. -O0 -g3
   - CXXFLAGS ........................... -O0 -g3 -ftrapv
   - LDFLAGS for executables ............
   - LDFLAGS for shared libraries .......
  'Release' build type (configuration):
   - Preprocessor defined macros ........
   - CFLAGS ............................. -O2
   - CXXFLAGS ........................... -O2
   - LDFLAGS for executables ............
   - LDFLAGS for shared libraries .......
  Use assembly routines ................. ON
  Use ccache for compiling .............. ON
  ...
  ```

  - cross-compiling for Windows:
  ```
  $ make -C depends HOST=x86_64-w64-mingw32 DEBUG=1 NO_QT=1
  $ cmake -B build --toolchain depends/x86_64-w64-mingw32/share/toolchain.cmake -DCMAKE_BUILD_TYPE=Debug
  ...
  Cross compiling ....................... TRUE, for Windows, x86_64
  Preprocessor defined macros ........... _WIN32_WINNT=0x0601 _WIN32_IE=0x0501 WIN32_LEAN_AND_MEAN NOMINMAX WIN32 _WINDOWS _MT _GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC
  C compiler ............................ /usr/bin/x86_64-w64-mingw32-gcc
  CFLAGS ................................ -pipe -std=c11 -O1
  C++ compiler .......................... /usr/bin/x86_64-w64-mingw32-g++-posix
  CXXFLAGS .............................. -pipe -std=c++17 -O1
  Common compile options ................
  Common link options ................... -Wl,--major-subsystem-version,6 -Wl,--minor-subsystem-version,1
  Linker flags for executables .......... -static
  Linker flags for shared libraries .....
  Build type (configuration):
   - CMAKE_BUILD_TYPE ................... Debug
   - Preprocessor defined macros ........ DEBUG DEBUG_LOCKORDER DEBUG_LOCKCONTENTION RPC_DOC_CHECK ABORT_ON_FAILED_ASSUME
   - CFLAGS ............................. -O0 -g3
   - CXXFLAGS ........................... -O0 -g3 -ftrapv
   - LDFLAGS for executables ............
   - LDFLAGS for shared libraries .......
  Use assembly routines ................. ON
  Use ccache for compiling .............. ON
  ...
  ```

  **A cross-project note.** The `ProcessConfigurations.cmake` is based on the same module that was suggested in bitcoin-core/secp256k1#1291. So, cross-reviewing is welcome :)

ACKs for top commit:
  theuni:
    ACK a65da0d to keep this moving. This has been sitting for too long :(

Tree-SHA512: 57c5e91ddf9675c6a2b56c0cb70fd3f045af8076bee74c49390de38b8d514e130d2086fde6d83d2d1278b437d0a10cc721f0aa44934698110aeadb3a1aef9e64
hebasto pushed a commit that referenced this pull request Nov 29, 2023
…BlockTx suppression

fa9dc92 test: Add missing CBlockPolicyEstimator::processBlockTx suppression (MarcoFalke)

Pull request description:

  Fixes bitcoin#28865 (comment)

  ```
  # FUZZ=policy_estimator UBSAN_OPTIONS="suppressions=/root/fuzz_dir/scratch/fuzz_gen/code/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1" ./src/test/fuzz/fuzz /tmp/crash-154b42214e70781a9c1ad72d3f2693913dcf8c06

  ...

  policy/fees.cpp:632:27: runtime error: implicit conversion from type 'unsigned int' of value 4294574080 (32-bit, unsigned) to type 'int' changed the value to -393216 (32-bit, signed)
      #0 0x55cbbe10daee in CBlockPolicyEstimator::processBlockTx(unsigned int, CTxMemPoolEntry const*) src/policy/fees.cpp:632:27
      #1 0x55cbbe10e361 in CBlockPolicyEstimator::processBlock(unsigned int, std::vector<CTxMemPoolEntry const*, std::allocator<CTxMemPoolEntry const*>>&) src/policy/fees.cpp:680:13
      #2 0x55cbbd84af48 in policy_estimator_fuzz_target(Span<unsigned char const>)::$_1::operator()() const src/test/fuzz/policy_estimator.cpp:69:40
      #3 0x55cbbd84af48 in unsigned long CallOneOf<policy_estimator_fuzz_target(Span<unsigned char const>)::$_0, policy_estimator_fuzz_target(Span<unsigned char const>)::$_1, policy_estimator_fuzz_target(Span<unsigned char const>)::$_2, policy_estimator_fuzz_target(Span<unsigned char const>)::$_3>(FuzzedDataProvider&, policy_estimator_fuzz_target(Span<unsigned char const>)::$_0, policy_estimator_fuzz_target(Span<unsigned char const>)::$_1, policy_estimator_fuzz_target(Span<unsigned char const>)::$_2, policy_estimator_fuzz_target(Span<unsigned char const>)::$_3) src/./test/fuzz/util.h:43:27
      #4 0x55cbbd84af48 in policy_estimator_fuzz_target(Span<unsigned char const>) src/test/fuzz/policy_estimator.cpp:38:9
      #5 0x55cbbda1cc18 in std::function<void (Span<unsigned char const>)>::operator()(Span<unsigned char const>) const /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_function.h:591:9
      #6 0x55cbbda1cc18 in LLVMFuzzerTestOneInput src/test/fuzz/fuzz.cpp:178:5
      #7 0x55cbbd26a944 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/root/fuzz_dir/scratch/fuzz_gen/code/src/test/fuzz/fuzz+0x190e944) (BuildId: ffb89e0b86c093ca3bdeae6f85537737a4e3b42d)
      #8 0x55cbbd253916 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/root/fuzz_dir/scratch/fuzz_gen/code/src/test/fuzz/fuzz+0x18f7916) (BuildId: ffb89e0b86c093ca3bdeae6f85537737a4e3b42d)
      #9 0x55cbbd25945a in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/root/fuzz_dir/scratch/fuzz_gen/code/src/test/fuzz/fuzz+0x18fd45a) (BuildId: ffb89e0b86c093ca3bdeae6f85537737a4e3b42d)
      #10 0x55cbbd284026 in main (/root/fuzz_dir/scratch/fuzz_gen/code/src/test/fuzz/fuzz+0x1928026) (BuildId: ffb89e0b86c093ca3bdeae6f85537737a4e3b42d)
      #11 0x7fe4aa8280cf  (/lib/x86_64-linux-gnu/libc.so.6+0x280cf) (BuildId: 96ab1a8f3b2c9a2ed37c7388615e6a726d037e89)
      #12 0x7fe4aa828188 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28188) (BuildId: 96ab1a8f3b2c9a2ed37c7388615e6a726d037e89)
      #13 0x55cbbd24e494 in _start (/root/fuzz_dir/scratch/fuzz_gen/code/src/test/fuzz/fuzz+0x18f2494) (BuildId: ffb89e0b86c093ca3bdeae6f85537737a4e3b42d)

  SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-sign-change policy/fees.cpp:632:27 in
  ```

  ```
  # base64 /tmp/crash-154b42214e70781a9c1ad72d3f2693913dcf8c06
  AQEAAAAAADkFlVwAAQEAAAAAADkFlZVcACTDSSsP3746IAZrH48khwMAAQEB/QEALQAACwAAAAAA
  FgAAAAAAAQAABgAAAAAAAAAAAAAAAAAAACcQAAAAAAAAAAAAAAAAAAAAAAD6AAAAOQWVXAABAQAA
  AAAAOQWVlVwAIMNJKw/fvjogBmsfjySHAwABAQH9AQAtAAALAAAAAAAAAAABAAAGAAAAAAAAAAAA
  AAAAAAAAJxAAAAAAAAAAAAAAAAAAAAAAAPr/AAAAAAAAAAAAAAQAAAAA/wAAAAAAAAAAAAAEAAAA
  AAEBAeAIAVwBXAAA/jbSBvwBKABSKBwBYgEB2wAEkvXInHYAAAAAAAAAvgAAAAAA/9//6v8e/xIk
  MgAlAiUAOw==

ACKs for top commit:
  fanquake:
    ACK fa9dc92
  dergoegge:
    utACK fa9dc92

Tree-SHA512: 3898c17c928ecc2bcc8c7086359e9ae00da2197b4d8e10c7bf6d12415326c9bca3ef6e1d8d3b83172ccfa604ce7e7371415262ba705225f9ea4da8b1a7eb0306
hebasto pushed a commit that referenced this pull request Nov 30, 2023
…tifications fuzz target

fab164f fuzz: Avoid signed-integer-overflow in wallet_notifications fuzz target (MarcoFalke)

Pull request description:

  Should avoid

  ```
  policy/feerate.cpp:29:63: runtime error: signed integer overflow: 77600710321911316 * 149 cannot be represented in type 'int64_t' (aka 'long')
      #0 0x563a1775ed66 in CFeeRate::GetFee(unsigned int) const src/policy/feerate.cpp:29:63
      #1 0x563a15913a69 in wallet::COutput::COutput(COutPoint const&, CTxOut const&, int, int, bool, bool, bool, long, bool, std::optional<CFeeRate>) src/./wallet/coinselection.h:91:57
      #2 0x563a16fa6a6d in wallet::FetchSelectedInputs(wallet::CWallet const&, wallet::CCoinControl const&, wallet::CoinSelectionParams const&) src/wallet/spend.cpp:297:17
      #3 0x563a16fc4512 in wallet::CreateTransactionInternal(wallet::CWallet&, std::vector<wallet::CRecipient, std::allocator<wallet::CRecipient>> const&, int, wallet::CCoinControl const&, bool) src/wallet/spend.cpp:1105:33
      #4 0x563a16fbec74 in wallet::CreateTransaction(wallet::CWallet&, std::vector<wallet::CRecipient, std::allocator<wallet::CRecipient>> const&, int, wallet::CCoinControl const&, bool) src/wallet/spend.cpp:1291:16
      #5 0x563a16fcf6df in wallet::FundTransaction(wallet::CWallet&, CMutableTransaction&, long&, int&, bilingual_str&, bool, std::set<int, std::less<int>, std::allocator<int>> const&, wallet::CCoinControl) src/wallet/spend.cpp:1361:16
      #6 0x563a1597b7b9 in wallet::(anonymous namespace)::FuzzedWallet::FundTx(FuzzedDataProvider&, CMutableTransaction) src/wallet/test/fuzz/notifications.cpp:162:15
      #7 0x563a15958240 in wallet::(anonymous namespace)::wallet_notifications_fuzz_target(Span<unsigned char const>)::$_0::operator()() const src/wallet/test/fuzz/notifications.cpp:228:23
      #8 0x563a15958240 in unsigned long CallOneOf<wallet::(anonymous namespace)::wallet_notifications_fuzz_target(Span<unsigned char const>)::$_0, wallet::(anonymous namespace)::wallet_notifications_fuzz_target(Span<unsigned char const>)::$_1>(FuzzedDataProvider&, wallet::(anonymous namespace)::wallet_notifications_fuzz_target(Span<unsigned char const>)::$_0, wallet::(anonymous namespace)::wallet_notifications_fuzz_target(Span<unsigned char const>)::$_1) src/./test/fuzz/util.h:43:27
      #9 0x563a15958240 in wallet::(anonymous namespace)::wallet_notifications_fuzz_target(Span<unsigned char const>) src/wallet/test/fuzz/notifications.cpp:196:9
      #10 0x563a15fdef0c in std::function<void (Span<unsigned char const>)>::operator()(Span<unsigned char const>) const /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_function.h:591:9
      #11 0x563a15fdef0c in LLVMFuzzerTestOneInput src/test/fuzz/fuzz.cpp:178:5
      #12 0x563a158032a4 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x19822a4) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)
      #13 0x563a15802999 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x1981999) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)
      #14 0x563a15804586 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::vector<fuzzer::SizedFile, std::allocator<fuzzer::SizedFile>>&) (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x1983586) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)
      #15 0x563a15804aa7 in fuzzer::Fuzzer::Loop(std::vector<fuzzer::SizedFile, std::allocator<fuzzer::SizedFile>>&) (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x1983aa7) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)
      #16 0x563a157f21fb in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x19711fb) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)
      #17 0x563a1581c766 in main (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x199b766) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)
      #18 0x7f499e17b0cf  (/lib/x86_64-linux-gnu/libc.so.6+0x280cf) (BuildId: 96ab1a8f3b2c9a2ed37c7388615e6a726d037e89)
      #19 0x7f499e17b188 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28188) (BuildId: 96ab1a8f3b2c9a2ed37c7388615e6a726d037e89)
      #20 0x563a157e70c4 in _start (/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/fuzz+0x19660c4) (BuildId: 8acb42ad599d7f6d25b6f93e18fd564d80df7c06)

  SUMMARY: UndefinedBehaviorSanitizer: signed-integer-overflow policy/feerate.cpp:29:63 in
  MS: 0 ; base unit: 0000000000000000000000000000000000000000
  0x3f,0x0,0x2f,0x5f,0x5f,0x5f,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0x7d,0xff,0xff,0xff,0xff,0xff,0x53,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x13,0x5e,0x5f,0x5f,0x8,0x25,0x0,0x5f,0x5f,0x5f,0x5f,0x5f,0x5f,0x8,0x25,0xca,0x7f,0x5f,0x5f,0x5f,0x13,0x13,0x5f,0x5f,0x5f,0x2,0xdb,0xca,0x0,0x0,0xe7,0xe6,0x66,0x65,0x0,0x0,0x0,0x0,0x44,0x3f,0xa,0xa,0xff,0xff,0xff,0xff,0xff,0x61,0x76,0x6f,0x69,0x0,0xb5,0x15,
  ?\000/___}}}}}}}}}}}}}}}}}}}}\377\377\377\377\377S\377\377\377\377\377\000\000\000\000\000\000\023^__\010%\000______\010%\312\177___\023\023___\002\333\312\000\000\347\346fe\000\000\000\000D?\012\012\377\377\377\377\377avoi\000\265\025
  artifact_prefix='./'; Test unit written to ./crash-4d3bac8a64d4e58b2f0943e6d28e6e1f16328d7d
  Base64: PwAvX19ffX19fX19fX19fX19fX19fX19fX3//////1P//////wAAAAAAABNeX18IJQBfX19fX18IJcp/X19fExNfX18C28oAAOfmZmUAAAAARD8KCv//////YXZvaQC1FQ==

ACKs for top commit:
  dergoegge:
    ACK fab164f
  brunoerg:
    ACK fab164f

Tree-SHA512: f416828f4394aa7303ee437f141e9bbd23c0e0f1b830e4ef3932338858249ba68a811b9837c5b7ad8c6ab871b6354996434183597c1a910a8d8e8d829693e4b2
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 23, 2024
Summary:
This var is used in sock.cpp (syserror.cpp after D16209) to pick the correct flavor of `strerror_r` but is never defined.
Define it.

This solution is based on hebasto/bitcoin#6

Test Plan:
```
cmake .. -GNinja
ninja
```

Check the var is set in build/CMakeCache.txt and build/src/config/bitcoin-config.h

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16212
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

Successfully merging this pull request may close these issues.

None yet

5 participants