From 81e2ed075ec9911941e3db8b9ff32475591be4d8 Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sun, 18 Oct 2026 21:58:23 +0200 Subject: [PATCH] Build AUR packages with clang and ThinLTO by default aurb now builds with clang + lld + ThinLTO and bind-mounts a ThinLTO cache and its clang.cfg into the chroot; --gcc keeps the old gcc build. update-kernel still uses gcc. --- .config/aurb/clang.cfg | 5 +++++ .config/aurutils-makepkg.conf | 10 ++++++++++ .local/bin/aurb | 30 ++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 .config/aurb/clang.cfg diff --git a/.config/aurb/clang.cfg b/.config/aurb/clang.cfg new file mode 100644 index 0000000..67df15c --- /dev/null +++ b/.config/aurb/clang.cfg @@ -0,0 +1,5 @@ +# clang options for aurb chroot builds (CC/CXX pass --config=, see aurutils-makepkg.conf). +# Here rather than in LDFLAGS: old libtool (<2.4.7) drops -fuse-ld=lld, and these then reach GNU ld. +-fuse-ld=lld +-Wl,--thinlto-cache-dir=/home/fuxino/.cache/thinlto +-Wl,--thinlto-cache-policy=cache_size_bytes=10g diff --git a/.config/aurutils-makepkg.conf b/.config/aurutils-makepkg.conf index 3f1fbe9..b091628 100644 --- a/.config/aurutils-makepkg.conf +++ b/.config/aurutils-makepkg.conf @@ -166,4 +166,14 @@ SRCEXT='.src.tar.gz' #-- Command used to run pacman as root, instead of trying sudo and su #PACMAN_AUTH=() export CCACHE_DIR=/home/fuxino/.cache/ccache + +# clang + lld + ThinLTO, only when aurb prepends AURB_CLANG=1 (its default; `aurb --gcc` doesn't). +# update-kernel uses this file as is, so the kernels stay on gcc. Linker flags live in clang.cfg +# (lld + ThinLTO cache); aurb bind-mounts its dir and the ThinLTO cache dir. +if [[ -n ${AURB_CLANG-} ]]; then + export CC="clang --config=/home/fuxino/.config/aurb/clang.cfg" + export CXX="clang++ --config=/home/fuxino/.config/aurb/clang.cfg" + export AR=llvm-ar NM=llvm-nm RANLIB=llvm-ranlib + LTOFLAGS="-flto=thin" +fi # vim: set ft=sh ts=2 sw=2 et: diff --git a/.local/bin/aurb b/.local/bin/aurb index 35b3498..6efb036 100755 --- a/.local/bin/aurb +++ b/.local/bin/aurb @@ -1,15 +1,33 @@ #!/bin/bash -# aurb / aurs: aur build / aur sync with ccache mounted in the chroot (use with -c) +# aurb / aurs: aur build / aur sync with ccache and the ThinLTO cache mounted in the chroot (use with -c). +# Builds with clang by default (see aurutils-makepkg.conf); --gcc builds with gcc instead. case "$(basename "$0")" in aurb) cmd=build ;; aurs) cmd=sync ;; *) echo "Invoke as aurb or aurs" >&2; exit 1 ;; esac -CCACHE_HOST_DIR="$HOME/.cache/ccache" -mkdir -p "$CCACHE_HOST_DIR" +baseconf="$HOME/.config/aurutils-makepkg.conf" +args=() +clang=1 +for arg in "$@"; do + if [[ $arg == --gcc ]]; then clang=0; else args+=("$arg"); fi +done -exec aur "$cmd" \ - --makepkg-conf "$HOME/.config/aurutils-makepkg.conf" \ +conf=$baseconf +if ((clang)); then + conf=$(mktemp "${XDG_RUNTIME_DIR:-/tmp}/aurb-clang.XXXXXX.conf") || exit 1 + trap 'rm -f "$conf"' EXIT + { echo 'AURB_CLANG=1'; cat "$baseconf"; } > "$conf" +fi + +CCACHE_HOST_DIR="$HOME/.cache/ccache" +THINLTO_HOST_DIR="$HOME/.cache/thinlto" +mkdir -p "$CCACHE_HOST_DIR" "$THINLTO_HOST_DIR" + +aur "$cmd" \ + --makepkg-conf "$conf" \ --bind-rw "$CCACHE_HOST_DIR" \ - "$@" + --bind-rw "$THINLTO_HOST_DIR" \ + --bind "$HOME/.config/aurb" \ + "${args[@]}"