Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env bash2# Copyright (c) The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or https://opensource.org/license/mit.5export LC_ALL=C.UTF-86set -o errexit -o pipefail8# Source the common prelude, which:9# 1. Checks if we're at the top directory of the Bitcoin Core repository10# 2. Defines a few common functions and variables11#12# shellcheck source=libexec/prelude.bash13source "$(dirname "${BASH_SOURCE[0]}")/libexec/prelude.bash"16###################17## SANITY CHECKS ##18###################20################21# Required non-builtin commands should be invocable22################24check_tools cat mkdir make getent curl git guix26################27# GUIX_BUILD_OPTIONS should be empty28################29#30# GUIX_BUILD_OPTIONS is an environment variable recognized by guix commands that31# can perform builds. This seems like what we want instead of32# ADDITIONAL_GUIX_COMMON_FLAGS, but the value of GUIX_BUILD_OPTIONS is actually33# _appended_ to normal command-line options. Meaning that they will take34# precedence over the command-specific ADDITIONAL_GUIX_<CMD>_FLAGS.35#36# This seems like a poor user experience. Thus we check for GUIX_BUILD_OPTIONS's37# existence here and direct users of this script to use our (more flexible)38# custom environment variables.39if [ -n "$GUIX_BUILD_OPTIONS" ]; then40cat << EOF41Error: Environment variable GUIX_BUILD_OPTIONS is not empty:42'$GUIX_BUILD_OPTIONS'44Unfortunately this script is incompatible with GUIX_BUILD_OPTIONS, please unset45GUIX_BUILD_OPTIONS and use ADDITIONAL_GUIX_COMMON_FLAGS to set build options46across guix commands or ADDITIONAL_GUIX_<CMD>_FLAGS to set build options for a47specific guix command.49See contrib/guix/README.md for more details.50EOF51exit 152fi54################55# The git worktree should not be dirty56################58if ! git diff-index --quiet HEAD -- && [ -z "$FORCE_DIRTY_WORKTREE" ]; then59cat << EOF60ERR: The current git worktree is dirty, which may lead to broken builds.62Aborting...64Hint: To make your git worktree clean, You may want to:651. Commit your changes,662. Stash your changes, or673. Set the 'FORCE_DIRTY_WORKTREE' environment variable if you insist on68using a dirty worktree69EOF70exit 171fi73mkdir -p "$VERSION_BASE"75################76# SOURCE_DATE_EPOCH should not unintentionally be set77################79check_source_date_epoch81################82# Build directories should not exist83################85# Default to building for all supported HOSTs (overridable by environment)86# powerpc64le-linux-gnu currently disabled due non-determinism issues across build arches.87export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu88x86_64-w64-mingw3289x86_64-apple-darwin arm64-apple-darwin}"91# Accumulate a list of build directories that already exist...92hosts_distsrc_exists=""93for host in $HOSTS; do94if [ -e "$(distsrc_for_host "$host")" ]; then95hosts_distsrc_exists+=" ${host}"96fi97done99if [ -n "$hosts_distsrc_exists" ]; then100# ...so that we can print them out nicely in an error message101cat << EOF102ERR: Build directories for this commit already exist for the following platform103triples you're attempting to build, probably because of previous builds.104Please remove, or otherwise deal with them prior to starting another build.106Aborting...108Hint: To blow everything away, you may want to use:110$ ./contrib/guix/guix-clean112Specifically, this will remove all files without an entry in the index,113excluding the SDK directory, the depends download cache, the depends built114packages cache, the garbage collector roots for Guix environments, and the115output directory.116EOF117for host in $hosts_distsrc_exists; do118echo " ${host} '$(distsrc_for_host "$host")'"119done120exit 1121else122mkdir -p "$DISTSRC_BASE"123fi125################126# When building for darwin, the macOS SDK should exist127################129for host in $HOSTS; do130case "$host" in131*darwin*)132OSX_SDK="$(make -C "${PWD}/depends" --no-print-directory HOST="$host" print-OSX_SDK | sed 's@^[^=]\+=@@g')"133if [ -e "$OSX_SDK" ]; then134echo "Found macOS SDK at '${OSX_SDK}', using..."135break136else137echo "macOS SDK does not exist at '${OSX_SDK}', please place the extracted, untarred SDK there to perform darwin builds, or define SDK_PATH environment variable. Exiting..."138exit 1139fi140;;141esac142done144################145# VERSION_BASE should have enough space146################148avail_KiB="$(df -Pk "$VERSION_BASE" | sed 1d | tr -s ' ' | cut -d' ' -f4)"149total_required_KiB=0150for host in $HOSTS; do151case "$host" in152*darwin*) required_KiB=440000 ;;153*mingw*) required_KiB=7600000 ;;154*) required_KiB=6400000 ;;155esac156total_required_KiB=$((total_required_KiB+required_KiB))157done159if (( total_required_KiB > avail_KiB )); then160total_required_GiB=$((total_required_KiB / 1048576))161avail_GiB=$((avail_KiB / 1048576))162echo "Performing a Bitcoin Core Guix build for the selected HOSTS requires ${total_required_GiB} GiB, however, only ${avail_GiB} GiB is available. Please free up some disk space before performing the build."163exit 1164fi166################167# Check that we can connect to the guix-daemon168################170cat << EOF171Checking that we can connect to the guix-daemon...173Hint: If this hangs, you may want to try turning your guix-daemon off and on174again.176EOF177if ! guix gc --list-failures > /dev/null; then178cat << EOF180ERR: Failed to connect to the guix-daemon, please ensure that one is running and181reachable.182EOF183exit 1184fi186# Developer note: we could use `guix repl` for this check and run:187#188# (import (guix store)) (close-connection (open-connection))189#190# However, the internal API is likely to change more than the CLI invocation192################193# Services database must have basic entries194################196if ! getent services http https ftp > /dev/null 2>&1; then197cat << EOF198ERR: Your system's C library cannot find service database entries for at least199one of the following services: http, https, ftp.201Hint: Most likely, /etc/services does not exist yet (common for docker images202and minimal distros), or you don't have permissions to access it.204If /etc/services does not exist yet, you may want to install the205appropriate package for your distro which provides it.207On Debian/Ubuntu: netbase208On Arch Linux: iana-etc210For more information, see: getent(1), services(5)212EOF214fi216#########217# SETUP #218#########220# Determine the maximum number of jobs to run simultaneously (overridable by221# environment)222JOBS="${JOBS:-$(nproc)}"224# Usage: host_to_commonname HOST225#226# HOST: The current platform triple we're building for227#228host_to_commonname() {229case "$1" in230*darwin*) echo osx ;;231*mingw*) echo win ;;232*linux*) echo linux ;;233*) exit 1 ;;234esac235}237# Determine the reference time used for determinism (overridable by environment)238SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git -c log.showSignature=false log --format=%at -1)}"240# Precious directories are those which should not be cleaned between successive241# guix builds242depends_precious_dir_names="SOURCES_PATH BASE_CACHE SDK_PATH"243base_dir_names="OUTDIR_BASE PROFILES_BASE"244precious_dir_names="${depends_precious_dir_names} ${base_dir_names}"246# If the user explicitly specified a precious directory, create it so we247# can map it into the container248for precious_dir_name in $precious_dir_names; do249precious_dir_path="${!precious_dir_name}"250if [ -n "$precious_dir_path" ]; then
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.