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 git guix26################27# Required env vars should be non-empty28################30cmd_usage() {31cat <<EOF32Synopsis:34env DETACHED_SIGS_REPO=<path/to/bitcoin-detached-sigs> \\35./contrib/guix/guix-codesign37EOF38}40if [ -z "$DETACHED_SIGS_REPO" ]; then41cmd_usage42exit 143fi45################46# GUIX_BUILD_OPTIONS should be empty47################48#49# GUIX_BUILD_OPTIONS is an environment variable recognized by guix commands that50# can perform builds. This seems like what we want instead of51# ADDITIONAL_GUIX_COMMON_FLAGS, but the value of GUIX_BUILD_OPTIONS is actually52# _appended_ to normal command-line options. Meaning that they will take53# precedence over the command-specific ADDITIONAL_GUIX_<CMD>_FLAGS.54#55# This seems like a poor user experience. Thus we check for GUIX_BUILD_OPTIONS's56# existence here and direct users of this script to use our (more flexible)57# custom environment variables.58if [ -n "$GUIX_BUILD_OPTIONS" ]; then59cat << EOF60Error: Environment variable GUIX_BUILD_OPTIONS is not empty:61'$GUIX_BUILD_OPTIONS'63Unfortunately this script is incompatible with GUIX_BUILD_OPTIONS, please unset64GUIX_BUILD_OPTIONS and use ADDITIONAL_GUIX_COMMON_FLAGS to set build options65across guix commands or ADDITIONAL_GUIX_<CMD>_FLAGS to set build options for a66specific guix command.68See contrib/guix/README.md for more details.69EOF70exit 171fi73################74# SOURCE_DATE_EPOCH should not unintentionally be set75################77check_source_date_epoch79################80# The codesignature git worktree should not be dirty81################83if ! git -C "$DETACHED_SIGS_REPO" diff-index --quiet HEAD -- && [ -z "$FORCE_DIRTY_WORKTREE" ]; then84cat << EOF85ERR: The DETACHED CODESIGNATURE git worktree is dirty, which may lead to broken builds.87Aborting...89Hint: To make your git worktree clean, You may want to:901. Commit your changes,912. Stash your changes, or923. Set the 'FORCE_DIRTY_WORKTREE' environment variable if you insist on93using a dirty worktree94EOF95exit 196fi98################99# Build directories should not exist100################102# Default to building for all supported HOSTs (overridable by environment)103export HOSTS="${HOSTS:-x86_64-w64-mingw32 x86_64-apple-darwin arm64-apple-darwin}"105# Accumulate a list of build directories that already exist...106hosts_distsrc_exists=""107for host in $HOSTS; do108if [ -e "$(distsrc_for_host "$host" codesigned)" ]; then109hosts_distsrc_exists+=" ${host}"110fi111done113if [ -n "$hosts_distsrc_exists" ]; then114# ...so that we can print them out nicely in an error message115cat << EOF116ERR: Build directories for this commit already exist for the following platform117triples you're attempting to build, probably because of previous builds.118Please remove, or otherwise deal with them prior to starting another build.120Aborting...122Hint: To blow everything away, you may want to use:124$ ./contrib/guix/guix-clean126Specifically, this will remove all files without an entry in the index,127excluding the SDK directory, the depends download cache, the depends built128packages cache, the garbage collector roots for Guix environments, and the129output directory.130EOF131for host in $hosts_distsrc_exists; do132echo " ${host} '$(distsrc_for_host "$host" codesigned)'"133done134exit 1135else136mkdir -p "$DISTSRC_BASE"137fi140################141# Codesigning tarballs SHOULD exist142################144# Usage: codesigning_tarball_for_host HOST [BASE]145#146# HOST: The current platform triple we're building for147# BASE: Optional. If provided, replaces ${OUTDIR_BASE}148#149codesigning_tarball_for_host() {150case "$1" in151*mingw*)152echo "$(outdir_for_host "$1" "" "$2")/${DISTNAME}-win64-codesigning.tar.gz"153;;154*darwin*)155echo "$(outdir_for_host "$1" "" "$2")/${DISTNAME}-${1}-codesigning.tar.gz"156;;157*)158exit 1159;;160esac161}163# Accumulate a list of build directories that already exist...164hosts_codesigning_tarball_missing=""165for host in $HOSTS; do166if [ ! -e "$(codesigning_tarball_for_host "$host")" ]; then167hosts_codesigning_tarball_missing+=" ${host}"168fi169done171if [ -n "$hosts_codesigning_tarball_missing" ]; then172# ...so that we can print them out nicely in an error message173cat << EOF174ERR: Codesigning tarballs do not exist175...177EOF178for host in $hosts_codesigning_tarball_missing; do179echo " ${host} '$(codesigning_tarball_for_host "$host")'"180done181exit 1182fi184################185# Check that we can connect to the guix-daemon186################188cat << EOF189Checking that we can connect to the guix-daemon...191Hint: If this hangs, you may want to try turning your guix-daemon off and on192again.194EOF195if ! guix gc --list-failures > /dev/null; then196cat << EOF198ERR: Failed to connect to the guix-daemon, please ensure that one is running and199reachable.200EOF201exit 1202fi204# Developer note: we could use `guix repl` for this check and run:205#206# (import (guix store)) (close-connection (open-connection))207#208# However, the internal API is likely to change more than the CLI invocation211#########212# SETUP #213#########215# Determine the maximum number of jobs to run simultaneously (overridable by216# environment)217JOBS="${JOBS:-$(nproc)}"219# Determine the reference time used for determinism (overridable by environment)220SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(git -c log.showSignature=false log --format=%at -1)}"222# Make sure an output directory exists for our builds223OUTDIR_BASE="${OUTDIR_BASE:-${VERSION_BASE}/output}"224mkdir -p "$OUTDIR_BASE"226#########227# BUILD #228#########230# Function to be called when codesigning for host ${1} and the user interrupts231# the codesign232int_trap() {233cat << EOF234** INT received while codesigning ${1}, you may want to clean up the relevant235work directories (e.g. distsrc-*) before recodesigning237Hint: To blow everything away, you may want to use:239$ ./contrib/guix/guix-clean241Specifically, this will remove all files without an entry in the index,242excluding the SDK directory, the depends download cache, the depends built243packages cache, the garbage collector roots for Guix environments, and the244output directory.245EOF246}248# Deterministically build Bitcoin Core249# shellcheck disable=SC2153250for host in $HOSTS; do
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.