Last active
October 7, 2025 12:48
-
-
Save willcl-ark/dae846d53d1ef120ba91d26a8c7182b4 to your computer and use it in GitHub Desktop.
Cross-compile freebsd using clang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| export HOST=x86_64-unknown-freebsd | |
| export FREEBSD_SYSROOT=/opt/cross-freebsd-14 | |
| export FREEBSD_VERSION="14.2" | |
| CLANG_REQUIRED="18" | |
| export CFLAGS="--sysroot=$FREEBSD_SYSROOT" | |
| export CXXFLAGS="--sysroot=$FREEBSD_SYSROOT" | |
| export LDFLAGS="--sysroot=$FREEBSD_SYSROOT" | |
| # Check Clang version - must match FreeBSD sysroot clang version which is clang18 for FreeBSD 14.2 | |
| CLANG_VERSION=$(clang --version | head -n1 | sed 's/.*clang version \([0-9]\+\).*/\1/') | |
| if [ "$CLANG_VERSION" != "$CLANG_REQUIRED" ]; then | |
| echo "ERROR: Clang version $CLANG_VERSION detected, but version $CLANG_REQUIRED is required" | |
| echo "The FreeBSD sysroot contains Clang $CLANG_REQUIRED intrinsics headers that must match the compiler version" | |
| exit 1 | |
| fi | |
| echo "Using Clang $CLANG_VERSION (compatible with FreeBSD sysroot)" | |
| # Get sysroot | |
| if [ ! -f "$FREEBSD_SYSROOT/base.txz" ]; then | |
| mkdir -p "$FREEBSD_SYSROOT" | |
| cd "$FREEBSD_SYSROOT" | |
| wget "http://ftp.plusline.de/FreeBSD/releases/amd64/$FREEBSD_VERSION-RELEASE/base.txz" | |
| tar -xf base.txz | |
| fi | |
| # Build depends | |
| make -C depends -j14 HOST=$HOST NO_QT=1 | |
| # Generate build system | |
| cmake -B build \ | |
| --toolchain "depends/$HOST/toolchain.cmake" \ | |
| -DCMAKE_SYSROOT=/opt/cross-freebsd-14 \ | |
| -DCMAKE_CXX_FLAGS="-isystem/opt/cross-freebsd-14/usr/lib/clang/18/include" | |
| # Build bitcoind | |
| cmake --build build --parallel --target bitcoind |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment