Skip to content

Commit

Permalink
cmake: Migrate Guix build scripts to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jan 26, 2024
1 parent 1e3dae6 commit 25fb8c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
8 changes: 5 additions & 3 deletions contrib/guix/guix-build
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ mkdir -p "$VERSION_BASE"
################

# Default to building for all supported HOSTs (overridable by environment)
export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu powerpc64le-linux-gnu
x86_64-w64-mingw32
x86_64-apple-darwin arm64-apple-darwin}"
# TODO: Re-enable Windows and macOS hosts.
# export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu powerpc64le-linux-gnu
# x86_64-w64-mingw32
# x86_64-apple-darwin arm64-apple-darwin}"
export HOSTS="${HOSTS:-x86_64-linux-gnu arm-linux-gnueabihf aarch64-linux-gnu riscv64-linux-gnu powerpc64-linux-gnu powerpc64le-linux-gnu}"

# Usage: distsrc_for_host HOST
#
Expand Down
45 changes: 17 additions & 28 deletions contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ esac
####################

# Build the depends tree, overriding variables that assume multilib gcc
# TODO: Drop NO_QT=1
make -C depends --jobs="$JOBS" HOST="$HOST" \
NO_QT=1 \
${V:+V=1} \
${SOURCES_PATH+SOURCES_PATH="$SOURCES_PATH"} \
${BASE_CACHE+BASE_CACHE="$BASE_CACHE"} \
Expand Down Expand Up @@ -215,7 +217,8 @@ mkdir -p "$OUTDIR"
###########################

# CONFIGFLAGS
CONFIGFLAGS="--enable-reduce-exports --disable-bench --disable-gui-tests --disable-fuzz-binary"
# TODO: Re-add CMake's analogue of --disable-gui-tests.
CONFIGFLAGS="-DREDUCE_EXPORTS=ON -DBUILD_BENCH=OFF -DBUILD_FUZZ_BINARY=OFF"

# CFLAGS
HOST_CFLAGS="-O2 -g"
Expand Down Expand Up @@ -248,31 +251,23 @@ mkdir -p "$DISTSRC"
# Extract the source tarball
tar --strip-components=1 -xf "${GIT_ARCHIVE}"

./autogen.sh

# Configure this DISTSRC for $HOST
# shellcheck disable=SC2086
env CONFIG_SITE="${BASEPREFIX}/${HOST}/share/config.site" \
./configure --prefix=/ \
--disable-ccache \
--disable-maintainer-mode \
--disable-dependency-tracking \
${CONFIGFLAGS} \
${HOST_CFLAGS:+CFLAGS="${HOST_CFLAGS}"} \
${HOST_CXXFLAGS:+CXXFLAGS="${HOST_CXXFLAGS}"} \
${HOST_LDFLAGS:+LDFLAGS="${HOST_LDFLAGS}"}

sed -i.old 's/-lstdc++ //g' config.status libtool
env CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}" LDFLAGS="${HOST_LDFLAGS}" \
cmake -S . -B build \
--toolchain "${BASEPREFIX}/${HOST}/share/toolchain.cmake" \
-DCCACHE=OFF \
${CONFIGFLAGS}

# Build Bitcoin Core
make --jobs="$JOBS" ${V:+V=1}
cmake --build build -j "$JOBS" ${V:+--verbose}

# Check that symbol/security checks tools are sane.
make test-security-check ${V:+V=1}
cmake --build build --target test-security-check ${V:+--verbose}
# Perform basic security checks on a series of executables.
make -C src --jobs=1 check-security ${V:+V=1}
cmake --build build -j 1 --target check-security ${V:+--verbose}
# Check that executables only contain allowed version symbols.
make -C src --jobs=1 check-symbols ${V:+V=1}
cmake --build build -j 1 --target check-symbols ${V:+--verbose}

mkdir -p "$OUTDIR"

Expand All @@ -294,7 +289,7 @@ mkdir -p "$DISTSRC"
make install-strip DESTDIR="${INSTALLPATH}" ${V:+V=1}
;;
*)
make install DESTDIR="${INSTALLPATH}" ${V:+V=1}
cmake --install build --prefix "${INSTALLPATH}" ${V:+--verbose}
;;
esac

Expand Down Expand Up @@ -327,21 +322,15 @@ mkdir -p "$DISTSRC"
;;
esac

# Prune libtool and object archives
find . -name "lib*.la" -delete
find . -name "lib*.a" -delete

# Prune pkg-config files
rm -rf "${DISTNAME}/lib/pkgconfig"

case "$HOST" in
*darwin*) ;;
*)
# Split binaries and libraries from their debug symbols
# TODO: Re-enable code for libbitcoinkernel.
{
find "${DISTNAME}/bin" -type f -executable -print0
find "${DISTNAME}/lib" -type f -print0
} | xargs -0 -P"$JOBS" -I{} "${DISTSRC}/contrib/devtools/split-debug.sh" {} {} {}.dbg
# find "${DISTNAME}/lib" -type f -print0
} | xargs -0 -P"$JOBS" -I{} "${DISTSRC}/build/split-debug.sh" {} {} {}.dbg
;;
esac

Expand Down
3 changes: 2 additions & 1 deletion contrib/guix/manifest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ inspecting signatures in Mach-O binaries.")
gzip
xz
;; Build tools
cmake-minimal
gnu-make
libtool
autoconf-2.71
Expand All @@ -525,5 +526,5 @@ inspecting signatures in Mach-O binaries.")
((string-contains target "-linux-")
(list (make-bitcoin-cross-toolchain target)))
((string-contains target "darwin")
(list clang-toolchain-17 binutils cmake-minimal python-signapple zip))
(list clang-toolchain-17 binutils python-signapple zip))
(else '())))))

0 comments on commit 25fb8c4

Please sign in to comment.