0
0
mirror of https://notabug.org/litucks/torzu.git synced 2025-04-24 09:05:13 +00:00

Optionally use Clang for containerized AppImage build

This commit is contained in:
spectranator 2025-04-12 22:33:53 +02:00
parent a426de1c51
commit 76516783d3
2 changed files with 36 additions and 14 deletions

View File

@ -15,22 +15,24 @@ ulimit -n 50000
# Install dependencies # Install dependencies
apt -y install cmake ninja-build build-essential autoconf pkg-config locales wget git file mold libtool lsb-release wget software-properties-common gnupg \ apt -y install cmake ninja-build build-essential autoconf pkg-config locales wget git file mold libtool lsb-release wget software-properties-common gnupg \
qtbase5-dev qtmultimedia5-dev qtbase5-private-dev glslang-tools libssl-dev libavcodec-dev libavfilter-dev libavutil-dev libswscale-dev libpulse-dev libasound2-dev qtbase5-dev qtmultimedia5-dev qtbase5-private-dev glslang-tools libssl-dev libavcodec-dev libavfilter-dev libavutil-dev libswscale-dev libpulse-dev libasound2-dev
if ! [ "$BUILD_USE_CPM" = 1 ]; then if [ ! "$BUILD_USE_CPM" = 1 ]; then
apt -y install libfmt-dev libenet-dev liblz4-dev nlohmann-json3-dev zlib1g-dev libopus-dev libsimpleini-dev libstb-dev libzstd-dev libusb-1.0-0-dev libcubeb-dev libcpp-jwt-dev libvulkan-dev gamemode-dev libasound2-dev libglu1-mesa-dev libxext-dev mesa-common-dev libva-dev apt -y install libfmt-dev libenet-dev liblz4-dev nlohmann-json3-dev zlib1g-dev libopus-dev libsimpleini-dev libstb-dev libzstd-dev libusb-1.0-0-dev libcubeb-dev libcpp-jwt-dev libvulkan-dev gamemode-dev libasound2-dev libglu1-mesa-dev libxext-dev mesa-common-dev libva-dev
# Install Boost if [ ! -f /usr/local/lib/cmake/Boost-1.88.0/BoostConfigVersion.cmake ]; then
wget https://archives.boost.io/release/1.88.0/source/boost_1_88_0.tar.bz2 # Install Boost
echo "Extracting Boost sources..." wget https://archives.boost.io/release/1.88.0/source/boost_1_88_0.tar.bz2
tar xf boost_1_88_0.tar.bz2 echo "Extracting Boost sources..."
cd boost_1_88_0 tar xf boost_1_88_0.tar.bz2
./bootstrap.sh cd boost_1_88_0
./b2 install --with-{headers,context} link=static ./bootstrap.sh
cd .. ./b2 install --with-{headers,context} link=static
rm -rf boost_1_88_0 boost_1_88_0.tar.bz2 cd ..
rm -rf boost_1_88_0 boost_1_88_0.tar.bz2
fi
fi fi
# Install Clang # Install Clang
if ! clang-19 --version; then if ([ "$BUILD_USE_CLANG" = 1 ] && ! clang-19 --version); then
cd /tmp cd /tmp
wget https://apt.llvm.org/llvm.sh wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh chmod +x llvm.sh
@ -46,11 +48,17 @@ mount -t overlay overlay -olowerdir=torzu-src-ro,upperdir=torzu-src-upper,workdi
# Get extra configuration/compilation options # Get extra configuration/compilation options
EXTRA_COMPILE_FLAGS="" EXTRA_COMPILE_FLAGS=""
EXTRA_CMAKE_FLAGS="" EXTRA_CMAKE_FLAGS=""
if [ "$BUILD_USE_CLANG" = 1 ]; then
EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19"
FATLTO_FLAG="-flto=full"
else
FATLTO_FLAG="-flto"
fi
if [ "$BUILD_USE_THIN_LTO" = 1 ]; then if [ "$BUILD_USE_THIN_LTO" = 1 ]; then
EXTRA_COMPILE_FLAGS="-flto=thin" EXTRA_COMPILE_FLAGS="-flto=thin"
fi fi
if [ "$BUILD_USE_FAT_LTO" = 1 ]; then if [ "$BUILD_USE_FAT_LTO" = 1 ]; then
EXTRA_COMPILE_FLAGS="-flto=full" EXTRA_COMPILE_FLAGS="$FATLTO_FLAG"
fi fi
if [ "$BUILD_USE_CPM" = 1 ]; then if [ "$BUILD_USE_CPM" = 1 ]; then
EXTRA_CMAKE_FLAGS="-DYUZU_USE_CPM=ON" EXTRA_CMAKE_FLAGS="-DYUZU_USE_CPM=ON"
@ -60,7 +68,7 @@ fi
cd /tmp cd /tmp
mkdir torzu-build mkdir torzu-build
cd torzu-build cd torzu-build
cmake /tmp/torzu-src -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DYUZU_TESTS=OFF -DENABLE_QT_TRANSLATION=OFF -DSPIRV_WERROR=OFF -DCMAKE_FIND_LIBRARY_SUFFIXES=".a;.so" -DSPIRV-Headers_SOURCE_DIR=/tmp/torzu-src/externals/SPIRV-Headers -DCMAKE_{C,CXX}_FLAGS="${EXTRA_COMPILE_FLAGS} -fdata-sections -ffunction-sections" -DCMAKE_{EXE,SHARED}_LINKER_FLAGS="-Wl,--gc-sections" $EXTRA_CMAKE_FLAGS cmake /tmp/torzu-src -GNinja -DCMAKE_BUILD_TYPE=Release -DYUZU_TESTS=OFF -DENABLE_QT_TRANSLATION=OFF -DSPIRV_WERROR=OFF -DCMAKE_FIND_LIBRARY_SUFFIXES=".a;.so" -DSPIRV-Headers_SOURCE_DIR=/tmp/torzu-src/externals/SPIRV-Headers -DCMAKE_{C,CXX}_FLAGS="${EXTRA_COMPILE_FLAGS} -fdata-sections -ffunction-sections" -DCMAKE_{EXE,SHARED}_LINKER_FLAGS="-Wl,--gc-sections" $EXTRA_CMAKE_FLAGS
ninja || ( ninja || (
echo "Compilation has failed. Dropping you into a shell so you can inspect the situation. Run 'ninja' to retry and exit shell once compilation has finished successfully." echo "Compilation has failed. Dropping you into a shell so you can inspect the situation. Run 'ninja' to retry and exit shell once compilation has finished successfully."
echo "Note that any changes made here will not be reflected to the host environment, but changes made from the host environment will be reflected here." echo "Note that any changes made here will not be reflected to the host environment, but changes made from the host environment will be reflected here."

View File

@ -5,6 +5,10 @@ set -e
for i in "$@" for i in "$@"
do do
case $i in case $i in
-l|--clang)
export BUILD_USE_CLANG=1
echo "-> Using Clang for compilation."
;;
-o|--thin-lto) -o|--thin-lto)
export BUILD_USE_THIN_LTO=1 export BUILD_USE_THIN_LTO=1
echo "-> Thin link time optimization enabled." echo "-> Thin link time optimization enabled."
@ -22,12 +26,22 @@ case $i in
echo "-> Not deleting rootfs after successful build." echo "-> Not deleting rootfs after successful build."
;; ;;
*) *)
echo "Usage: $0 [--thin-lto/-o] [--fat-lto/-O] [--use-cpm/-p] [--keep-rootfs/-k]" echo "Usage: $0 [--clang/-l] [--thin-lto/-o] [--fat-lto/-O] [--use-cpm/-p] [--keep-rootfs/-k]"
exit 1 exit 1
;; ;;
esac esac
done done
# Make sure options are valid
if [ "$BUILD_USE_THIN_LTO" = 1 ] && [ "$BUILD_USE_CLANG" != 1 ]; then
echo "Thin LTO can't be used without Clang!"
exit 2
fi
if [ "$BUILD_USE_THIN_LTO" = 1 ] && [ "$BUILD_USE_FAT_LTO" = 1 ]; then
echo "Only either thin or fat LTO can be used!"
exit 2
fi
# Get torzu source dir # Get torzu source dir
TORZU_SOURCE_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" TORZU_SOURCE_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
echo "-> Source dir is $TORZU_SOURCE_DIR" echo "-> Source dir is $TORZU_SOURCE_DIR"