Skip to content

Commit

Permalink
bitcoin-core: Migrate to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jan 19, 2024
1 parent b487d00 commit 32fb361
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion projects/bitcoin-core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions projects/bitcoin-core/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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/

0 comments on commit 32fb361

Please sign in to comment.