Skip to content

Commit e26d1ba

Browse files
committed
Refactor cross compilation scripts
1 parent ec2a523 commit e26d1ba

8 files changed

+234
-145
lines changed

.ci/build_appimage.sh

+47-33
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ sudo ()
77
}
88

99
# Build
10-
if [[ "$1" != "0" ]]; then
11-
.ci/common/build.sh appimage_build linux || exit 1
12-
fi
10+
PLATFORM=$1
11+
.ci/common/build.sh appimage_build $PLATFORM || exit 1
1312

1413
repo_dir=$(pwd)
1514
cd appimage_build
@@ -45,45 +44,60 @@ cmake .. &&
4544
make -j$(nproc --all) &&
4645
mv src/linuxdeploy-plugin-appimage ../.. &&
4746
cd ../.. &&
48-
rm -rf plugin-appimage &&
49-
50-
# Build AppImageKit
51-
sudo apt install -y snapd squashfs-tools &&
52-
sudo snap install docker &&
53-
git clone https://github.com/AppImage/AppImageKit --recurse-submodules &&
54-
cd AppImageKit &&
55-
sudo env ARCH=$(arch) bash ci/build.sh
56-
sudo cp out/appimagetool /usr/bin/ &&
57-
sudo cp out/digest /usr/bin/ &&
58-
sudo cp out/validate /usr/bin/ &&
59-
cd .. &&
60-
sudo mkdir -p /usr/lib/appimagekit &&
61-
sudo ln -s /usr/bin/mksquashfs /usr/lib/appimagekit/mksquashfs &&
47+
rm -rf plugin-appimage
48+
49+
# Download appimagetool
50+
wget https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage &&
51+
mv appimagetool-*.AppImage appimagetool
52+
chmod +x appimagetool
53+
export PATH=$(pwd):$PATH
6254

6355
# Install patchelf from PyPI (see https://github.com/linuxdeploy/linuxdeploy-plugin-qt/issues/133#issuecomment-1608168363)
6456
sudo apt install -y python3-pip
57+
python3 -m venv .venv
58+
source .venv/bin/activate
6559
pip3 install patchelf
66-
export PATH=$PATH:~/.local/bin
60+
patchelf --version
61+
62+
# Use custom ldd and strip
63+
if [[ "$PLATFORM" == "linux_gcc_arm64" ]]; then
64+
ln -s /usr/bin/${BUILD_TOOLCHAIN_PREFIX}strip strip
65+
sudo cp ../.ci/bin/xldd /usr/bin/${BUILD_TOOLCHAIN_PREFIX}ldd
66+
ln -s /usr/bin/${BUILD_TOOLCHAIN_PREFIX}ldd ldd
67+
export CT_XLDD_ROOT="$BUILD_SYSROOT_PATH"
68+
fi
69+
70+
# Set LD_LIBRARY_PATH (directories with *.so files)
71+
LD_LIBRARY_PATH=""
72+
73+
for file in $(find . -type f -name "*.so"); do
74+
dir=$(dirname "$file")
75+
if [[ ":$LD_LIBRARY_PATH:" != *":$dir:"* ]]; then
76+
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`readlink -f $dir`"
77+
fi
78+
done
79+
80+
LD_LIBRARY_PATH=${LD_LIBRARY_PATH#:}
81+
export LD_LIBRARY_PATH
82+
echo "LD_LIBRARY_PATH set to: $LD_LIBRARY_PATH"
6783

6884
# Build AppImage
85+
if [[ "$PLATFORM" == "linux_gcc_arm64" ]]; then
86+
# TODO: Do not use AppImageKit releases, they're obsolete
87+
wget https://github.com/AppImage/AppImageKit/releases/download/continuous/runtime-aarch64
88+
export ARCH=arm_aarch64
89+
APPIMAGE_ARCH=aarch64
90+
export LDAI_RUNTIME_FILE=runtime-aarch64
91+
export QEMU_LD_PREFIX="$BUILD_SYSROOT_PATH"
92+
else
93+
APPIMAGE_ARCH=x86_64
94+
fi
95+
6996
export QML_SOURCES_PATHS=$(pwd)/src &&
70-
export EXTRA_QT_PLUGINS="svg;" &&
71-
export LDAI_UPDATE_INFORMATION="${appimage_zsync_prefix}${app_name}*-${APPIMAGE_ARCH-$(arch)}.AppImage.zsync"
97+
export EXTRA_QT_MODULES="qml;svg;" &&
98+
export LDAI_UPDATE_INFORMATION="${appimage_zsync_prefix}${app_name}*-${APPIMAGE_ARCH}.AppImage.zsync"
7299
echo "AppImage update information: ${LDAI_UPDATE_INFORMATION}"
73100

74-
case "$(qmake -query QMAKE_XSPEC)" in
75-
linux-arm-gnueabi-g++)
76-
wget https://github.com/AppImage/AppImageKit/releases/download/continuous/runtime-armhf
77-
export ARCH=arm
78-
export LDAI_RUNTIME_FILE=runtime-armhf
79-
;;
80-
linux-aarch64-gnu-g++)
81-
wget https://github.com/AppImage/AppImageKit/releases/download/continuous/runtime-aarch64
82-
export ARCH=arm_aarch64
83-
export LDAI_RUNTIME_FILE=runtime-aarch64
84-
;;
85-
esac
86-
87101
./linuxdeploy --appdir AppDir -e src/app/${executable_name} -i $repo_dir/res/${executable_name}.png -d $repo_dir/release/appimage.desktop --plugin qt --output appimage
88102

89103
mv *.AppImage* $repo_dir

.ci/build_qt6.sh

+27-71
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,48 @@
33
sudo apt install -y lsb-release
44

55
qt_version="$1"
6-
qt_modules="$(echo $2 | tr ' ' ',')"
6+
7+
if [[ "$2" == "" ]]; then
8+
qt_modules=""
9+
else
10+
qt_modules=",$(echo $2 | tr ' ' ',')"
11+
fi
12+
713
target_arch="$3"
814
root_path="$(pwd)"
9-
sysroot_path="${root_path}/sysroot"
10-
sysroot_ubuntu_version="$(lsb_release -rs).1"
11-
sysroot_ubuntu_codename="$(lsb_release -cs)"
12-
host_prefix="${root_path}/qt-host"
13-
cross_prefix="${root_path}/qt-cross"
15+
#host_prefix="${root_path}/qt-host"
16+
host_prefix="$QT_HOST_PATH"
17+
cross_prefix="$QT_CROSS_PATH"
1418
target_prefix="/usr/local/qt"
15-
toolchain_config="${root_path}/.ci/qt6-toolchain.cmake"
16-
17-
case "$target_arch" in
18-
aarch64)
19-
target_arch_name="armv8-a"
20-
toolchain_name="aarch64-linux-gnu"
21-
target_platform="linux-aarch64-gnu-g++"
22-
;;
23-
armv7)
24-
target_arch_name="armv7-a"
25-
toolchain_name="arm-linux-gnueabihf"
26-
target_platform="linux-arm-gnueabi-g++"
27-
;;
28-
esac
29-
30-
toolchain_prefix="${toolchain_name}-"
31-
32-
case "$target_arch" in
33-
aarch64)
34-
target_arch_debian_name="arm64"
35-
;;
36-
armv7)
37-
target_arch_debian_name="armhf"
38-
;;
39-
esac
4019

4120
echo "Qt version to build: ${qt_version}"
4221
echo "Qt modules: ${qt_modules}"
43-
echo "Target architecture: ${target_arch} (${target_arch_name})"
44-
45-
# Install dependencies
46-
${root_path}/.ci/qt6_deps.sh || exit 1
47-
${root_path}/.ci/install_cross_compiler.sh "${target_arch}" || exit 1
48-
sudo apt install -y qemu-user-static || exit 1
49-
sudo apt install -y symlinks || exit 1
22+
echo "Target architecture: ${target_arch} (${BUILD_ARCH_NAME})"
5023

5124
# Clone Qt
5225
git clone https://github.com/qt/qt5 qt || exit 1
5326
cd qt
54-
git checkout "v$qt_version" || exit 1
55-
./init-repository --module-subset=qtbase,qttools,qtdeclarative,qtsvg,${qt_modules} || exit 1
27+
git checkout $(git tag | grep '^v6\.8\.[0-9]*$' | sort -V | tail -n 1) || exit 1
28+
./init-repository --module-subset=qtbase,qttools,qtdeclarative,qtsvg${qt_modules} || exit 1
5629

5730
# Build Qt (host)
58-
mkdir host-build
59-
cd host-build
60-
echo "Building host Qt..."
61-
../configure -release -nomake examples -nomake tests -opensource -confirm-license -prefix "$host_prefix" || exit 1
62-
cmake --build . --parallel $(nproc --all) || exit 1
63-
echo "Installing host Qt..."
64-
cmake --install . || exit 1
65-
cd ..
66-
rm -rf host-build
67-
68-
# Prepare sysroot
69-
echo "Preparing sysroot..."
70-
curl "https://cdimage.ubuntu.com/ubuntu-base/releases/${sysroot_ubuntu_codename}/release/ubuntu-base-${sysroot_ubuntu_version}-base-${target_arch_debian_name}.tar.gz" > ./ubuntu-base.tar.gz || exit 1
71-
mkdir -p "$sysroot_path"
72-
sudo tar -xvzf ubuntu-base.tar.gz -C "$sysroot_path" || exit 1
73-
sudo update-binfmts --enable qemu-arm || exit 1
74-
sudo mount -o bind /dev "${sysroot_path}/dev" || exit 1
75-
sudo cp /etc/resolv.conf "${sysroot_path}/etc" || exit 1
76-
sudo chmod 1777 "${sysroot_path}/tmp" || exit 1
77-
sudo cp "${root_path}/.ci/qt6_deps.sh" "${sysroot_path}/"
78-
sudo chroot "$sysroot_path" /bin/bash -c "/qt6_deps.sh" || exit 1
79-
sudo chroot "$sysroot_path" /bin/bash -c "apt install -y symlinks && symlinks -rc /" || exit 1
31+
#mkdir host-build
32+
#cd host-build
33+
#echo "Building host Qt..."
34+
#../configure -release -nomake examples -nomake tests -opensource -confirm-license -prefix "$host_prefix" || exit 1
35+
#cmake --build . --parallel $(nproc --all) || exit 1
36+
#echo "Installing host Qt..."
37+
#cmake --install . || exit 1
38+
#cd ..
39+
#rm -rf host-build
8040

8141
# Build Qt (cross)
8242
mkdir cross-build
8343
cd cross-build
8444
echo "Cross-compiling Qt..."
85-
export BUILD_SYSROOT_PATH=${sysroot_path}
86-
export BUILD_TOOLCHAIN_NAME=${toolchain_name}
87-
export BUILD_TOOLCHAIN_PREFIX=${toolchain_prefix}
88-
export BUILD_ARCH_NAME=${target_arch_name}
89-
../configure -release -opengl es2 -nomake examples -nomake tests -qt-host-path "$host_prefix" -xplatform "$target_platform" \
90-
-device-option CROSS_COMPILE="$toolchain_prefix" -sysroot "$sysroot_path" -opensource -confirm-license \
91-
-prefix "$target_prefix" -extprefix "$cross_prefix" -- -DCMAKE_TOOLCHAIN_FILE="$toolchain_config" \
45+
../configure -release -opengl es2 -nomake examples -nomake tests -qt-host-path "$host_prefix" -xplatform "$BUILD_PLATFORM" \
46+
-device-option CROSS_COMPILE="$BUILD_TOOLCHAIN_PREFIX" -sysroot "$BUILD_SYSROOT_PATH" -opensource -confirm-license \
47+
-prefix "$target_prefix" -extprefix "$cross_prefix" -- -DCMAKE_TOOLCHAIN_FILE="$BUILD_TOOLCHAIN_CONFIG" \
9248
-DQT_FEATURE_xcb=ON -DFEATURE_xcb_xlib=ON -DQT_FEATURE_xlib=ON || exit 1
9349
cmake --build . --parallel $(nproc --all) || exit 1
9450
echo "Installing cross-compiled Qt..."
@@ -97,8 +53,8 @@ cd ..
9753
rm -rf cross-build
9854

9955
# Cleanup
100-
sudo umount "${sysroot_path}/dev" || exit 1
56+
sudo umount "${BUILD_SYSROOT_PATH}/dev" || exit 1
10157
cd ..
10258
rm -rf qt
10359
# Required for cache
104-
sudo chmod 777 -R ${sysroot_path}
60+
sudo chmod 777 -R ${BUILD_SYSROOT_PATH}

.ci/common/build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ mkdir -p "$BUILD_DIR"
1212

1313
if [[ "$PLATFORM" == "win64" ]] || [[ "$PLATFORM" == "win32" ]]; then
1414
cmake -B "$BUILD_DIR" -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DSCRATCHCPP_PLAYER_BUILD_UNIT_TESTS=OFF || exit 3
15+
elif [[ "$PLATFORM" == "linux_gcc_arm64" ]]; then
16+
cmake -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release -DSCRATCHCPP_PLAYER_BUILD_UNIT_TESTS=OFF -DCMAKE_PREFIX_PATH="$QT_ROOT_DIR" -DCMAKE_TOOLCHAIN_FILE="$BUILD_TOOLCHAIN_CONFIG" -DCMAKE_FIND_ROOT_PATH="$QT_ROOT_DIR" -DQT_HOST_PATH="$QT_HOST_PATH" -DQT_HOST_CMAKE_DIR="$QT_HOST_PATH/lib/cmake"
1517
else
1618
cmake -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release -DSCRATCHCPP_PLAYER_BUILD_UNIT_TESTS=OFF || exit 3
1719
fi

.ci/install_cross_compiler.sh

-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ case "$1" in
55
aarch64)
66
sudo apt install -y g++-aarch64-linux-gnu
77
;;
8-
armv7)
9-
sudo apt install -y g++-arm-linux-gnueabihf
108
esac

.ci/prepare_cross_build.sh

+43-27
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
11
#!/bin/bash
22

3+
sudo apt install -y lsb-release
4+
35
target_arch="$1"
6+
root_path="$(pwd)"
7+
sysroot_path="${root_path}/sysroot"
8+
sysroot_ubuntu_version="$(lsb_release -rs).1"
9+
sysroot_ubuntu_codename="$(lsb_release -cs)"
10+
cross_prefix="${root_path}/qt-cross"
11+
toolchain_config="${root_path}/.ci/qt6-toolchain.cmake"
412

513
case "$target_arch" in
614
aarch64)
7-
toolchain_prefix="aarch64-linux-gnu-"
8-
echo "APPIMAGE_ARCH=aarch64" >> "${GITHUB_ENV}"
9-
;;
10-
armv7)
11-
toolchain_prefix="arm-linux-gnueabihf-"
12-
echo "APPIMAGE_ARCH=armhf" >> "${GITHUB_ENV}"
15+
target_arch_name="armv8-a"
16+
target_arch_debian_name="arm64"
17+
toolchain_name="aarch64-linux-gnu"
18+
target_platform="linux-aarch64-gnu-g++"
1319
;;
1420
esac
1521

16-
echo "$(pwd)/qt-cross/bin:$(pwd)/qt-host/libexec" >> $GITHUB_PATH
17-
echo "LD_LIBRARY_PATH=$(pwd)/qt-cross/lib:$(pwd)/qt-host/lib" >> "${GITHUB_ENV}"
18-
.ci/install-cross-compiler.sh "$target_arch"
19-
.ci/qt6-dependencies.sh
20-
if [[ "$target_arch" == "armv7" ]]; then
21-
echo "QMAKE_CC=arm-linux-gnueabihf-gcc
22-
QMAKE_CXX=arm-linux-gnueabihf-g++
23-
QMAKE_LINK=arm-linux-gnueabihf-g++
24-
QMAKE_LINK_SHLIB=arm-linux-gnueabihf-g++
25-
QMAKE_AR=arm-linux-gnueabihf-ar cqs
26-
QMAKE_OBJCOPY=arm-linux-gnueabihf-objcopy
27-
QMAKE_NM=arm-linux-gnueabihf-nm -P
28-
QMAKE_STRIP=arm-linux-gnueabihf-strip" >> .qmake.conf
29-
fi
30-
31-
# Prepare cross-tools for linuxdeploy
32-
sudo cp /usr/bin/${toolchain_prefix}strip strip
33-
sudo mv /usr/bin/ldd /usr/bin/ldd-amd64
34-
sudo cp .ci/bin/xldd /usr/bin/${toolchain_prefix}ldd
35-
sudo ln -s /usr/bin/${toolchain_prefix}ldd /usr/bin/ldd
36-
echo "CT_XLDD_ROOT=$(pwd)/sysroot" >> "${GITHUB_ENV}"
22+
toolchain_prefix="${toolchain_name}-"
23+
24+
echo "Target architecture: ${target_arch} (${target_arch_name})"
25+
26+
# Install dependencies
27+
${root_path}/.ci/install_cross_compiler.sh "${target_arch}" || exit 1
28+
sudo apt install -y qemu-user-static || exit 1
29+
30+
# Prepare sysroot
31+
echo "Preparing sysroot..."
32+
curl "https://cdimage.ubuntu.com/ubuntu-base/releases/${sysroot_ubuntu_codename}/release/ubuntu-base-${sysroot_ubuntu_version}-base-${target_arch_debian_name}.tar.gz" > ./ubuntu-base.tar.gz || exit 1
33+
mkdir -p "$sysroot_path"
34+
sudo tar -xvzf ubuntu-base.tar.gz -C "$sysroot_path" || exit 1
35+
rm ubuntu-base.tar.gz
36+
sudo update-binfmts --enable qemu-arm || exit 1
37+
sudo mount -o bind /dev "${sysroot_path}/dev" || exit 1
38+
sudo cp /etc/resolv.conf "${sysroot_path}/etc" || exit 1
39+
sudo chmod 1777 "${sysroot_path}/tmp" || exit 1
40+
sudo cp "${root_path}/.ci/qt6_deps.sh" "${sysroot_path}/"
41+
sudo chroot "$sysroot_path" /bin/bash -c "/qt6_deps.sh" || exit 1
42+
sudo chroot "$sysroot_path" /bin/bash -c "apt update && apt install -y symlinks libssl-dev && symlinks -rc /" || exit 1
43+
sudo umount "${sysroot_path}/dev" || exit 1
44+
45+
# Prepare environment
46+
echo "BUILD_SYSROOT_PATH=$sysroot_path" >> "$GITHUB_ENV"
47+
echo "BUILD_TOOLCHAIN_NAME=$toolchain_name" >> "$GITHUB_ENV"
48+
echo "BUILD_TOOLCHAIN_PREFIX=$toolchain_prefix" >> "$GITHUB_ENV"
49+
echo "BUILD_TOOLCHAIN_CONFIG=$toolchain_config" >> "$GITHUB_ENV"
50+
echo "BUILD_ARCH_NAME=$target_arch_name" >> "$GITHUB_ENV"
51+
echo "BUILD_PLATFORM=$target_platform" >> "$GITHUB_ENV"
52+
echo "QT_ROOT_DIR=$cross_prefix" >> "$GITHUB_ENV"

0 commit comments

Comments
 (0)