From 32fb3618c8c2ebef7dec9326c2648c320c8ea734 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 19 Jan 2024 08:08:13 +0000 Subject: [PATCH] bitcoin-core: Migrate to CMake --- projects/bitcoin-core/Dockerfile | 2 +- projects/bitcoin-core/build.sh | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/projects/bitcoin-core/Dockerfile b/projects/bitcoin-core/Dockerfile index 334085a4b452..3ab831d89a6a 100644 --- a/projects/bitcoin-core/Dockerfile +++ b/projects/bitcoin-core/Dockerfile @@ -23,7 +23,7 @@ RUN apt-get update && apt-get install -y \ automake autotools-dev bsdmainutils build-essential cmake curl g++-multilib libtool make \ patch pkg-config python3 wget zip -RUN git clone --depth=1 https://github.com/bitcoin/bitcoin.git bitcoin-core +RUN git clone --depth=1 --branch 231104-cmake-T https://github.com/hebasto/bitcoin.git bitcoin-core RUN git clone --depth=1 https://github.com/bitcoin-core/qa-assets bitcoin-core/assets && \ rm -rf bitcoin-core/assets/.git # Remove git history to save storage RUN git clone --depth 1 https://github.com/guidovranken/cryptofuzz diff --git a/projects/bitcoin-core/build.sh b/projects/bitcoin-core/build.sh index 4fbe96dde329..23088d174d30 100755 --- a/projects/bitcoin-core/build.sh +++ b/projects/bitcoin-core/build.sh @@ -52,19 +52,20 @@ export CPPFLAGS="-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE ${FIX_32BIT:-}" # Build the fuzz targets -sed -i "s|PROVIDE_FUZZ_MAIN_FUNCTION|NEVER_PROVIDE_MAIN_FOR_OSS_FUZZ|g" "./configure.ac" -./autogen.sh +sed -i "s|PROVIDE_FUZZ_MAIN_FUNCTION|NEVER_PROVIDE_MAIN_FOR_OSS_FUZZ|g" "./src/test/fuzz/util/CMakeLists.txt" +mkdir build +cd build # OSS-Fuzz will provide CC, CXX, etc. So only set: -# * --enable-fuzz, see https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md -# * CONFIG_SITE, see https://github.com/bitcoin/bitcoin/blob/master/depends/README.md +# * -DFUZZ=ON, see https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md +# * --toolchain, see https://github.com/bitcoin/bitcoin/blob/master/depends/README.md if [ "$SANITIZER" = "memory" ]; then - CONFIG_SITE="$PWD/depends/$BUILD_TRIPLET/share/config.site" ./configure --enable-fuzz SANITIZER_LDFLAGS="$LIB_FUZZING_ENGINE" --disable-hardening --with-asm=no + cmake -S .. -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" --toolchain depends/${BUILD_TRIPLET}/share/toolchain.cmake -DCMAKE_BUILD_TYPE=None -DFUZZ=ON -DSANITIZER_LDFLAGS="$LIB_FUZZING_ENGINE" -DHARDENING=OFF -DASM=OFF else - CONFIG_SITE="$PWD/depends/$BUILD_TRIPLET/share/config.site" ./configure --enable-fuzz SANITIZER_LDFLAGS="$LIB_FUZZING_ENGINE" + cmake -S .. -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" --toolchain depends/${BUILD_TRIPLET}/share/toolchain.cmake -DCMAKE_BUILD_TYPE=None -DFUZZ=ON -DSANITIZER_LDFLAGS="$LIB_FUZZING_ENGINE" fi -make -j$(nproc) +cmake --build . -j$(nproc) WRITE_ALL_FUZZ_TARGETS_AND_ABORT="/tmp/a" "./src/test/fuzz/fuzz" || true readarray FUZZ_TARGETS < "/tmp/a" @@ -81,7 +82,7 @@ fi # replace the string in the source code and re-invoke 'make'. This is slower, # so use the hack. export MAGIC_STR="b5813eee2abc9d3358151f298b75a72264ffa119d2f71ae7fefa15c4b70b4bc5b38e87e3107a730f25891ea428b2b4fabe7a84f5bfa73c79e0479e085e4ff157" -sed -i "s|std::getenv(\"FUZZ\")|\"$MAGIC_STR\"|g" "./src/test/fuzz/fuzz.cpp" +sed -i "s|std::getenv(\"FUZZ\")|\"$MAGIC_STR\"|g" "../src/test/fuzz/fuzz.cpp" make -j$(nproc) # Replace the magic string with the actual name of each fuzz target @@ -90,11 +91,11 @@ for fuzz_target in ${FUZZ_TARGETS[@]}; do chmod +x "$OUT/$fuzz_target" ( - cd assets/fuzz_seed_corpus + cd ../assets/fuzz_seed_corpus if [ -d "$fuzz_target" ]; then zip --recurse-paths --quiet --junk-paths "$OUT/${fuzz_target}_seed_corpus.zip" "${fuzz_target}" fi ) done -cp assets/fuzz_dicts/*.dict $OUT/ +cp ../assets/fuzz_dicts/*.dict $OUT/