#!/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()