moar ci changes

This commit is contained in:
Agel committed 2026-11-13 10:56:08 +01:00
1 parent 5940d86ed2
commit 1ef94b910a
19 files changed
+1313 -663

No files matched your search

+130 -49
View File
@@ -1,32 +1,51 @@
#!/usr/bin/env python3
"""
Downloads and extracts MSYS2 clangarm64 Qt6 packages and all transitive
runtime dependencies into the destination directory.
Downloads and extracts MSYS2 MinGW-w64 (clang64 / clangarm64) Qt6 packages,
third-party libraries (libarchive, libiconv, minizip, uchardet, zlib), and all
transitive runtime dependencies into the destination sysroot directory.
Usage:
download-mingw-arm64-qt.py --dest /path/to/qt_arm64 [--dry-run]
download-mingw-arm64-qt.py --dest /path/to/sysroot [--arch {x86_64,arm64}] [--dry-run]
"""
import argparse
import glob
import io
import os
import re
import shutil
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",
ARCH_CONFIG = {
"x86_64": {
"repo": "clang64",
"pkg_prefix": "mingw-w64-clang-x86_64",
},
"arm64": {
"repo": "clangarm64",
"pkg_prefix": "mingw-w64-clang-aarch64",
},
}
MIRROR_BASES = [
"https://mirror.msys2.org/mingw",
"https://repo.msys2.org/mingw",
]
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",
SEED_PACKAGES = [
"qt6-base",
"qt6-declarative",
"qt6-svg",
"qt6-imageformats",
"libarchive",
"libiconv",
"minizip",
"uchardet",
"zlib",
]
# Non-runtime / scripting packages not required by Qt6 C++ / QML applications
@@ -42,6 +61,13 @@ EXPECTED_DLLS = [
"Qt6Gui.dll",
"Qt6Qml.dll",
"Qt6Quick.dll",
"Qt6Svg.dll",
"Qt6Widgets.dll",
"Qt6Network.dll",
"libarchive-13.dll",
"libiconv-2.dll",
"libminizip-1.dll",
"libuchardet.dll",
"zlib1.dll",
"libzstd.dll",
"libmd4c.dll",
@@ -50,30 +76,37 @@ EXPECTED_DLLS = [
"libharfbuzz-0.dll",
"libpng16-16.dll",
"libglib-2.0-0.dll",
"libc++.dll",
"libunwind.dll",
]
EXPECTED_PC_FILES = [
"minizip.pc",
"libarchive.pc",
"uchardet.pc",
]
def fetch_url(url, timeout=30):
def fetch_url(url, timeout=60):
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"
def download_db(repo):
for base in MIRROR_BASES:
db_url = f"{base}/{repo}/{repo}.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
return data, f"{base}/{repo}"
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")
raise RuntimeError(f"Failed to download {repo}.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')}")
@@ -84,14 +117,13 @@ def parse_database(db_bytes):
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")
content = tar.extractfile(member).read().decode("utf-8", errors="replace")
current_section = None
pkg_name = None
filename = None
depends = []
current_section = None
provides = []
for line in content.splitlines():
line = line.strip()
if line.startswith("%") and line.endswith("%"):
@@ -105,18 +137,22 @@ def parse_database(db_bytes):
depends.append(dep)
elif current_section == "PROVIDES" and line:
prov = re.split(r"[<>=]", line)[0]
provides_map[prov] = pkg_name
provides.append(prov)
if pkg_name:
packages[pkg_name] = {"filename": filename, "depends": depends}
provides_map[pkg_name] = pkg_name
for prov in provides:
if prov not in packages:
provides_map[prov] = pkg_name
return packages, provides_map
def resolve_dependencies(packages, provides_map):
queue = list(SEEDS)
visited = set(SEEDS)
def resolve_dependencies(packages, provides_map, pkg_prefix):
seeds = [f"{pkg_prefix}-{name}" for name in SEED_PACKAGES]
queue = list(seeds)
visited = set(seeds)
resolved = []
while queue:
@@ -140,17 +176,17 @@ def resolve_dependencies(packages, provides_map):
return sorted(resolved)
def download_and_extract_packages(resolved, base_mirror, dest_dir):
def download_and_extract_packages(resolved, repo, dest_dir):
os.makedirs(dest_dir, exist_ok=True)
temp_pkg = "/tmp/arm64_pkg.tar.zst"
temp_pkg = f"/tmp/msys2_{repo}_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}"
for base in MIRROR_BASES:
pkg_url = f"{base}/{repo}/{filename}"
try:
data = fetch_url(pkg_url, timeout=60)
with open(temp_pkg, "wb") as f:
@@ -159,12 +195,11 @@ def download_and_extract_packages(resolved, base_mirror, dest_dir):
break
except Exception as e:
last_err = e
print(f" Failed from {mirror} ({e}), trying next mirror...", file=sys.stderr)
print(f" Failed from {base}/{repo} ({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,
@@ -177,35 +212,80 @@ def download_and_extract_packages(resolved, base_mirror, dest_dir):
raise RuntimeError(f"Failed to extract {filename}: {err}")
def configure_sysroot(dest_dir, repo):
abs_dest = os.path.abspath(dest_dir)
# Rewrite hardcoded /clang64 or /clangarm64 prefixes in pkg-config files
pc_files = glob.glob(os.path.join(abs_dest, "lib", "pkgconfig", "*.pc")) + glob.glob(
os.path.join(abs_dest, "share", "pkgconfig", "*.pc")
)
for pc_path in pc_files:
with open(pc_path, "r", encoding="utf-8", errors="replace") as f:
content = f.read()
updated = content.replace(f"/{repo}", abs_dest)
if updated != content:
with open(pc_path, "w", encoding="utf-8") as f:
f.write(updated)
# Copy any share/pkgconfig/*.pc (e.g. zlib.pc) into lib/pkgconfig so a single PKG_CONFIG_PATH works
lib_pc_dir = os.path.join(abs_dest, "lib", "pkgconfig")
os.makedirs(lib_pc_dir, exist_ok=True)
for pc_path in glob.glob(os.path.join(abs_dest, "share", "pkgconfig", "*.pc")):
target_pc = os.path.join(lib_pc_dir, os.path.basename(pc_path))
if not os.path.exists(target_pc):
shutil.copy2(pc_path, target_pc)
# Remove target Windows Qt6*Tools CMake packages so CMake cross-compilation
# always uses host Linux tools (moc, rcc, qmlcachegen, qmlimportscanner) from QT_HOST_PATH.
for tools_dir in glob.glob(os.path.join(abs_dest, "lib", "cmake", "Qt6*Tools")):
if os.path.isdir(tools_dir):
shutil.rmtree(tools_dir)
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)
missing_dlls = [dll for dll in EXPECTED_DLLS if not os.path.isfile(os.path.join(bin_dir, dll))]
if missing_dlls:
raise RuntimeError(f"Missing expected DLLs in {bin_dir}: {', '.join(missing_dlls)}")
if missing:
raise RuntimeError(f"Missing expected DLLs in {bin_dir}: {', '.join(missing)}")
pc_dir = os.path.join(dest_dir, "lib", "pkgconfig")
missing_pcs = [pc for pc in EXPECTED_PC_FILES if not os.path.isfile(os.path.join(pc_dir, pc))]
if missing_pcs:
raise RuntimeError(f"Missing expected pkg-config files in {pc_dir}: {', '.join(missing_pcs)}")
print(f"==> Verification passed: all {len(EXPECTED_DLLS)} required core DLLs present in {bin_dir}")
print(
f"==> Verification passed: all {len(EXPECTED_DLLS)} core DLLs and "
f"{len(EXPECTED_PC_FILES)} pkg-config files present in {dest_dir}"
)
def main():
parser = argparse.ArgumentParser(description="Download MSYS2 clangarm64 Qt6 packages and dependencies")
parser = argparse.ArgumentParser(
description="Download MSYS2 Windows (x86_64 / arm64) Qt6 and third-party packages"
)
parser.add_argument("--dest", required=True, help="Destination directory to extract packages into")
parser.add_argument(
"--arch",
choices=["x86_64", "arm64"],
default="arm64",
help="Target Windows architecture (default: arm64)",
)
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")
cfg = ARCH_CONFIG[args.arch]
repo = cfg["repo"]
pkg_prefix = cfg["pkg_prefix"]
resolved = resolve_dependencies(packages, provides_map)
print(f"==> Resolved {len(resolved)} packages to install:")
db_bytes, _ = download_db(repo)
packages, provides_map = parse_database(db_bytes)
print(f"==> Parsed {len(packages)} packages from MSYS2 {repo} database")
resolved = resolve_dependencies(packages, provides_map, pkg_prefix)
print(f"==> Resolved {len(resolved)} packages to install for Windows {args.arch} ({repo}):")
for pkg_name, filename in resolved:
print(f" - {pkg_name} ({filename})")
@@ -213,9 +293,10 @@ def main():
print("==> Dry run complete.")
return
download_and_extract_packages(resolved, mirror, args.dest)
download_and_extract_packages(resolved, repo, args.dest)
configure_sysroot(args.dest, repo)
verify_installation(args.dest)
print(f"==> Successfully installed Qt6 Windows ARM64 into {args.dest}")
print(f"==> Successfully installed Windows {args.arch} sysroot into {args.dest}")
if __name__ == "__main__":