diff --git a/.cirrus.yml b/.cirrus.yml index 2a3cb1c6d9a..7efb2616b60 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -211,3 +211,13 @@ task: type: small env: FILE_ENV: "./ci/test/00_setup_env_mac_cross.sh" + +task: + name: 'riscv32 bare metal, static libbitcoin_consensus' + << : *GLOBAL_TASK_TEMPLATE + persistent_worker: + labels: + type: small + env: + FILE_ENV: "./ci/test/00_setup_env_riscv_bare_cross.sh" + diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dba6f255d4..a20f487eadf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,11 +329,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") endif() endif() +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(core_interface INTERFACE Threads::Threads ) +endif() add_library(sanitize_interface INTERFACE) target_link_libraries(core_interface INTERFACE sanitize_interface) @@ -381,8 +383,10 @@ if(BUILD_FUZZ_BINARY) ) endif() +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") include(AddBoostIfNeeded) add_boost_if_needed() +endif() if(BUILD_DAEMON OR BUILD_GUI OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY) find_package(Libevent 2.1.8 MODULE REQUIRED) diff --git a/ci/test/00_setup_env_riscv_bare_cross.sh b/ci/test/00_setup_env_riscv_bare_cross.sh new file mode 100755 index 00000000000..09dc91f634d --- /dev/null +++ b/ci/test/00_setup_env_riscv_bare_cross.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2019-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C.UTF-8 + +export CONTAINER_NAME=ci_native_riscv_bare + +export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04" +export PACKAGES="autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev libslirp-dev" +export BITCOIN_CONFIG="-DCMAKE_C_COMPILER=/opt/riscv-ilp32/bin/riscv32-unknown-elf-gcc \ + -DCMAKE_CXX_COMPILER=/opt/riscv-ilp32/bin/riscv32-unknown-elf-g++ \ + -DBUILD_KERNEL_LIB=OFF \ + -DBUILD_UTIL_CHAINSTATE=OFF \ + -DBUILD_TESTS=OFF \ + -DBUILD_BENCH=OFF \ + -DBUILD_FUZZ_BINARY=OFF \ + -DBUILD_DAEMON=OFF \ + -DBUILD_TX=OFF \ + -DBUILD_UTIL=OFF \ + -DBUILD_CLI=OFF \ + -DENABLE_WALLET=OFF \ + -DCMAKE_SYSTEM_NAME=Generic \ + " + +export BARE_METAL_RISCV="true" +export RUN_UNIT_TESTS="false" +export RUN_FUNCTIONAL_TESTS="false" +export NO_DEPENDS="true" diff --git a/ci/test/01_base_install.sh b/ci/test/01_base_install.sh index 0130e820c21..f141841563e 100755 --- a/ci/test/01_base_install.sh +++ b/ci/test/01_base_install.sh @@ -84,6 +84,29 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then rm -rf /msan/llvm-project fi +if [[ ${BARE_METAL_RISCV} == "true" ]]; then + ${CI_RETRY_EXE} git clone --depth=1 https://github.com/riscv-collab/riscv-gnu-toolchain -b 2024.11.22 /riscv/gcc + ( cd /riscv/gcc; + ./configure --prefix=/opt/riscv-ilp32 --with-arch=rv32gc --with-abi=ilp32; + make -j "$MAKEJOBS"; + make install; ) + rm -rf /riscv/gcc + + ${CI_RETRY_EXE} git clone --depth=1 https://sourceware.org/git/newlib-cygwin.git -b topic/3.6 /riscv/newlib + ( cd /riscv/newlib; + mkdir build && cd build; + ../configure \ + --target=riscv32-unknown-elf --with-arch=rv32gc --with-abi=ilp32 --disable-shared --disable-multilib\ + --prefix=/opt/newlib \ + CC_FOR_TARGET=/opt/riscv-ilp32/bin/riscv32-unknown-elf-gcc \ + CXX_FOR_TARGET=/opt/riscv-ilp32/bin/riscv32-unknown-elf-g++ \ + AR_FOR_TARGET=/opt/riscv-ilp32/bin/riscv32-unknown-elf-ar \ + RANLIB_FOR_TARGET=/opt/riscv-ilp32/bin/riscv32-unknown-elf-ranlib + make -j "$MAKEJOBS"; + make install; ) + rm -rf /riscv/newlib +fi + if [[ "${RUN_TIDY}" == "true" ]]; then ${CI_RETRY_EXE} git clone --depth=1 https://github.com/include-what-you-use/include-what-you-use -b clang_"${TIDY_LLVM_V}" /include-what-you-use cmake -B /iwyu-build/ -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-"${TIDY_LLVM_V}" -S /include-what-you-use diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh index 6e77a8927c2..bbb3d594ed5 100755 --- a/ci/test/03_test_script.sh +++ b/ci/test/03_test_script.sh @@ -134,6 +134,61 @@ bash -c "${PRINT_CCACHE_STATISTICS}" du -sh "${DEPENDS_DIR}"/*/ du -sh "${PREVIOUS_RELEASES_DIR}" +if [[ ${BARE_METAL_RISCV} == "true" ]]; then + cmake --build . --target bitcoin_consensus + + echo -e "#include