From 5940d86ed2f61f9fef8dc039954e518429100c97 Mon Sep 17 00:00:00 2001 From: Agel Date: Fri, 13 Nov 2026 08:37:05 +0100 Subject: [PATCH] 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. --- .gitlab-ci.yml | 23 +-- AGENTS.md | 4 +- CMakeLists.txt | 6 +- docker/Dockerfile.build | 22 +-- packaging/package-windows.sh | 8 +- scripts/download-mingw-arm64-qt.py | 222 +++++++++++++++++++++++++++++ scripts/verify-windows-dlls.py | 214 +++++++++++++++++++++++++++ 7 files changed, 467 insertions(+), 32 deletions(-) mode change 100644 => 100755 packaging/package-windows.sh create mode 100755 scripts/download-mingw-arm64-qt.py create mode 100755 scripts/verify-windows-dlls.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3797fdf..39fae72 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,15 +1,27 @@ +spec: + inputs: + FORCE_REBUILD_IMAGE: + description: "Force (true) or skip (false) building the runner image, even if files changed" + type: string + options: + - "auto" + - "true" + - "false" + default: "auto" +--- workflow: auto_cancel: on_new_commit: interruptible rules: - - if: $FORCE_REBUILD_IMAGE == "true" + - if: '"$[[ inputs.FORCE_REBUILD_IMAGE ]]" == "true" || $FORCE_REBUILD_IMAGE == "true"' variables: CI_PIPELINE_TYPE: image-rebuild - - if: $FORCE_REBUILD_IMAGE == "false" + - if: '"$[[ inputs.FORCE_REBUILD_IMAGE ]]" == "false" || $FORCE_REBUILD_IMAGE == "false"' variables: CI_PIPELINE_TYPE: normal - changes: - docker/Dockerfile.build + - scripts/download-mingw-arm64-qt.py - scripts/install-deps-ubuntu.sh - scripts/mingw-w64-toolchain.cmake - scripts/mingw-w64-arm64-toolchain.cmake @@ -26,13 +38,6 @@ stages: variables: GIT_CLEAN_FLAGS: -fdx - FORCE_REBUILD_IMAGE: - value: "auto" - options: - - "auto" - - "true" - - "false" - description: "Force (true) or skip (false) building the runner image, even if files changed" # ── Build the runner image and push to registry ──────────────────────────────── build-docker: diff --git a/AGENTS.md b/AGENTS.md index a63fc40..55cf4a5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -70,7 +70,7 @@ PATH="/c/msys64/opt/qt/6.10.3/mingw_64/bin:/c/msys64/mingw64/bin:$PATH" "C:/msys ``` ### Windows ARM64 Cross-Compilation Environment (Linux host / CI) -Cross-compiled using `llvm-mingw` (`aarch64-w64-mingw32`) and MSYS2 `clangarm64` Qt 6 / sysroot packages: +Cross-compiled using `llvm-mingw` (`aarch64-w64-mingw32`) and MSYS2 `clangarm64` Qt 6 / sysroot packages (transitive runtime dependencies resolved automatically via `scripts/download-mingw-arm64-qt.py`): ```bash PKG_CONFIG_PATH="/opt/mingw-arm64-sysroot/lib/pkgconfig" cmake -B build-windows-arm64 -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ @@ -80,7 +80,7 @@ PKG_CONFIG_PATH="/opt/mingw-arm64-sysroot/lib/pkgconfig" cmake -B build-windows- -DQT_HOST_PATH="/opt/qt/6.10.3/gcc_64" cmake --build build-windows-arm64 --target asteria-qt ``` -Packaging: +Packaging (includes automated PE binary DLL dependency verification via `scripts/verify-windows-dlls.py`): ```bash packaging/package-windows.sh build-windows-arm64 /opt/qt/6.10.3/mingw_arm64 /opt/mingw-arm64-sysroot dist arm64 ``` diff --git a/CMakeLists.txt b/CMakeLists.txt index 9224526..f2131e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,9 @@ find_package(Qt6 6.8 REQUIRED COMPONENTS Network ) qt_standard_project_setup(REQUIRES 6.8) -find_package(Qt6 OPTIONAL_COMPONENTS DBus) +if(UNIX AND NOT APPLE) + find_package(Qt6 OPTIONAL_COMPONENTS DBus) +endif() # Third-party libraries find_package(PkgConfig REQUIRED) @@ -180,7 +182,7 @@ target_link_libraries(asteria-qt PRIVATE ${UCHARDET_LIB} ) -if(Qt6DBus_FOUND) +if(UNIX AND NOT APPLE AND Qt6DBus_FOUND) target_link_libraries(asteria-qt PRIVATE Qt6::DBus) target_compile_definitions(asteria-qt PRIVATE HAS_QT_DBUS) target_sources(asteria-qt PRIVATE diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build index c7328c4..f908b09 100644 --- a/docker/Dockerfile.build +++ b/docker/Dockerfile.build @@ -49,24 +49,10 @@ RUN wget -q https://github.com/mstorsjo/llvm-mingw/releases/download/${LLVM_MING ENV PATH="${PATH}:/opt/llvm-mingw/bin" # ── Qt 6 for Windows ARM64 (MinGW cross-compile target) ──────────────────────── -RUN mkdir -p ${QT_INSTALL_DIR}/${QT_VERSION}/mingw_arm64 && \ - for pkg in \ - mingw-w64-clang-aarch64-qt6-base \ - mingw-w64-clang-aarch64-qt6-declarative \ - mingw-w64-clang-aarch64-qt6-svg \ - mingw-w64-clang-aarch64-qt6-5compat \ - mingw-w64-clang-aarch64-pcre2 \ - mingw-w64-clang-aarch64-double-conversion \ - mingw-w64-clang-aarch64-zstd \ - mingw-w64-clang-aarch64-brotli \ - mingw-w64-clang-aarch64-harfbuzz \ - mingw-w64-clang-aarch64-freetype \ - mingw-w64-clang-aarch64-libpng; do \ - file=$(curl -sL https://mirror.msys2.org/mingw/clangarm64/ | grep -o "${pkg}-[0-9][^\"]*pkg\.tar\.zst" | head -n 1) && \ - wget -q "https://mirror.msys2.org/mingw/clangarm64/${file}" -O /tmp/pkg.tar.zst && \ - tar -I zstd -xf /tmp/pkg.tar.zst --strip-components=1 -C "${QT_INSTALL_DIR}/${QT_VERSION}/mingw_arm64" && \ - rm /tmp/pkg.tar.zst; \ - done +COPY scripts/download-mingw-arm64-qt.py /tmp/download-mingw-arm64-qt.py +RUN chmod +x /tmp/download-mingw-arm64-qt.py && \ + python3 /tmp/download-mingw-arm64-qt.py --dest "${QT_INSTALL_DIR}/${QT_VERSION}/mingw_arm64" && \ + rm /tmp/download-mingw-arm64-qt.py # ── Toolchain files ──────────────────────────────────────────────────────────── COPY scripts/mingw-w64-toolchain.cmake /opt/mingw-w64-toolchain.cmake diff --git a/packaging/package-windows.sh b/packaging/package-windows.sh old mode 100644 new mode 100755 index c441ef0..f7c8941 --- a/packaging/package-windows.sh +++ b/packaging/package-windows.sh @@ -72,7 +72,9 @@ if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then libwinpthread-1.dll ) for dll in "${ARM64_DLLS[@]}"; do - find /opt/llvm-mingw/aarch64-w64-mingw32/ -name "$dll" -exec cp {} "$DIST_DIR/" \; 2>/dev/null || true + 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 @@ -108,6 +110,10 @@ 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/" diff --git a/scripts/download-mingw-arm64-qt.py b/scripts/download-mingw-arm64-qt.py new file mode 100755 index 0000000..4bc5f77 --- /dev/null +++ b/scripts/download-mingw-arm64-qt.py @@ -0,0 +1,222 @@ +#!/usr/bin/env python3 +""" +Downloads and extracts MSYS2 clangarm64 Qt6 packages and all transitive +runtime dependencies into the destination directory. + +Usage: + download-mingw-arm64-qt.py --dest /path/to/qt_arm64 [--dry-run] +""" + +import argparse +import io +import os +import re +import subprocess +import sys +import tarfile +import urllib.error +import urllib.request + +MIRROR_URLS = [ + "https://mirror.msys2.org/mingw/clangarm64", + "https://repo.msys2.org/mingw/clangarm64", +] + +SEEDS = [ + "mingw-w64-clang-aarch64-qt6-base", + "mingw-w64-clang-aarch64-qt6-declarative", + "mingw-w64-clang-aarch64-qt6-svg", + "mingw-w64-clang-aarch64-qt6-5compat", +] + +# Non-runtime / scripting packages not required by Qt6 C++ / QML applications +SKIP_SUBSTRINGS = ( + "python", + "tcl", + "tk", + "mpdecimal", +) + +EXPECTED_DLLS = [ + "Qt6Core.dll", + "Qt6Gui.dll", + "Qt6Qml.dll", + "Qt6Quick.dll", + "zlib1.dll", + "libzstd.dll", + "libmd4c.dll", + "libb2-1.dll", + "libfreetype-6.dll", + "libharfbuzz-0.dll", + "libpng16-16.dll", + "libglib-2.0-0.dll", +] + + +def fetch_url(url, timeout=30): + req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0 (Asteria-CI)"}) + with urllib.request.urlopen(req, timeout=timeout) as resp: + return resp.read() + + +def download_db(): + for mirror in MIRROR_URLS: + db_url = f"{mirror}/clangarm64.db.tar.zst" + print(f"==> Downloading package database from {db_url}...") + try: + data = fetch_url(db_url, timeout=30) + print(f"==> Downloaded database ({len(data)} bytes)") + return data, mirror + except Exception as e: + print(f" Failed ({e}), trying next mirror...", file=sys.stderr) + raise RuntimeError("Failed to download clangarm64.db.tar.zst from all mirrors") + + +def parse_database(db_bytes): + # Decompress zstd + res = subprocess.run(["zstd", "-d", "-c"], input=db_bytes, capture_output=True) + if res.returncode != 0: + raise RuntimeError(f"zstd decompression failed: {res.stderr.decode('utf-8', errors='replace')}") + + tar = tarfile.open(fileobj=io.BytesIO(res.stdout)) + packages = {} + provides_map = {} + + for member in tar.getmembers(): + if member.isfile() and member.name.endswith("/desc"): + f = tar.extractfile(member) + if not f: + continue + content = f.read().decode("utf-8", errors="replace") + pkg_name = None + filename = None + depends = [] + current_section = None + for line in content.splitlines(): + line = line.strip() + if line.startswith("%") and line.endswith("%"): + current_section = line[1:-1] + elif current_section == "NAME" and line: + pkg_name = line + elif current_section == "FILENAME" and line: + filename = line + elif current_section == "DEPENDS" and line: + dep = re.split(r"[<>=]", line)[0] + depends.append(dep) + elif current_section == "PROVIDES" and line: + prov = re.split(r"[<>=]", line)[0] + provides_map[prov] = pkg_name + + if pkg_name: + packages[pkg_name] = {"filename": filename, "depends": depends} + provides_map[pkg_name] = pkg_name + + return packages, provides_map + + +def resolve_dependencies(packages, provides_map): + queue = list(SEEDS) + visited = set(SEEDS) + resolved = [] + + while queue: + curr = queue.pop(0) + real_pkg = provides_map.get(curr, curr) + if any(skip in real_pkg for skip in SKIP_SUBSTRINGS): + continue + if real_pkg in packages: + visited.add(real_pkg) + resolved.append((real_pkg, packages[real_pkg]["filename"])) + for dep in packages[real_pkg]["depends"]: + dep_real = provides_map.get(dep, dep) + if any(skip in dep_real for skip in SKIP_SUBSTRINGS): + continue + if dep_real not in visited: + visited.add(dep_real) + queue.append(dep_real) + else: + print(f"Warning: dependency '{curr}' not found in database", file=sys.stderr) + + return sorted(resolved) + + +def download_and_extract_packages(resolved, base_mirror, dest_dir): + os.makedirs(dest_dir, exist_ok=True) + temp_pkg = "/tmp/arm64_pkg.tar.zst" + + for i, (pkg_name, filename) in enumerate(resolved, 1): + print(f"[{i}/{len(resolved)}] Downloading {filename}...") + downloaded = False + last_err = None + + for mirror in MIRROR_URLS: + pkg_url = f"{mirror}/{filename}" + try: + data = fetch_url(pkg_url, timeout=60) + with open(temp_pkg, "wb") as f: + f.write(data) + downloaded = True + break + except Exception as e: + last_err = e + print(f" Failed from {mirror} ({e}), trying next mirror...", file=sys.stderr) + + if not downloaded: + raise RuntimeError(f"Failed to download {filename}: {last_err}") + + # Extract stripping top-level directory (clangarm64) + tar_res = subprocess.run( + ["tar", "-I", "zstd", "-xf", temp_pkg, "--strip-components=1", "-C", dest_dir], + capture_output=True, + ) + if os.path.exists(temp_pkg): + os.remove(temp_pkg) + + if tar_res.returncode != 0: + err = tar_res.stderr.decode("utf-8", errors="replace") + raise RuntimeError(f"Failed to extract {filename}: {err}") + + +def verify_installation(dest_dir): + bin_dir = os.path.join(dest_dir, "bin") + if not os.path.isdir(bin_dir): + raise RuntimeError(f"Expected bin directory missing: {bin_dir}") + + missing = [] + for dll in EXPECTED_DLLS: + dll_path = os.path.join(bin_dir, dll) + if not os.path.isfile(dll_path): + missing.append(dll) + + if missing: + raise RuntimeError(f"Missing expected DLLs in {bin_dir}: {', '.join(missing)}") + + print(f"==> Verification passed: all {len(EXPECTED_DLLS)} required core DLLs present in {bin_dir}") + + +def main(): + parser = argparse.ArgumentParser(description="Download MSYS2 clangarm64 Qt6 packages and dependencies") + parser.add_argument("--dest", required=True, help="Destination directory to extract packages into") + parser.add_argument("--dry-run", action="store_true", help="Resolve packages without downloading or extracting") + args = parser.parse_args() + + db_bytes, mirror = download_db() + packages, provides_map = parse_database(db_bytes) + print(f"==> Parsed {len(packages)} packages from MSYS2 database") + + resolved = resolve_dependencies(packages, provides_map) + print(f"==> Resolved {len(resolved)} packages to install:") + for pkg_name, filename in resolved: + print(f" - {pkg_name} ({filename})") + + if args.dry_run: + print("==> Dry run complete.") + return + + download_and_extract_packages(resolved, mirror, args.dest) + verify_installation(args.dest) + print(f"==> Successfully installed Qt6 Windows ARM64 into {args.dest}") + + +if __name__ == "__main__": + main() diff --git a/scripts/verify-windows-dlls.py b/scripts/verify-windows-dlls.py new file mode 100755 index 0000000..bdbe146 --- /dev/null +++ b/scripts/verify-windows-dlls.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python3 +""" +Verifies that all PE DLL dependencies of an executable and its bundled plugins +are satisfied within the target distribution directory. + +Usage: + verify-windows-dlls.py /path/to/dist_dir +""" + +import os +import struct +import sys + +# Standard Windows system and runtime libraries (case-insensitive) +SYSTEM_DLLS = { + # Core OS & NT subsystems + "ntdll.dll", + "kernel32.dll", + "kernelbase.dll", + "user32.dll", + "gdi32.dll", + "gdiplus.dll", + "shell32.dll", + "shlwapi.dll", + "ole32.dll", + "oleaut32.dll", + "comdlg32.dll", + "comctl32.dll", + "advapi32.dll", + "version.dll", + "ws2_32.dll", + "wsock32.dll", + "netapi32.dll", + "userenv.dll", + "winmm.dll", + "uxtheme.dll", + "dwmapi.dll", + "imm32.dll", + "crypt32.dll", + "bcrypt.dll", + "ncrypt.dll", + "secur32.dll", + "sspicli.dll", + "setupapi.dll", + "cfgmgr32.dll", + "iphlpapi.dll", + "dnsapi.dll", + "rpcrt4.dll", + "mpr.dll", + "authz.dll", + "wtsapi32.dll", + "propsys.dll", + "powrprof.dll", + "winspool.drv", + "shcore.dll", + "hid.dll", + # Graphics & DirectX + "d3d9.dll", + "d3d11.dll", + "d3d12.dll", + "dxgi.dll", + "d2d1.dll", + "dwrite.dll", + "opengl32.dll", + "glu32.dll", + # CRT / UCRT + "msvcrt.dll", + "ucrtbase.dll", +} + + +def is_system_dll(name): + lower = name.lower() + if lower in SYSTEM_DLLS: + return True + if lower.startswith("api-ms-win-") or lower.startswith("ext-ms-win-"): + return True + return False + + +def get_pe_imports(file_path): + try: + with open(file_path, "rb") as f: + data = f.read() + except Exception as e: + print(f"Warning: could not read {file_path}: {e}", file=sys.stderr) + return [] + + if len(data) < 0x40 or data[:2] != b"MZ": + return [] + + pe_offset = struct.unpack_from(" len(data) or data[pe_offset:pe_offset+4] != b"PE\x00\x00": + return [] + + magic = struct.unpack_from(" len(data): + return [] + + import_rva, import_size = struct.unpack_from(" 5: + print(f" ... and {len(users) - 5} more", file=sys.stderr) + return False + + print(f"OK: Verified {checked_count} binaries. All external DLL imports satisfied ({len(available_dlls)} DLLs bundled).") + return True + + +def main(): + if len(sys.argv) < 2: + print("Usage: verify-windows-dlls.py ", file=sys.stderr) + sys.exit(2) + + dist_dir = sys.argv[1] + if not verify_dist_directory(dist_dir): + sys.exit(1) + + +if __name__ == "__main__": + main()