RFC: Riscv bare metal CI job #31425

pull sedited wants to merge 3 commits into bitcoin:master from sedited:bare_metal_support changing 10 files +141 −4
  1. sedited commented at 8:30 AM on December 5, 2024: contributor

    This adds a CI job for building the static consensus library and linking it to an executable. It uses newlib-cygwin as a C library for the final linking step. This ensure compatibility with this target going forward and can serve as a starting point for enabling bare metal builds for the entire kernel library. This would have also caught the error fixed in #31365.

  2. DrahtBot commented at 8:30 AM on December 5, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31425.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK willcl-ark
    Concept ACK laanwj, hebasto, fanquake

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34411 (Full Libevent removal by fanquake)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. sedited force-pushed on Dec 5, 2024
  4. DrahtBot commented at 9:12 AM on December 5, 2024: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Debug: https://github.com/bitcoin/bitcoin/runs/33960779294</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  5. DrahtBot added the label CI failed on Dec 5, 2024
  6. maflcko commented at 9:16 AM on December 5, 2024: member

    can serve as a starting point for enabling bare metal builds for the entire kernel library.

    Interesting. Do you think this is possible at all, given that the kernel library links leveldb, which I'd presume is not bare-metal ready?

    So I guess this mostly serves as a check that users can ship their own-brewed libbitcoinconsensus (or so, or subset of it)?

  7. sedited force-pushed on Dec 5, 2024
  8. sedited commented at 9:26 AM on December 5, 2024: contributor

    Interesting. Do you think this is possible at all, given that the kernel library links leveldb, which I'd presume is not bare-metal ready?

    Yes, definitely not ready. I think the main hurdle is the background compaction, which I am not sure how to tackle. Maybe we'll find a solution for it eventually though, either by patching it, or allowing the user to bring their own utxos.

    So I guess this mostly serves as a check that users can ship their own-brewed libbitcoinconsensus (or so, or subset of it)?

    Yes, that is the goal for now.

  9. sedited marked this as ready for review on Dec 5, 2024
  10. sedited force-pushed on Dec 5, 2024
  11. in ci/test/03_test_script.sh:168 in 4910ae5d0d outdated
     163 | +        -Wl,--no-whole-archive \
     164 | +        src/crypto/libbitcoin_crypto.a \
     165 | +        src/secp256k1/lib/libsecp256k1.a \
     166 | +        /opt/riscv-ilp32/riscv32-unknown-elf/lib/libstdc++.a \
     167 | +        /riscv/newlib/build/riscv32-unknown-elf/newlib/libc.a \
     168 | +        /riscv/newlib/build/riscv32-unknown-elf/newlib/libm.a \
    


    laanwj commented at 11:20 AM on December 5, 2024:

    Any specific reason to use the intermediate build and not the installed libraries from /opt/newlib, here?

  12. in ci/test/01_base_install.sh:98 in 4910ae5d0d outdated
      93 | +
      94 | +    ${CI_RETRY_EXE} git clone --depth=1 https://sourceware.org/git/newlib-cygwin.git -b topic/3.6 /riscv/newlib
      95 | +    cd /riscv/newlib
      96 | +    mkdir build && cd build
      97 | +    ../configure \
      98 | +        --target=riscv32-unknown-elf --disable-newlib-io-float --enable-newlib-io-long-long --enable-newlib-io-long-double --with-arch=rv32gc --with-abi=ilp32 --disable-shared --disable-multilib\
    


    laanwj commented at 11:22 AM on December 5, 2024:

    Are you sure enabling i/o for long-double is needed? i don't believe we use this type anywhere.


    sedited commented at 2:25 PM on December 6, 2024:

    Sorry, all these flags were a mess. I was experimenting with linking in a range of other functionality, as well as running it on linux directly, and didn't prune stuff out nicely. Removed most of them again.

  13. laanwj commented at 11:35 AM on December 5, 2024: member

    It uses newlib-cygwin as a C library for the final linking step.

    Mentioning this because i had to look it up to be sure: newlib-cygwin has nothing to do with Windows whatsoever. It's simply a minimalist libc.

    I think the main hurdle is the background compaction, which I am not sure how to tackle.

    Could be a periodic foreground task, if threads aren't available? But yes, this would imply patching leveldb, there is no such API right now.

  14. laanwj added the label Build system on Dec 5, 2024
  15. laanwj added the label Tests on Dec 5, 2024
  16. DrahtBot removed the label CI failed on Dec 5, 2024
  17. in ci/test/01_base_install.sh:89 in 4910ae5d0d outdated
      83 | @@ -84,6 +84,29 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
      84 |    rm -rf /msan/llvm-project
      85 |  fi
      86 |  
      87 | +if [[ ${BARE_METAL_RISCV} == "true" ]]; then
      88 | +    ${CI_RETRY_EXE} git clone --depth=1 https://github.com/riscv-collab/riscv-gnu-toolchain -b 2024.11.22 /riscv/gcc
      89 | +    cd /riscv/gcc
    


    maflcko commented at 1:35 PM on December 5, 2024:

    style-wise, it would be good to not use cd in the CI scripts, because it affects the global state for all remaining lines.

    It is better to wrap it into (), for example ( cd a ; foo(); ) (or similar).

  18. in ci/test/01_base_install.sh:107 in 4910ae5d0d outdated
     102 | +        AR_FOR_TARGET=/opt/riscv-ilp32/bin/riscv32-unknown-elf-ar \
     103 | +        RANLIB_FOR_TARGET=/opt/riscv-ilp32/bin/riscv32-unknown-elf-ranlib \
     104 | +        CFLAGS_FOR_TARGET="-march=rv32gc -mabi=ilp32 -mcmodel=medlow "\
     105 | +        CXXFLAGS_FOR_TARGET="-std=c++20 -march=rv32gc -mabi=ilp32 -mcmodel=medlow"
     106 | +    make -j "$MAKEJOBS"
     107 | +    make install
    


    maflcko commented at 1:38 PM on December 5, 2024:

    It would be good to rm -rf everything duplicate. Otherwise, you are using up space twice:

    $ podman image ls | grep riscv
    localhost/ci_native_riscv_bare  latest      dfa9b8223b62  5 minutes ago  13.9 GB
    

    See the llvm build on how to do this.


    sedited commented at 2:39 PM on December 6, 2024:

    Should be better now:

    docker image ls | grep riscv
    ci_native_riscv_bare   latest    55627eefe6d7   3 minutes ago   2.8GB
    
  19. sedited force-pushed on Dec 6, 2024
  20. sedited commented at 3:39 PM on December 6, 2024: contributor

    Updated 4910ae5d0d9954b8b811d7c52e3539979ea46016 -> f27760012b3e236933ea5d1b39a6ba74884df1a2 (bare_metal_support_0 -> bare_metal_support_1, compare)

    • Addressed @maflcko's comment, removing sources after install step.
    • Addressed @maflcko's comment, wrapped cd step into a subshell
    • Addressed @laanwj's comment, use the installed lib
    • Addressed @laanwj's comment, removing a bunch of unneeded/superfluous flags
    • Added a start section to the binary for the global pointer and returning an exit code. Though not needed, since we are only checking that it links, I feel like this makes the example a bit clearer.
  21. in ci/test/03_test_script.sh:154 in f27760012b outdated
     149 | +              la gp, __global_pointer$
     150 | +              .option pop
     151 | +
     152 | +              call main
     153 | +
     154 | +              # Put Exit2 system call number into the a7 register
    


    laanwj commented at 12:46 PM on December 10, 2024:

    concept ACK on making it actually runnable somewhat i was confused for a moment here, as to what syscall numbers mean for bare-metal maybe add "Linux" to the comment

  22. laanwj commented at 12:58 PM on December 10, 2024: member

    Concept ACK, this looks like the minimum required to sanity check that libconsensus.a can be compiled for, and linked for bare-metal RISC-V. It is not enough to test that it actually works (this would require a lot more, quite nasty low-level code), but maybe that's out of scope for this project. At the least it is for this PR.

  23. hebasto commented at 10:53 AM on December 14, 2024: member

    Concept ACK.

  24. in CMakeLists.txt:377 in f27760012b outdated
     373 | @@ -372,8 +374,10 @@ if(BUILD_FUZZ_BINARY)
     374 |    )
     375 |  endif()
     376 |  
     377 | +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
    


    hebasto commented at 2:36 PM on February 3, 2025:

    I imagine that expanding this build scenario might enable building boost and libevent in depends, no?

    If so, the Boost check should have another option to be disabled.

    Additionally, mind considering this comment: https://github.com/bitcoin/bitcoin/blob/1172bc4157eefe80d1aaf0b56459857ec651e535/cmake/module/AddBoostIfNeeded.cmake#L7-L8

    which, in turn, was based on this legacy code:https://github.com/bitcoin/bitcoin/blob/32efe850438ef22e2de39e562af557872a402c31/configure.ac#L1247-L1251

  25. DrahtBot added the label Needs rebase on Mar 31, 2025
  26. sedited force-pushed on Apr 3, 2025
  27. DrahtBot removed the label Needs rebase on Apr 3, 2025
  28. DrahtBot added the label CI failed on Apr 3, 2025
  29. DrahtBot commented at 6:00 AM on April 4, 2025: contributor

    CI failure:

    [12:50:33.743] gmake: *** No rule to make target 'install'.  Stop.
    
  30. maflcko commented at 8:38 AM on May 21, 2025: member

    Coming from #32460 (comment), I noticed that https://www.sourceware.org/newlib/libc.html doesn't list ftruncate, so I guess the build will fail once more code is compiled/linked?

  31. fanquake commented at 8:41 AM on May 21, 2025: member
  32. DrahtBot added the label Needs rebase on Jul 29, 2025
  33. sedited force-pushed on Aug 7, 2025
  34. sedited commented at 7:59 PM on August 7, 2025: contributor

    Rebased f27760012b3e236933ea5d1b39a6ba74884df1a2 -> ec7c86c732c995d2c38e2a3f93ad55a451a8cf81 (bare_metal_support_1 -> bare_metal_support_2, compare)

    • Fixed a bunch of silent and proper merge conflicts.
  35. DrahtBot removed the label Needs rebase on Aug 7, 2025
  36. DrahtBot removed the label CI failed on Aug 7, 2025
  37. DrahtBot added the label Needs rebase on Sep 3, 2025
  38. sedited force-pushed on Sep 4, 2025
  39. sedited commented at 4:08 PM on September 4, 2025: contributor

    Rebased ec7c86c732c995d2c38e2a3f93ad55a451a8cf81 -> a577bbe5df766a4e0e5a36fc997b7880eec45c0e (bare_metal_support_2 -> bare_metal_support_3, compare)

  40. DrahtBot removed the label Needs rebase on Sep 4, 2025
  41. sedited force-pushed on Sep 17, 2025
  42. sedited commented at 11:44 AM on September 17, 2025: contributor

    Rebased a577bbe5df766a4e0e5a36fc997b7880eec45c0e -> e254de76ac0a390569bc5b561f61babb6d021dcb (bare_metal_support_3 -> bare_metal_support_4, compare)

  43. sedited added this to a project on Dec 14, 2025
  44. sedited changed the project status on Dec 14, 2025
  45. DrahtBot added the label Needs rebase on Dec 22, 2025
  46. sedited force-pushed on Dec 23, 2025
  47. sedited commented at 11:26 AM on December 23, 2025: contributor

    Rebased e254de76ac0a390569bc5b561f61babb6d021dcb -> dc53679c60c3a5758700002bbdca6a5ab112c24c (bare_metal_support_4 -> bare_metal_support_5, compare)

  48. DrahtBot removed the label Needs rebase on Dec 23, 2025
  49. fanquake commented at 11:03 AM on February 9, 2026: member

    Concept ACK - Similar to #34421, if there are reservations about having this run in the CI, we can at least add the config.

  50. in ci/test/03_test_script.sh:214 in dc53679c60 outdated
     209 | +        "${BASE_BUILD_DIR}"/src/secp256k1/lib/libsecp256k1.a \
     210 | +        /opt/riscv-ilp32/riscv32-unknown-elf/lib/libstdc++.a \
     211 | +        /opt/newlib/riscv32-unknown-elf/lib/libc.a \
     212 | +        /opt/newlib/riscv32-unknown-elf/lib/libm.a \
     213 | +        /opt/riscv-ilp32/lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a \
     214 | +        -o test.elf
    


    fanquake commented at 11:31 AM on February 9, 2026:

    It could be nice to call file/ldd or something similar, on the produced outputs, so it's more clear what is being built. Otherwise the end-of run output is a bit hard to parse:

    + /opt/riscv-ilp32/bin/riscv32-unknown-elf-gcc -c start.s -o start.o
    + echo -e '#include <sys/stat.h>
              void _exit(int code) { while(1); }
              int _sbrk(int incr) { return 0; }
              int _write(int file, char *ptr, int len) { return 0; }
              int _close(int file) { return -1; }
              int _fstat(int file, struct stat *st) { st->st_mode = S_IFCHR; return 0; }
              int _isatty(int file) { return 1; }
              int _lseek(int file, int ptr, int dir) { return 0; }
              int _read(int file, char *ptr, int len) { return 0; }
              int _kill(int pid, int sig) { return -1; }
              int _getpid(void) { return -1; }'
    + /opt/riscv-ilp32/bin/riscv32-unknown-elf-gcc -g -march=rv32i -mabi=ilp32 -c syscalls.c -o syscalls.o
    + /opt/riscv-ilp32/bin/riscv32-unknown-elf-g++ -g -std=c++20 -march=rv32gc -mabi=ilp32 -nostdlib /opt/riscv-ilp32/lib/gcc/riscv32-unknown-elf/14.2.0/crtbegin.o test.o start.o syscalls.o /ci_container_base/ci/scratch/build-riscv32-unknown-elf-gcc/lib/libbitcoin_consensus.a /ci_container_base/ci/scratch/build-riscv32-unknown-elf-gcc/lib/libbitcoin_crypto.a /ci_container_base/ci/scratch/build-riscv32-unknown-elf-gcc/src/secp256k1/lib/libsecp256k1.a /opt/riscv-ilp32/riscv32-unknown-elf/lib/libstdc++.a /opt/newlib/riscv32-unknown-elf/lib/libc.a /opt/newlib/riscv32-unknown-elf/lib/libm.a /opt/riscv-ilp32/lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a -o test.elf
    + '[' -n '' ']'
    + '[' '' = true ']'
    + '[' false = true ']'
    + '[' false = true ']'
    + '[' false = true ']'
    + [[ '' == true ]]
    + '[' false = true ']'
    Stop and remove CI container by ID
    + docker container kill cfdbe4713beee3e4d396bd9d9226c99efafd3679bb04acdb89ec063eae8402d5
    Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
    cfdbe4713beee3e4d396bd9d9226c99efafd3679bb04acdb89ec063eae8402d5
    

    sedited commented at 9:47 AM on February 10, 2026:

    Added file:

    + file test.elf
    test.elf: ELF 32-bit LSB executable, UCB RISC-V, RVC, soft-float ABI, version 1 (SYSV), statically linked, with debug_info, not stripped
    
  51. sedited force-pushed on Feb 10, 2026
  52. sedited commented at 9:46 AM on February 10, 2026: contributor

    Updated dc53679c60c3a5758700002bbdca6a5ab112c24c -> 774042bb0eecee783ab04e0cb53f762b71984e77 (bare_metal_support_5 -> bare_metal_support_6, compare)

    • Took @fanquake's suggestion, added file command to print final build artifact's information.
    • Addressed @laanwj's comment, added a small comment indicating that making the binary executable on linux serves debugging purposes.
  53. DrahtBot added the label Needs rebase on Apr 9, 2026
  54. sedited force-pushed on Apr 22, 2026
  55. sedited commented at 8:32 PM on April 22, 2026: contributor

    Rebased 774042bb0eecee783ab04e0cb53f762b71984e77 -> 0de648ca1e71cdb76883dc2e31f4c7e630528d27 (bare_metal_support_6 -> bare_metal_support_7, compare)

    • Added some more workarounds after the recent changes to the aes code included the secure allocator, which pulls in the lockedpool, which in turn does not make sense in its current form for bare metal targets.
  56. DrahtBot removed the label Needs rebase on Apr 23, 2026
  57. DrahtBot added the label Needs rebase on May 26, 2026
  58. sedited force-pushed on May 26, 2026
  59. sedited commented at 12:25 PM on May 26, 2026: contributor

    Updated 0de648ca1e71cdb76883dc2e31f4c7e630528d27 -> 50fc04c18cb226bf7545698bcabd1f0028f253cd (bare_metal_support_7 -> bare_metal_support_8, compare)

  60. DrahtBot added the label CI failed on May 26, 2026
  61. DrahtBot removed the label Needs rebase on May 26, 2026
  62. DrahtBot removed the label CI failed on May 28, 2026
  63. in .github/workflows/ci.yml:541 in 50fc04c18c
     536 | @@ -537,6 +537,12 @@ jobs:
     537 |              timeout-minutes: 120
     538 |              file-env: './ci/test/00_setup_env_native_msan.sh'
     539 |  
     540 | +          - name: 'riscv32 bare metal, static libbitcoin_consensus'
     541 | +            cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-lg'
    


    fanquake commented at 10:00 AM on June 17, 2026:

    Can switch this to:

                warp-runner: 'warp-ubuntu-latest-x64-16x'
                fallback-runner: 'ubuntu-latest'
    
  64. in ci/test/00_setup_env_riscv_bare_cross.sh:3 in 50fc04c18c
       0 | @@ -0,0 +1,37 @@
       1 | +#!/usr/bin/env bash
       2 | +#
       3 | +# Copyright (c) 2019-present The Bitcoin Core developers
    


    fanquake commented at 10:00 AM on June 17, 2026:
    # Copyright (c) The Bitcoin Core developers
    # Distributed under the MIT software license, see the accompanying
    # file COPYING or https://opensource.org/license/mit.
    
  65. in ci/test/00_setup_env_riscv_bare_cross.sh:12 in 50fc04c18c
       7 | +export LC_ALL=C.UTF-8
       8 | +
       9 | +export CONTAINER_NAME=ci_native_riscv_bare
      10 | +
      11 | +export GOAL="bitcoin_consensus bitcoin_crypto secp256k1"
      12 | +export CI_IMAGE_NAME_TAG="docker.io/ubuntu:24.04"
    


    fanquake commented at 10:01 AM on June 17, 2026:
    export CI_IMAGE_NAME_TAG="mirror.gcr.io/ubuntu:26.04"
    
  66. in ci/test/01_base_install.sh:88 in 50fc04c18c
      83 | @@ -84,6 +84,29 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then
      84 |    rm -rf /llvm-project
      85 |  fi
      86 |  
      87 | +if [[ ${BARE_METAL_RISCV} == "true" ]]; then
      88 | +    ${CI_RETRY_EXE} git clone --depth=1 https://github.com/riscv-collab/riscv-gnu-toolchain -b 2024.11.22 /riscv/gcc
    


    fanquake commented at 10:08 AM on June 17, 2026:

    2024.11.22

    Should this point to any particular release (can't tell from upstream tags, which are all nightly, what should be used)?


    sedited commented at 4:37 PM on June 17, 2026:

    This basically just needs a compatible host. Looks like you need to look at the submodule information to actually find out what is being versioned? I don't think it matters too much as long as everything links fine.

  67. in ci/test/03_test_script.sh:170 in 50fc04c18c outdated
     166 | @@ -167,6 +167,62 @@ if [ -n "${CI_LIMIT_STACK_SIZE}" ]; then
     167 |    ulimit -s 512
     168 |  fi
     169 |  
     170 | +if [[ ${BARE_METAL_RISCV} == "true" ]]; then
    


    fanquake commented at 10:10 AM on June 17, 2026:

    This chunk is a lot to have inlined here. Could split it into it's own script?


    sedited commented at 3:39 PM on June 17, 2026:

    Could do that, but not sure where to put.


    maflcko commented at 6:12 AM on June 18, 2026:

    You could put it in "${BASE_ROOT_DIR}/ci/test/ like some other ci test snippets.

  68. fanquake commented at 10:12 AM on June 17, 2026: member

    I think this is something we should be testing, and would like to see it move forward.

  69. in ci/test/03_test_script.sh:221 in 50fc04c18c
     216 | +        "${BASE_BUILD_DIR}"/src/secp256k1/lib/libsecp256k1.a \
     217 | +        /opt/riscv-ilp32/riscv32-unknown-elf/lib/libstdc++.a \
     218 | +        /opt/newlib/riscv32-unknown-elf/lib/libc.a \
     219 | +        /opt/newlib/riscv32-unknown-elf/lib/libm.a \
     220 | +        /opt/riscv-ilp32/lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a \
     221 | +        -o test.elf
    


    willcl-ark commented at 3:56 PM on June 17, 2026:

    As an interim, how about force-linking the whole archive, while test only has ScriptErrorString. Otherwise the linker can ignore everything else no?

        /opt/riscv-ilp32/bin/riscv32-unknown-elf-g++ -g -std=c++20 -march=rv32gc -mabi=ilp32 \
            -nostdlib \
            /opt/riscv-ilp32/lib/gcc/riscv32-unknown-elf/14.2.0/crtbegin.o \
            test.o \
            start.o \
            syscalls.o \
             -Wl,--whole-archive \
            "${BASE_BUILD_DIR}"/lib/libbitcoin_consensus.a \
            "${BASE_BUILD_DIR}"/lib/libbitcoin_crypto.a \
            "${BASE_BUILD_DIR}"/src/secp256k1/lib/libsecp256k1.a \
             -Wl,--no-whole-archive \
            /opt/riscv-ilp32/riscv32-unknown-elf/lib/libstdc++.a \
            /opt/newlib/riscv32-unknown-elf/lib/libc.a \
            /opt/newlib/riscv32-unknown-elf/lib/libm.a \
            /opt/riscv-ilp32/lib/gcc/riscv32-unknown-elf/14.2.0/libgcc.a \
            -o test.elf
    
  70. sedited force-pushed on Jun 17, 2026
  71. sedited commented at 4:35 PM on June 17, 2026: contributor

    Rebased and updated 50fc04c18cb226bf7545698bcabd1f0028f253cd -> 0558992d33f336790721920dd57d17441a6c9cea (bare_metal_support_8 -> bare_metal_support_9, compare)

    • Updated to newest riscv toolchain tag and modernized the script a bit, allowing to remove the external newlib and use the version shipped with the toolchain repository.
    • Addressed @willcl-ark's comment, added whole-archive flags.
    • Addressed @fanquake's comment, switched to warp runners.
    • Addressed @fanquake's comment, corrected copyright notice.
    • Addressed @fanquake's comment, migrated to ubuntu 26.04
  72. in ci/test/03_test_script.sh:171 in bff8027243
     166 | @@ -167,6 +167,72 @@ if [ -n "${CI_LIMIT_STACK_SIZE}" ]; then
     167 |    ulimit -s 512
     168 |  fi
     169 |  
     170 | +if [[ ${BARE_METAL_RISCV} == "true" ]]; then
     171 | +    echo -e "#include <script/script_error.h>\n int main() { return ScriptErrorString(ScriptError_t::SCRIPT_ERR_UNKNOWN_ERROR).size() > 0; }" > test.cpp
    


    willcl-ark commented at 9:38 AM on June 18, 2026:

    In bff80272432f8393651ce53cd0be9a5123490b41

    Yeah, I agree with fanquake/marco that this assembly/syscall stub/linking section is not really test orchestration, so keeping it inline in 03_test_script.sh makes that shared script harder to read.

    As suggested previously, could we move the generated test.cpp, start.s, syscalls.c, and final link command into a dedicated helper, e.g. ${BASE_ROOT_DIR}/ci/test/link_riscv_bare_consensus.sh, and have 03_test_script.sh just call that helper when BARE_METAL_RISCV=true?


    willcl-ark commented at 9:45 AM on June 18, 2026:

    I see this was actioned before I could hit send! :)

  73. sedited force-pushed on Jun 18, 2026
  74. sedited commented at 9:40 AM on June 18, 2026: contributor

    Updated 0558992d33f336790721920dd57d17441a6c9cea -> fcbf52fdd1b91298ab81a7dde3063554826f32a0 (bare_metal_support_9 -> bare_metal_support_10, compare)

    • Addressed @fanquake's comment, split linking steps into their own script.
    • Disable gdb for the toolchain, which slims down the build a bit.
  75. willcl-ark commented at 9:44 AM on June 18, 2026: member

    Approach ACK

    this CI job gives an early warning if libbitcoin_consensus.a, libbitcoin_crypto.a, or libsecp256k1.a start depending on hosted OS assumptions that break a riscv32-unknown-elf bare-metal-style link. although using generic I think will actually help catch a class of errors which may apply to other bare metal targets too.

    it seems therefore like a useful minimal guard for keeping the consensus-related static archive linkable in a freestanding environment, and @sedited already highlighted one bug which would have been caught if we'd had this job.

    however it is currently only a compile/link smoke test. it doesn't run the ELF, boot on hardware, exercise script verification, or prove broader bare-metal support. (not goals of this PR, either). the handwritten _start, syscall stubs, and link recipe are also currently embedded in the generic CI script.

    follow ups which I can think of as being interesting might be to link a small real bitcoinconsensus_verify_script caller, and run the ELF under QEMU.

  76. in .github/workflows/ci.yml:527 in fcbf52fdd1 outdated
     522 | @@ -523,6 +523,12 @@ jobs:
     523 |              timeout-minutes: 120
     524 |              file-env: './ci/test/00_setup_env_native_msan.sh'
     525 |  
     526 | +          - name: 'riscv32 bare metal, static libbitcoin_consensus'
     527 | +            warp-runner: 'warp-ubuntu-latest-x64-16x'
    


    willcl-ark commented at 2:35 PM on June 22, 2026:

    I think it would be good to see if we can downgrade this to 8x after it's been merged here. It's only 10 minutes long, and will likely get even shorter when hitting more caches.

    Generally, it's better (cheaper) for us to use a slower CI instance, if we can tolerate the longer runtimes. As this one appears to be pretty quick (~ 10 minutes) it could make sense to downgrade to 8x in the future IMO.

  77. willcl-ark approved
  78. willcl-ark commented at 2:35 PM on June 22, 2026: member

    ACK fcbf52fdd1b91298ab81a7dde3063554826f32a0

    Thjis LGTM now. I'm sure we will find more improvements to make to it, but it already serves a useful purpose, and looks to be implemented correctly according to it's current intended purpose.

  79. DrahtBot requested review from hebasto on Jun 22, 2026
  80. DrahtBot requested review from laanwj on Jun 22, 2026
  81. DrahtBot requested review from fanquake on Jun 22, 2026
  82. DrahtBot added the label Needs rebase on Jun 23, 2026
  83. build: Add option for building for bare metal envs
    A bare metal build is now supported by setting CMAKE_SYSTEM_NAME=Generic
    
    Skip the platform-dependent feature checks, such as threads and atomics,
    which are typically not available on bare metal. Also only make the
    boost headers mandatory if they exist for the target.
    
    Also exclude aes from the crypto library, since that requires the secure
    allocator, which uses more advance features, such as mutexes.
    a9a1d92a1d
  84. Add CI job for producing a static bare metal binary bfdbf513f6
  85. Add CI job for riscv bare metal b36730a3ef
  86. sedited force-pushed on Jun 25, 2026
  87. sedited commented at 8:28 AM on June 25, 2026: contributor

    Rebased fcbf52fdd1b91298ab81a7dde3063554826f32a0 -> b36730a3efc85c4acdb93f06910e37151b8f2cf9 (bare_metal_support_10 -> bare_metal_support_11, compare)

  88. willcl-ark approved
  89. willcl-ark commented at 8:44 AM on June 25, 2026: member

    reACK b36730a3efc85c4acdb93f06910e37151b8f2cf9

    Checked range-diff only

    $ git range-diff fcbf52fdd1b...b36730a3efc
    
     -:  ----------- > 87:  703a671fbc2 fuzz: compact coins view db during fuzzing
     1:  29af6df7e91 ! 88:  a9a1d92a1da build: Add option for building for bare metal envs
        @@ CMakeLists.txt: endif()
          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)
        + if(ENABLE_WALLET)
        +   if(VCPKG_TARGET_TRIPLET)
    
          ## cmake/introspection.cmake ##
         @@ cmake/introspection.cmake: if(NOT WIN32)
        @@ src/CMakeLists.txt: target_link_libraries(bitcoin_node
              univalue
         -    Boost::headers
         +    $<TARGET_NAME_IF_EXISTS:Boost::headers>
        -     $<TARGET_NAME_IF_EXISTS:libevent::core>
        -     $<TARGET_NAME_IF_EXISTS:libevent::extra>
        -     $<TARGET_NAME_IF_EXISTS:libevent::pthreads>
        +     $<TARGET_NAME_IF_EXISTS:USDT::headers>
        + )
        + if(WITH_EMBEDDED_ASMAP)
    
          ## src/crypto/CMakeLists.txt ##
         @@
     2:  bfcbc99953e = 89:  bfdbf513f69 Add CI job for producing a static bare metal binary
     3:  fcbf52fdd1b = 90:  b36730a3efc  Add CI job for riscv bare metal
    
  90. DrahtBot removed the label Needs rebase on Jun 25, 2026
  91. fanquake commented at 11:51 AM on June 25, 2026: member

    Guix Build:

    6be5510ac97201592d603a27c9a505de38c458114788d70dd661fe8fd3d6e6f8  guix-build-b36730a3efc8/output/aarch64-linux-gnu/SHA256SUMS.part
    5e45521428d5238e033a7d389fff528cbca87ab90896064d750d025640703c69  guix-build-b36730a3efc8/output/aarch64-linux-gnu/bitcoin-b36730a3efc8-aarch64-linux-gnu-debug.tar.gz
    f6b3984af843fe120e66e9666b4b8a089ce2b840b9a2357d8b44e2a8eda4410b  guix-build-b36730a3efc8/output/aarch64-linux-gnu/bitcoin-b36730a3efc8-aarch64-linux-gnu.tar.gz
    4c8e7b5f32293878baa2182e64195ff0c0dfb17241d0b1f08e1d4f4a39f4adfd  guix-build-b36730a3efc8/output/arm-linux-gnueabihf/SHA256SUMS.part
    44f106cccc1d7c140109476c94d60742e6cd7bae5add7524d22447f7cc9721de  guix-build-b36730a3efc8/output/arm-linux-gnueabihf/bitcoin-b36730a3efc8-arm-linux-gnueabihf-debug.tar.gz
    77a191511717860710465402eaf76682b9febda71877faf4d808017dfe610825  guix-build-b36730a3efc8/output/arm-linux-gnueabihf/bitcoin-b36730a3efc8-arm-linux-gnueabihf.tar.gz
    553c96e9f0b89fb1aa36a92f1b7358756afb18f74ef228bc48d843dcc74955f2  guix-build-b36730a3efc8/output/arm64-apple-darwin/SHA256SUMS.part
    c6722e53e2297a0e4ba278f0a9c2db7f5aac46cd08a8c306dab9a2c717aed357  guix-build-b36730a3efc8/output/arm64-apple-darwin/bitcoin-b36730a3efc8-arm64-apple-darwin-codesigning.tar.gz
    d812ae4608f5a82cf426a2092e368d0a65414e854c29124f49a86cf914eff94d  guix-build-b36730a3efc8/output/arm64-apple-darwin/bitcoin-b36730a3efc8-arm64-apple-darwin-unsigned.tar.gz
    c5f54764eae63cfbf0eb029ba7c8c82073cf8bb9fd577bf780f701d09beccc1a  guix-build-b36730a3efc8/output/arm64-apple-darwin/bitcoin-b36730a3efc8-arm64-apple-darwin-unsigned.zip
    1266fafab396a1fc3395ea4767c8e36225b05537f34ba759936677f07dced0f3  guix-build-b36730a3efc8/output/dist-archive/bitcoin-b36730a3efc8.tar.gz
    2989ef62e3ea922f4d20b2cd819ea6d5a92fee9df44e0625aa3fee8de0126688  guix-build-b36730a3efc8/output/powerpc64-linux-gnu/SHA256SUMS.part
    2839d7dd674212a55e3c4607c371233b11a7532e080c2f7356732aa629ecda7a  guix-build-b36730a3efc8/output/powerpc64-linux-gnu/bitcoin-b36730a3efc8-powerpc64-linux-gnu-debug.tar.gz
    474fe25da36be086ea228a4d5d7684f49fdb0a6227bc10d49a6adb796921316d  guix-build-b36730a3efc8/output/powerpc64-linux-gnu/bitcoin-b36730a3efc8-powerpc64-linux-gnu.tar.gz
    590191adf09b41365e80d28e9b1ebee7961154cb733767aad2ca5d38ad3073b8  guix-build-b36730a3efc8/output/riscv64-linux-gnu/SHA256SUMS.part
    61dacc898e24b439d747840b3551b76731809529ae426caad9e0427eb86db641  guix-build-b36730a3efc8/output/riscv64-linux-gnu/bitcoin-b36730a3efc8-riscv64-linux-gnu-debug.tar.gz
    af959fce01450358ec25da5400d1aaf004fa43a7ba5795833036beeb6ee0a935  guix-build-b36730a3efc8/output/riscv64-linux-gnu/bitcoin-b36730a3efc8-riscv64-linux-gnu.tar.gz
    31925acd25f9e26e29ecdafdf1b4866e457aa08d64154aa5a82bbca1e49beaba  guix-build-b36730a3efc8/output/x86_64-apple-darwin/SHA256SUMS.part
    b6c36c78dac4145dc37e2318913b778e26a05e84e3549632daaa28dfc11e270c  guix-build-b36730a3efc8/output/x86_64-apple-darwin/bitcoin-b36730a3efc8-x86_64-apple-darwin-codesigning.tar.gz
    1017504a58bc5c1ba457dcbea48572b336333693885c292cf644925513cfb393  guix-build-b36730a3efc8/output/x86_64-apple-darwin/bitcoin-b36730a3efc8-x86_64-apple-darwin-unsigned.tar.gz
    d82720b34eb948716304084506906dffb5c54a2c5c875ac6fb029eaa5b67de2f  guix-build-b36730a3efc8/output/x86_64-apple-darwin/bitcoin-b36730a3efc8-x86_64-apple-darwin-unsigned.zip
    06d242a85329e4ba73385fc6f43c75e766d9ec7cbd54f66d7a6431c4b6242ef4  guix-build-b36730a3efc8/output/x86_64-linux-gnu/SHA256SUMS.part
    5156a48188c0e6a5448d67d335dcea0444b734e832446ec4cd9236f7ddd2feec  guix-build-b36730a3efc8/output/x86_64-linux-gnu/bitcoin-b36730a3efc8-x86_64-linux-gnu-debug.tar.gz
    3319ee73fc87f87a554f29f09994e96ef51424be8e2535d00963ff9291761143  guix-build-b36730a3efc8/output/x86_64-linux-gnu/bitcoin-b36730a3efc8-x86_64-linux-gnu.tar.gz
    724e29ad87d45682faf8a26e6ec70408a96d22c56ec21c04e128e57757ba4990  guix-build-b36730a3efc8/output/x86_64-w64-mingw32/SHA256SUMS.part
    bf6093cca7f4741b9a68d4e86766986c1c764cd05c93f23adec9bfd3641fdcde  guix-build-b36730a3efc8/output/x86_64-w64-mingw32/bitcoin-b36730a3efc8-win64-codesigning.tar.gz
    f32aead13c295e61774a00e289bab5deced84e184b5c8aae4559aaa5526e2ea1  guix-build-b36730a3efc8/output/x86_64-w64-mingw32/bitcoin-b36730a3efc8-win64-debug.zip
    3bdc7bd3175f4027f8e9c0ad140f4445a0ef6022d6c281a5df3540e59c7eda4a  guix-build-b36730a3efc8/output/x86_64-w64-mingw32/bitcoin-b36730a3efc8-win64-setup-unsigned.exe
    2a318a377ec0623a944cd5240e50677b4ea6bc2620f48edec9c143877f9ae85a  guix-build-b36730a3efc8/output/x86_64-w64-mingw32/bitcoin-b36730a3efc8-win64-unsigned.zip
    

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-06-25 17:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me