Files
asteria-qt/packaging/package-windows.sh
T
Agel 5940d86ed2 ci: resolve missing Windows ARM64 runtime DLLs and add pipeline inputs
The Windows ARM64 release package failed to launch on startup due to missing
runtime DLLs (libdbus-1-3.dll, libmd4c.dll, zlib1.dll, libzstd.dll).

This failure stemmed from several architectural and CI pipeline issues:
1. CMake unconditionally linked Qt6::DBus whenever available in the sysroot,
   introducing an unnecessary dependency on Qt6DBus.dll and libdbus-1-3.dll
   on Windows, even though D-Bus portal dialogs are only used on Linux.
2. The Docker build environment installed MSYS2 ARM64 Qt packages via an
   unchecked shell loop against a hardcoded package list. This missed crucial
   transitive runtime dependencies (such as md4c, zlib-ng-compat, libb2, and
   ICU) and failed silently when downloads or extractions broke.
3. Windows packaging lacked PE import verification, allowing broken packages
   with unresolved dynamic links to be produced and published without warning.

To fix these issues and make image management more accessible:
- Restrict Qt6::DBus detection and linking in CMakeLists.txt to Linux only,
  eliminating the D-Bus dependency from Windows builds.
- Introduce scripts/download-mingw-arm64-qt.py to parse the MSYS2 clangarm64
  database, resolve the complete transitive dependency graph, and verify
  essential runtime DLLs during the Docker image build.
- Introduce scripts/verify-windows-dlls.py and integrate it into
  packaging/package-windows.sh to validate PE imports across the executable
  and bundled Qt plugins, failing packaging if any non-system DLL is missing.
- Expose FORCE_REBUILD_IMAGE as a typed GitLab CI pipeline input (spec: inputs)
  to provide an interactive dropdown when triggering manual pipelines in the UI,
  and trigger container rebuilds when the download script changes.
- Update AGENTS.md documentation to reflect the new dependency and packaging
  verification workflows.
2026-11-13 08:37:05 +01:00

120 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Package Windows build as a portable directory with all DLLs
# Usage: package-windows.sh <build-dir> <qt-dir> <mingw-sysroot> <output-dir> [arch]
set -euo pipefail
BUILD_DIR="${1:?Usage: package-windows.sh <build-dir> <qt-dir> <mingw-sysroot> <output-dir> [arch]}"
QT_DIR="${2:?}"
MINGW_SYSROOT="${3:?}"
OUTPUT_DIR="${4:?}"
ARCH="${5:-x86_64}"
PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
DIST_DIR="${BUILD_DIR}/dist"
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
# Copy the main executable
cp "$BUILD_DIR/asteria-qt.exe" "$DIST_DIR/"
# Use windeployqt to gather Qt dependencies
# windeployqt6 from the cross-compiled Qt may not work on Linux host,
# so we manually copy the required DLLs
# Qt DLLs — copy all Qt6*.dll and related runtime DLLs from Qt bin directory
cp "$QT_DIR/bin/"*.dll "$DIST_DIR/" 2>/dev/null || true
# Qt plugins (support standard Qt layout and MSYS2 share/qt6 layout)
PLUGIN_DIR="$QT_DIR/plugins"
if [ ! -d "$PLUGIN_DIR" ] && [ -d "$QT_DIR/share/qt6/plugins" ]; then
PLUGIN_DIR="$QT_DIR/share/qt6/plugins"
fi
mkdir -p "$DIST_DIR/platforms"
cp "$PLUGIN_DIR/platforms/qwindows.dll" "$DIST_DIR/platforms/" 2>/dev/null || true
mkdir -p "$DIST_DIR/imageformats"
cp "$PLUGIN_DIR/imageformats/"*.dll "$DIST_DIR/imageformats/" 2>/dev/null || true
mkdir -p "$DIST_DIR/iconengines"
cp "$PLUGIN_DIR/iconengines/"*.dll "$DIST_DIR/iconengines/" 2>/dev/null || true
mkdir -p "$DIST_DIR/tls"
cp "$PLUGIN_DIR/tls/"*.dll "$DIST_DIR/tls/" 2>/dev/null || true
if [ -d "$PLUGIN_DIR/styles" ]; then
mkdir -p "$DIST_DIR/styles"
cp "$PLUGIN_DIR/styles/"*.dll "$DIST_DIR/styles/" 2>/dev/null || true
fi
# QML modules (support standard Qt layout and MSYS2 share/qt6 layout)
QML_DIR="$QT_DIR/qml"
if [ ! -d "$QML_DIR" ] && [ -d "$QT_DIR/share/qt6/qml" ]; then
QML_DIR="$QT_DIR/share/qt6/qml"
fi
mkdir -p "$DIST_DIR/qml"
for mod in QtCore Qt QtQuick QtQml Qt5Compat; do
if [ -d "$QML_DIR/$mod" ]; then
cp -r "$QML_DIR/$mod" "$DIST_DIR/qml/"
fi
done
# Architecture-specific runtime DLLs
if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then
PKG_NAME="asteria-qt-windows-arm64"
# LLVM-MinGW runtime DLLs for ARM64
ARM64_DLLS=(
libc++.dll
libunwind.dll
libwinpthread-1.dll
)
for dll in "${ARM64_DLLS[@]}"; do
if [ ! -f "$DIST_DIR/$dll" ]; then
find /opt/llvm-mingw/aarch64-w64-mingw32/ -name "$dll" -exec cp {} "$DIST_DIR/" \; 2>/dev/null || true
fi
if [ ! -f "$DIST_DIR/$dll" ] && [ -f "$MINGW_SYSROOT/bin/$dll" ]; then
cp "$MINGW_SYSROOT/bin/$dll" "$DIST_DIR/"
fi
done
else
PKG_NAME="asteria-qt-windows"
# MinGW-w64 runtime DLLs for x86_64
MINGW_DLLS=(
libgcc_s_seh-1.dll
libstdc++-6.dll
libwinpthread-1.dll
)
for dll in "${MINGW_DLLS[@]}"; do
find /usr/lib/gcc/x86_64-w64-mingw32/ -name "$dll" -exec cp {} "$DIST_DIR/" \; 2>/dev/null || true
if [ ! -f "$DIST_DIR/$dll" ] && [ -f "/usr/x86_64-w64-mingw32/lib/$dll" ]; then
cp "/usr/x86_64-w64-mingw32/lib/$dll" "$DIST_DIR/"
fi
done
fi
# Third-party DLLs from sysroot (if dynamically built)
if [ -f "$MINGW_SYSROOT/lib/libuchardet.dll" ]; then
cp "$MINGW_SYSROOT/lib/libuchardet.dll" "$DIST_DIR/"
elif [ -f "$MINGW_SYSROOT/bin/libuchardet.dll" ]; then
cp "$MINGW_SYSROOT/bin/libuchardet.dll" "$DIST_DIR/"
fi
# Create qt.conf for portable deployment
cat > "$DIST_DIR/qt.conf" << 'EOF'
[Paths]
Plugins = .
Qml2Imports = qml
EOF
# Verify all PE binary dependencies in DIST_DIR
echo "==> Verifying bundled DLL dependencies in $DIST_DIR..."
python3 "$PROJECT_DIR/scripts/verify-windows-dlls.py" "$DIST_DIR"
# Output flat directory — GitLab zips the artifact directory on download
mkdir -p "$OUTPUT_DIR/$PKG_NAME"
cp -r "$DIST_DIR/"* "$OUTPUT_DIR/$PKG_NAME/"