moar ci changes
This commit is contained in:
19 files changed
+1313
-663
No files matched your search
Executable
+306
@@ -0,0 +1,306 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Populates a Linux AppDir for asteria-qt (x86_64 or arm64/aarch64) by copying
|
||||
required Qt plugins, QML modules, and transitive ELF shared libraries using
|
||||
architecture-independent tools (readelf + patchelf).
|
||||
|
||||
Usage:
|
||||
bundle-linux-appdir.py --appdir <AppDir> --qt-dir <QtDir> [--arch {x86_64,arm64}]
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Standard AppImage host-provided system/driver libraries (excluded from AppDir/usr/lib)
|
||||
EXCLUDED_SYSTEM_LIBS = {
|
||||
"ld-linux-x86-64.so.2",
|
||||
"ld-linux-aarch64.so.1",
|
||||
"libanl.so.1",
|
||||
"libc.so.6",
|
||||
"libcrypt.so.1",
|
||||
"libdbus-1.so.3",
|
||||
"libdl.so.2",
|
||||
"libdrm.so.2",
|
||||
"libEGL.so.1",
|
||||
"libexpat.so.1",
|
||||
"libfontconfig.so.1",
|
||||
"libfreetype.so.6",
|
||||
"libgbm.so.1",
|
||||
"libgcc_s.so.1",
|
||||
"libGL.so.1",
|
||||
"libGLdispatch.so.0",
|
||||
"libglib-2.0.so.0",
|
||||
"libGLX.so.0",
|
||||
"libharfbuzz.so.0",
|
||||
"libICE.so.6",
|
||||
"libm.so.6",
|
||||
"libnsl.so.1",
|
||||
"libOpenGL.so.0",
|
||||
"libpthread.so.0",
|
||||
"libresolv.so.2",
|
||||
"librt.so.1",
|
||||
"libSM.so.6",
|
||||
"libstdc++.so.6",
|
||||
"libutil.so.1",
|
||||
"libvulkan.so.1",
|
||||
"libwayland-client.so.0",
|
||||
"libwayland-cursor.so.0",
|
||||
"libwayland-egl.so.1",
|
||||
"libX11.so.6",
|
||||
"libX11-xcb.so.1",
|
||||
"libxcb.so.1",
|
||||
"libXext.so.6",
|
||||
"libz.so.1",
|
||||
}
|
||||
|
||||
PLUGIN_DIRS = [
|
||||
"platforms",
|
||||
"wayland-decoration-client",
|
||||
"wayland-graphics-integration-client",
|
||||
"wayland-shell-integration",
|
||||
"xcbglintegrations",
|
||||
"platformthemes",
|
||||
"platforminputcontexts",
|
||||
"imageformats",
|
||||
"iconengines",
|
||||
"tls",
|
||||
]
|
||||
|
||||
# Skip optional plugins that pull in heavy/unrelated desktop or embedded stacks
|
||||
SKIP_PLUGINS = {
|
||||
"libqeglfs.so",
|
||||
"libqlinuxfb.so",
|
||||
"libqvkkhrdisplay.so",
|
||||
"libqvnc.so",
|
||||
"libqgtk3.so",
|
||||
"libqcertonlybackend.so",
|
||||
}
|
||||
|
||||
QML_MODULES = [
|
||||
"QtCore",
|
||||
"Qt",
|
||||
"QtQml",
|
||||
"QtQuick",
|
||||
]
|
||||
|
||||
UNUSED_QTQUICK_SUBDIRS = {
|
||||
"tooling",
|
||||
"LocalStorage",
|
||||
"Particles",
|
||||
"Pdf",
|
||||
"Scene2D",
|
||||
"Scene3D",
|
||||
"Timeline",
|
||||
"VirtualKeyboard",
|
||||
}
|
||||
|
||||
NEEDED_RE = re.compile(r"\(NEEDED\)\s+Shared library:\s+\[([^\]]+)\]")
|
||||
|
||||
|
||||
def is_elf(filepath):
|
||||
if not os.path.isfile(filepath) or os.path.islink(filepath):
|
||||
return False
|
||||
try:
|
||||
with open(filepath, "rb") as f:
|
||||
return f.read(4) == b"\x7fELF"
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def get_dt_needed(filepath):
|
||||
res = subprocess.run(["readelf", "-d", filepath], capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return []
|
||||
return NEEDED_RE.findall(res.stdout)
|
||||
|
||||
|
||||
def setup_appdir_metadata(appdir):
|
||||
desktop_src = os.path.join(appdir, "usr", "share", "applications", "asteria-qt.desktop")
|
||||
icon_src = os.path.join(appdir, "usr", "share", "icons", "hicolor", "256x256", "apps", "asteria-qt.png")
|
||||
|
||||
if os.path.isfile(desktop_src):
|
||||
shutil.copy2(desktop_src, os.path.join(appdir, "asteria-qt.desktop"))
|
||||
if os.path.isfile(icon_src):
|
||||
shutil.copy2(icon_src, os.path.join(appdir, "asteria-qt.png"))
|
||||
dir_icon = os.path.join(appdir, ".DirIcon")
|
||||
if os.path.lexists(dir_icon):
|
||||
os.remove(dir_icon)
|
||||
os.symlink("asteria-qt.png", dir_icon)
|
||||
|
||||
apprun_path = os.path.join(appdir, "AppRun")
|
||||
with open(apprun_path, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
"#!/bin/sh\n"
|
||||
'HERE="$(dirname "$(readlink -f "$0")")"\n'
|
||||
'export LD_LIBRARY_PATH="$HERE/usr/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"\n'
|
||||
'export QT_PLUGIN_PATH="$HERE/usr/plugins"\n'
|
||||
'export QML2_IMPORT_PATH="$HERE/usr/qml"\n'
|
||||
'export QML_IMPORT_PATH="$HERE/usr/qml"\n'
|
||||
'exec "$HERE/usr/bin/asteria-qt" "$@"\n'
|
||||
)
|
||||
os.chmod(apprun_path, 0o755)
|
||||
|
||||
qt_conf_path = os.path.join(appdir, "usr", "bin", "qt.conf")
|
||||
with open(qt_conf_path, "w", encoding="utf-8") as f:
|
||||
f.write("[Paths]\nPrefix = ..\nPlugins = plugins\nImports = qml\nQml2Imports = qml\n")
|
||||
|
||||
|
||||
def copy_qt_plugins_and_qml(appdir, qt_dir):
|
||||
plugins_src = os.path.join(qt_dir, "plugins")
|
||||
plugins_dst = os.path.join(appdir, "usr", "plugins")
|
||||
os.makedirs(plugins_dst, exist_ok=True)
|
||||
|
||||
for pdir in PLUGIN_DIRS:
|
||||
src_sub = os.path.join(plugins_src, pdir)
|
||||
if not os.path.isdir(src_sub):
|
||||
continue
|
||||
dst_sub = os.path.join(plugins_dst, pdir)
|
||||
os.makedirs(dst_sub, exist_ok=True)
|
||||
for fname in os.listdir(src_sub):
|
||||
if not fname.endswith(".so") or fname in SKIP_PLUGINS:
|
||||
continue
|
||||
shutil.copy2(os.path.join(src_sub, fname), os.path.join(dst_sub, fname))
|
||||
|
||||
qml_src = os.path.join(qt_dir, "qml")
|
||||
qml_dst = os.path.join(appdir, "usr", "qml")
|
||||
os.makedirs(qml_dst, exist_ok=True)
|
||||
|
||||
for mod in QML_MODULES:
|
||||
src_mod = os.path.join(qml_src, mod)
|
||||
if os.path.isdir(src_mod):
|
||||
dst_mod = os.path.join(qml_dst, mod)
|
||||
if os.path.exists(dst_mod):
|
||||
shutil.rmtree(dst_mod)
|
||||
shutil.copytree(src_mod, dst_mod)
|
||||
|
||||
for unused in UNUSED_QTQUICK_SUBDIRS:
|
||||
unused_path = os.path.join(qml_dst, "QtQuick", unused)
|
||||
if os.path.isdir(unused_path):
|
||||
shutil.rmtree(unused_path)
|
||||
|
||||
for root, _, files in os.walk(qml_dst):
|
||||
for fname in files:
|
||||
if fname.endswith((".qmltypes", ".metainfo", ".prl")):
|
||||
os.remove(os.path.join(root, fname))
|
||||
|
||||
|
||||
def find_library(soname, search_dirs):
|
||||
for sdir in search_dirs:
|
||||
candidate = os.path.join(sdir, soname)
|
||||
if os.path.exists(candidate):
|
||||
return os.path.realpath(candidate)
|
||||
return None
|
||||
|
||||
|
||||
def bundle_and_verify_libs(appdir, qt_dir, triplet):
|
||||
lib_dst = os.path.join(appdir, "usr", "lib")
|
||||
os.makedirs(lib_dst, exist_ok=True)
|
||||
|
||||
search_dirs = [
|
||||
os.path.join(qt_dir, "lib"),
|
||||
f"/usr/lib/{triplet}",
|
||||
f"/lib/{triplet}",
|
||||
]
|
||||
|
||||
# Remove optional plugins (like imageformats/tls) whose third-party backing lib isn't installed
|
||||
plugins_dst = os.path.join(appdir, "usr", "plugins")
|
||||
for root, _, files in os.walk(plugins_dst):
|
||||
for fname in list(files):
|
||||
fpath = os.path.join(root, fname)
|
||||
if not is_elf(fpath):
|
||||
continue
|
||||
needed = get_dt_needed(fpath)
|
||||
missing_opt = [
|
||||
n
|
||||
for n in needed
|
||||
if n not in EXCLUDED_SYSTEM_LIBS and find_library(n, search_dirs) is None
|
||||
]
|
||||
if missing_opt and os.path.basename(root) in ("imageformats", "tls", "platforminputcontexts", "wayland-graphics-integration-client"):
|
||||
print(f" Skipping optional plugin {fname} (missing optional system lib: {', '.join(missing_opt)})")
|
||||
os.remove(fpath)
|
||||
|
||||
# Collect initial ELF files in AppDir
|
||||
queue = []
|
||||
for root, _, files in os.walk(appdir):
|
||||
for fname in files:
|
||||
fpath = os.path.join(root, fname)
|
||||
if is_elf(fpath):
|
||||
queue.append(fpath)
|
||||
|
||||
bundled_sonames = set(os.listdir(lib_dst))
|
||||
copied_count = 0
|
||||
|
||||
while queue:
|
||||
elf_path = queue.pop(0)
|
||||
for soname in get_dt_needed(elf_path):
|
||||
if soname in EXCLUDED_SYSTEM_LIBS or soname in bundled_sonames:
|
||||
continue
|
||||
real_src = find_library(soname, search_dirs)
|
||||
if real_src is None:
|
||||
continue
|
||||
dst_file = os.path.join(lib_dst, soname)
|
||||
shutil.copy2(real_src, dst_file)
|
||||
os.chmod(dst_file, stat.S_IMODE(os.stat(dst_file).st_mode) | stat.S_IWUSR)
|
||||
bundled_sonames.add(soname)
|
||||
queue.append(dst_file)
|
||||
copied_count += 1
|
||||
|
||||
print(f"==> Bundled {copied_count} shared libraries into {lib_dst}")
|
||||
|
||||
# Patch RPATH so executable and libraries resolve $ORIGIN
|
||||
exe_path = os.path.join(appdir, "usr", "bin", "asteria-qt")
|
||||
subprocess.run(["patchelf", "--set-rpath", "$ORIGIN/../lib", exe_path], check=True)
|
||||
|
||||
for fname in os.listdir(lib_dst):
|
||||
fpath = os.path.join(lib_dst, fname)
|
||||
if is_elf(fpath):
|
||||
subprocess.run(["patchelf", "--set-rpath", "$ORIGIN", fpath], check=False)
|
||||
|
||||
# Verify all DT_NEEDED dependencies in AppDir
|
||||
missing_by_soname = {}
|
||||
all_elfs = []
|
||||
for root, _, files in os.walk(appdir):
|
||||
for fname in files:
|
||||
fpath = os.path.join(root, fname)
|
||||
if is_elf(fpath):
|
||||
all_elfs.append(fpath)
|
||||
|
||||
for elf_path in sorted(all_elfs):
|
||||
rel = os.path.relpath(elf_path, appdir)
|
||||
for soname in get_dt_needed(elf_path):
|
||||
if soname in EXCLUDED_SYSTEM_LIBS or soname in bundled_sonames:
|
||||
continue
|
||||
missing_by_soname.setdefault(soname, []).append(rel)
|
||||
|
||||
if missing_by_soname:
|
||||
print(f"FAILED: Found {len(missing_by_soname)} missing ELF shared libraries in {appdir}:", file=sys.stderr)
|
||||
for soname, importers in sorted(missing_by_soname.items()):
|
||||
print(f" [MISSING] {soname} needed by:", file=sys.stderr)
|
||||
for imp in importers[:5]:
|
||||
print(f" - {imp}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f"==> ELF verification passed: scanned {len(all_elfs)} binaries in {appdir}, 0 missing dependencies.")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Bundle Qt plugins, QML modules, and ELF libraries into AppDir")
|
||||
parser.add_argument("--appdir", required=True, help="Path to AppDir")
|
||||
parser.add_argument("--qt-dir", required=True, help="Path to target Qt installation directory")
|
||||
parser.add_argument("--arch", default="x86_64", choices=["x86_64", "arm64", "aarch64"])
|
||||
args = parser.parse_args()
|
||||
|
||||
triplet = "aarch64-linux-gnu" if args.arch in ("arm64", "aarch64") else "x86_64-linux-gnu"
|
||||
|
||||
setup_appdir_metadata(args.appdir)
|
||||
copy_qt_plugins_and_qml(args.appdir, args.qt_dir)
|
||||
bundle_and_verify_libs(args.appdir, args.qt_dir, triplet)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -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__":
|
||||
|
||||
@@ -9,7 +9,7 @@ brew update
|
||||
brew install cmake ninja pkg-config uchardet minizip libarchive gitlab-runner
|
||||
|
||||
echo ""
|
||||
echo "Installing Qt 6.10.3 via aqtinstall → /opt/qt ..."
|
||||
echo "Installing Qt 6.12.0 via aqtinstall → /opt/qt ..."
|
||||
python3 -m venv /tmp/aqt-venv
|
||||
/tmp/aqt-venv/bin/pip install --quiet aqtinstall
|
||||
|
||||
@@ -19,17 +19,17 @@ QT_DIR_NAME="macos"
|
||||
|
||||
sudo mkdir -p /opt/qt
|
||||
sudo chown "$USER" /opt/qt
|
||||
/tmp/aqt-venv/bin/aqt install-qt mac desktop 6.10.3 "$QT_ARCH" \
|
||||
/tmp/aqt-venv/bin/aqt install-qt mac desktop 6.12.0 "$QT_ARCH" \
|
||||
-m qtimageformats qtpdf --outputdir /opt/qt
|
||||
/tmp/aqt-venv/bin/aqt install-src mac 6.10.3 --outputdir /opt/qt
|
||||
/tmp/aqt-venv/bin/aqt install-src mac 6.12.0 --outputdir /opt/qt
|
||||
rm -rf /tmp/aqt-venv
|
||||
|
||||
QT_DIR="/opt/qt/6.10.3/$QT_DIR_NAME"
|
||||
QT_DIR="/opt/qt/6.12.0/$QT_DIR_NAME"
|
||||
|
||||
echo ""
|
||||
echo "All dependencies installed."
|
||||
echo ""
|
||||
echo "Qt 6.10.3 is at $QT_DIR"
|
||||
echo "Qt 6.12.0 is at $QT_DIR"
|
||||
echo ""
|
||||
echo "Build with:"
|
||||
echo " PKG_CONFIG_PATH=\"\$(brew --prefix libarchive)/lib/pkgconfig:\$PKG_CONFIG_PATH\" \\"
|
||||
|
||||
+178
-26
@@ -1,41 +1,193 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install all development dependencies for asteria-qt on Ubuntu/Debian.
|
||||
# Tested on Ubuntu 24.04. Run with sudo or as root.
|
||||
# Qt 6.10.x is installed via aqtinstall to /opt/qt — the Ubuntu apt repo only
|
||||
# ships Qt 6.4, which is too old (qt_policy QTP0004 requires Qt 6.8+).
|
||||
# Install development dependencies for asteria-qt on Ubuntu (24.04+).
|
||||
# Run with sudo or as root.
|
||||
#
|
||||
# Usage:
|
||||
# sudo scripts/install-deps-ubuntu.sh [--with-arm64] [--with-sources]
|
||||
#
|
||||
# Environment variables:
|
||||
# QT_VERSION Qt version to install via aqtinstall (default: 6.12.0)
|
||||
# QT_INSTALL_DIR Destination directory for Qt (default: /opt/qt)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
apt-get update
|
||||
QT_VERSION="${QT_VERSION:-6.12.0}"
|
||||
QT_INSTALL_DIR="${QT_INSTALL_DIR:-/opt/qt}"
|
||||
WITH_ARM64=false
|
||||
WITH_SOURCES=false
|
||||
|
||||
apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
ninja-build \
|
||||
git \
|
||||
libgl1-mesa-dev \
|
||||
libxkbcommon-dev \
|
||||
libuchardet-dev \
|
||||
zlib1g-dev \
|
||||
libminizip-dev \
|
||||
libarchive-dev \
|
||||
libdjvulibre-dev \
|
||||
libwpd-dev \
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--with-arm64) WITH_ARM64=true ;;
|
||||
--with-sources) WITH_SOURCES=true ;;
|
||||
*)
|
||||
echo "Unknown option: $arg" >&2
|
||||
echo "Usage: $0 [--with-arm64] [--with-sources]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
HOST_ARCH="$(dpkg --print-architecture)"
|
||||
|
||||
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
|
||||
echo "==> Enabling Ubuntu arm64 multiarch repository..."
|
||||
dpkg --add-architecture arm64
|
||||
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
|
||||
if ! grep -q "^Architectures:" /etc/apt/sources.list.d/ubuntu.sources; then
|
||||
sed -i "s/^Types: deb$/Types: deb\nArchitectures: amd64/" /etc/apt/sources.list.d/ubuntu.sources
|
||||
fi
|
||||
SUITE="$(awk '/^Suites:/ {print $2; exit}' /etc/apt/sources.list.d/ubuntu.sources)"
|
||||
SUITE="${SUITE:-noble}"
|
||||
cat <<EOF > /etc/apt/sources.list.d/ubuntu-arm64.sources
|
||||
Types: deb
|
||||
URIs: http://ports.ubuntu.com/ubuntu-ports/
|
||||
Suites: ${SUITE} ${SUITE}-updates ${SUITE}-backports ${SUITE}-security
|
||||
Components: main universe restricted multiverse
|
||||
Architectures: arm64
|
||||
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "==> Installing system build tools and libraries..."
|
||||
apt-get update -qq
|
||||
|
||||
PACKAGES=(
|
||||
build-essential
|
||||
ca-certificates
|
||||
cmake
|
||||
curl
|
||||
file
|
||||
git
|
||||
jq
|
||||
libarchive-dev
|
||||
libdbus-1-dev
|
||||
libegl-dev
|
||||
libfontconfig1-dev
|
||||
libfreetype-dev
|
||||
libgl-dev
|
||||
libglib2.0-0t64
|
||||
libminizip-dev
|
||||
libtiff6
|
||||
libuchardet-dev
|
||||
libwayland-client0
|
||||
libwayland-cursor0
|
||||
libwayland-egl1
|
||||
libwebp7
|
||||
libwebpdemux2
|
||||
libwebpmux3
|
||||
libxcb-cursor0
|
||||
libxcb-icccm4
|
||||
libxcb-image0
|
||||
libxcb-keysyms1
|
||||
libxcb-randr0
|
||||
libxcb-render-util0
|
||||
libxcb-shape0
|
||||
libxcb-shm0
|
||||
libxcb-sync1
|
||||
libxcb-util1
|
||||
libxcb-xfixes0
|
||||
libxcb-xkb1
|
||||
libxkbcommon-dev
|
||||
libxkbcommon-x11-0
|
||||
ninja-build
|
||||
patchelf
|
||||
pkg-config
|
||||
python3
|
||||
python3-venv
|
||||
wget
|
||||
xz-utils
|
||||
zip
|
||||
zlib1g-dev
|
||||
zstd
|
||||
)
|
||||
|
||||
echo ""
|
||||
echo "Installing Qt 6.10.3 via aqtinstall → /opt/qt ..."
|
||||
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
|
||||
PACKAGES+=(
|
||||
g++-aarch64-linux-gnu
|
||||
libarchive13t64:arm64
|
||||
libdbus-1-dev:arm64
|
||||
libegl-dev:arm64
|
||||
libfontconfig1-dev:arm64
|
||||
libfreetype-dev:arm64
|
||||
libgl-dev:arm64
|
||||
libglib2.0-0t64:arm64
|
||||
libminizip-dev:arm64
|
||||
libtiff6:arm64
|
||||
libuchardet-dev:arm64
|
||||
libwayland-client0:arm64
|
||||
libwayland-cursor0:arm64
|
||||
libwayland-egl1:arm64
|
||||
libwebp7:arm64
|
||||
libwebpdemux2:arm64
|
||||
libwebpmux3:arm64
|
||||
libxcb-cursor0:arm64
|
||||
libxcb-icccm4:arm64
|
||||
libxcb-image0:arm64
|
||||
libxcb-keysyms1:arm64
|
||||
libxcb-randr0:arm64
|
||||
libxcb-render-util0:arm64
|
||||
libxcb-shape0:arm64
|
||||
libxcb-shm0:arm64
|
||||
libxcb-sync1:arm64
|
||||
libxcb-util1:arm64
|
||||
libxcb-xfixes0:arm64
|
||||
libxcb-xkb1:arm64
|
||||
libxkbcommon-dev:arm64
|
||||
libxkbcommon-x11-0:arm64
|
||||
zlib1g-dev:arm64
|
||||
)
|
||||
fi
|
||||
|
||||
apt-get install -y --no-install-recommends "${PACKAGES[@]}"
|
||||
|
||||
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
|
||||
# libarchive-dev is not Multi-Arch: same on Ubuntu 24.04 (due to libext2fs-dev);
|
||||
# headers are already in /usr/include, so wire the arm64 .so symlink and .pc file.
|
||||
ln -sf libarchive.so.13 /usr/lib/aarch64-linux-gnu/libarchive.so
|
||||
mkdir -p /usr/lib/aarch64-linux-gnu/pkgconfig
|
||||
sed 's/x86_64-linux-gnu/aarch64-linux-gnu/g' \
|
||||
/usr/lib/x86_64-linux-gnu/pkgconfig/libarchive.pc \
|
||||
> /usr/lib/aarch64-linux-gnu/pkgconfig/libarchive.pc
|
||||
fi
|
||||
|
||||
echo "==> Installing Qt ${QT_VERSION} via aqtinstall -> ${QT_INSTALL_DIR}..."
|
||||
python3 -m venv /tmp/aqt-venv
|
||||
/tmp/aqt-venv/bin/pip install --quiet aqtinstall
|
||||
/tmp/aqt-venv/bin/aqt install-qt linux desktop 6.10.3 linux_gcc_64 -m qtimageformats qtpdf qtwebview --outputdir /opt/qt
|
||||
/tmp/aqt-venv/bin/aqt install-src linux 6.10.3 --archives qtbase qtimageformats qtwebview --outputdir /opt/qt
|
||||
|
||||
if [ "$HOST_ARCH" = "arm64" ]; then
|
||||
/tmp/aqt-venv/bin/aqt install-qt linux_arm64 desktop "${QT_VERSION}" linux_gcc_arm64 \
|
||||
-m qtimageformats --outputdir "${QT_INSTALL_DIR}"
|
||||
QT_NATIVE_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
|
||||
else
|
||||
/tmp/aqt-venv/bin/aqt install-qt linux desktop "${QT_VERSION}" linux_gcc_64 \
|
||||
-m qtimageformats --outputdir "${QT_INSTALL_DIR}"
|
||||
QT_NATIVE_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64"
|
||||
|
||||
if [ "$WITH_ARM64" = true ]; then
|
||||
echo "==> Installing Qt ${QT_VERSION} (Linux arm64) via aqtinstall -> ${QT_INSTALL_DIR}..."
|
||||
/tmp/aqt-venv/bin/aqt install-qt linux_arm64 desktop "${QT_VERSION}" linux_gcc_arm64 \
|
||||
-m qtimageformats --outputdir "${QT_INSTALL_DIR}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$WITH_SOURCES" = true ]; then
|
||||
/tmp/aqt-venv/bin/aqt install-src linux "${QT_VERSION}" \
|
||||
--archives qtbase qtdeclarative qtsvg qtimageformats --outputdir "${QT_INSTALL_DIR}"
|
||||
fi
|
||||
|
||||
rm -rf /tmp/aqt-venv
|
||||
|
||||
echo ""
|
||||
echo "All dependencies installed."
|
||||
echo ""
|
||||
echo "Qt 6.10.3 is at /opt/qt/6.10.3/gcc_64"
|
||||
echo "==> All Ubuntu dependencies installed."
|
||||
echo " Qt ${QT_VERSION} native path: ${QT_NATIVE_DIR}"
|
||||
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
|
||||
echo " Qt ${QT_VERSION} arm64 path: ${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
|
||||
fi
|
||||
echo ""
|
||||
echo "Build with:"
|
||||
echo " cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/gcc_64"
|
||||
echo " cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=${QT_NATIVE_DIR}"
|
||||
echo " cmake --build build --parallel"
|
||||
@@ -24,19 +24,19 @@ pacman -S --needed \
|
||||
mingw-w64-x86_64-python-psutil
|
||||
|
||||
echo ""
|
||||
echo "Installing Qt 6.10.3 via aqtinstall → /opt/qt ..."
|
||||
echo "Installing Qt 6.12.0 via aqtinstall → /opt/qt ..."
|
||||
python3 -m venv --system-site-packages /tmp/aqt-venv
|
||||
/tmp/aqt-venv/bin/python3 -m pip install --upgrade pip
|
||||
/tmp/aqt-venv/bin/python3 -m pip install setuptools pyppmd
|
||||
/tmp/aqt-venv/bin/pip install aqtinstall
|
||||
/tmp/aqt-venv/bin/aqt install-qt windows desktop 6.10.3 win64_mingw -m qtimageformats qtpdf qtwebview --outputdir /opt/qt
|
||||
/tmp/aqt-venv/bin/aqt install-qt windows desktop 6.12.0 win64_mingw -m qtimageformats qtpdf qtwebview --outputdir /opt/qt
|
||||
rm -rf /tmp/aqt-venv
|
||||
|
||||
echo ""
|
||||
echo "All dependencies installed."
|
||||
echo ""
|
||||
echo "Qt 6.10.3 is at /opt/qt/6.10.3/mingw_64"
|
||||
echo "Qt 6.12.0 is at /opt/qt/6.12.0/mingw_64"
|
||||
echo ""
|
||||
echo "Build with:"
|
||||
echo " cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=c:\msys64\opt\qt\6.10.3\mingw_64"
|
||||
echo " cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=c:\msys64\opt\qt\6.12.0\mingw_64"
|
||||
echo " cmake --build build --parallel"
|
||||
@@ -0,0 +1,27 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
|
||||
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-rpath-link,/usr/lib/aarch64-linux-gnu -Wl,-rpath-link,/lib/aarch64-linux-gnu")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Wl,-rpath-link,/usr/lib/aarch64-linux-gnu -Wl,-rpath-link,/lib/aarch64-linux-gnu")
|
||||
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH
|
||||
${CMAKE_PREFIX_PATH}
|
||||
/usr/aarch64-linux-gnu
|
||||
/usr/lib/aarch64-linux-gnu
|
||||
/usr
|
||||
)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
set(QT_NO_PACKAGE_VERSION_CHECK TRUE)
|
||||
set(QT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING TRUE)
|
||||
|
||||
# Point pkg-config at the Ubuntu arm64 multiarch pkgconfig directories
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig")
|
||||
set(ENV{PKG_CONFIG_PATH} "")
|
||||
@@ -6,15 +6,22 @@ set(CMAKE_CXX_COMPILER aarch64-w64-mingw32-g++)
|
||||
set(CMAKE_RC_COMPILER aarch64-w64-mingw32-windres)
|
||||
|
||||
# Append default sysroot paths. list(APPEND) preserves any paths already set via
|
||||
# -DCMAKE_FIND_ROOT_PATH on the cmake command line (e.g. the Qt Windows ARM64 install dir),
|
||||
# while plain set() would silently override them and break find_package(Qt6).
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH /opt/mingw-arm64-sysroot /opt/llvm-mingw/aarch64-w64-mingw32)
|
||||
# -DCMAKE_FIND_ROOT_PATH on the cmake command line (e.g. the Qt Windows ARM64 install dir).
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH} /opt/mingw-arm64-sysroot /opt/llvm-mingw/aarch64-w64-mingw32)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
# Point pkg-config at the MinGW ARM64 sysroot so it finds cross-compiled .pc files
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{MINGW_ARM64_SYSROOT}/lib/pkgconfig")
|
||||
set(ENV{PKG_CONFIG_PATH} "")
|
||||
set(QT_NO_PACKAGE_VERSION_CHECK TRUE)
|
||||
set(QT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING TRUE)
|
||||
|
||||
# Point pkg-config at the MinGW ARM64 sysroot so it never picks up host Linux .pc files
|
||||
if(DEFINED ENV{MINGW_ARM64_SYSROOT} AND NOT "$ENV{MINGW_ARM64_SYSROOT}" STREQUAL "")
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{MINGW_ARM64_SYSROOT}/lib/pkgconfig:$ENV{MINGW_ARM64_SYSROOT}/share/pkgconfig")
|
||||
elseif(DEFINED ENV{QT_WINDOWS_ARM64_DIR} AND NOT "$ENV{QT_WINDOWS_ARM64_DIR}" STREQUAL "")
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{QT_WINDOWS_ARM64_DIR}/lib/pkgconfig:$ENV{QT_WINDOWS_ARM64_DIR}/share/pkgconfig")
|
||||
else()
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "/opt/mingw-arm64-sysroot/lib/pkgconfig:/opt/mingw-arm64-sysroot/share/pkgconfig")
|
||||
endif()
|
||||
@@ -1,27 +1,27 @@
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
|
||||
# Explicitly prefer GCC toolchain in /usr/bin when available to prevent collision with llvm-mingw
|
||||
if(EXISTS "/usr/bin/x86_64-w64-mingw32-gcc")
|
||||
set(CMAKE_C_COMPILER /usr/bin/x86_64-w64-mingw32-gcc)
|
||||
set(CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++)
|
||||
set(CMAKE_RC_COMPILER /usr/bin/x86_64-w64-mingw32-windres)
|
||||
else()
|
||||
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
endif()
|
||||
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
|
||||
# Append default sysroot paths. list(APPEND) preserves any paths already set via
|
||||
# -DCMAKE_FIND_ROOT_PATH on the cmake command line (e.g. the Qt Windows install dir),
|
||||
# while plain set() would silently override them and break find_package(Qt6).
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH /opt/mingw-sysroot /usr/x86_64-w64-mingw32)
|
||||
# -DCMAKE_FIND_ROOT_PATH on the cmake command line (e.g. the Qt Windows install dir).
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH} /opt/mingw-sysroot /opt/llvm-mingw/x86_64-w64-mingw32 /usr/x86_64-w64-mingw32)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
# Point pkg-config at the MinGW sysroot so it finds cross-compiled .pc files
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{MINGW_SYSROOT}/lib/pkgconfig")
|
||||
set(ENV{PKG_CONFIG_PATH} "")
|
||||
set(QT_NO_PACKAGE_VERSION_CHECK TRUE)
|
||||
set(QT_NO_PACKAGE_VERSION_INCOMPATIBLE_WARNING TRUE)
|
||||
|
||||
# Point pkg-config at the MinGW x86_64 sysroot so it never picks up host Linux .pc files
|
||||
if(DEFINED ENV{MINGW_SYSROOT} AND NOT "$ENV{MINGW_SYSROOT}" STREQUAL "")
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{MINGW_SYSROOT}/lib/pkgconfig:$ENV{MINGW_SYSROOT}/share/pkgconfig")
|
||||
elseif(DEFINED ENV{QT_WINDOWS_DIR} AND NOT "$ENV{QT_WINDOWS_DIR}" STREQUAL "")
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "$ENV{QT_WINDOWS_DIR}/lib/pkgconfig:$ENV{QT_WINDOWS_DIR}/share/pkgconfig")
|
||||
else()
|
||||
set(ENV{PKG_CONFIG_LIBDIR} "/opt/mingw-sysroot/lib/pkgconfig:/opt/mingw-sysroot/share/pkgconfig")
|
||||
endif()
|
||||
@@ -34,7 +34,7 @@ CI_SERVER_URL="${CI_SERVER_URL:-https://gitlab.com}"
|
||||
RUNNER_NAME="${RUNNER_NAME:-asteria-qt-macos-runner}"
|
||||
RUNNER_TAGS="${RUNNER_TAGS:-macos-qt}"
|
||||
|
||||
export QT_MACOS_DIR="${QT_MACOS_DIR:-/opt/qt/6.10.3/macos}"
|
||||
export QT_MACOS_DIR="${QT_MACOS_DIR:-/opt/qt/6.12.0/macos}"
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
LIBARCHIVE_PREFIX="$(brew --prefix libarchive 2>/dev/null || true)"
|
||||
if [ -n "${LIBARCHIVE_PREFIX}" ] && [ -d "${LIBARCHIVE_PREFIX}/lib/pkgconfig" ]; then
|
||||
|
||||
+55
-22
@@ -1,21 +1,28 @@
|
||||
#!/bin/bash
|
||||
# Run CI build/package jobs locally using podman or docker.
|
||||
# Usage: test-ci-linux.sh [--build-image]
|
||||
# --build-image build the CI image from Dockerfile instead of pulling the prebuilt one
|
||||
# Run Linux CI build/test/package jobs locally using podman or docker.
|
||||
# Usage: test-ci-linux.sh [--build-image] [--image <tag>] [--arm64] [--only-arm64]
|
||||
set -euo pipefail
|
||||
|
||||
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
OUTPUT_DIR="$PROJECT_DIR/ci-output"
|
||||
DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build"
|
||||
PREBUILT_IMAGE="registry.gitlab.com/asteria-bookreader/asteria-qt/build-env:latest"
|
||||
PREBUILT_IMAGE="${PREBUILT_IMAGE:-registry.gitlab.com/asteria-bookreader/asteria-qt/build-env:latest}"
|
||||
IMAGE_TAG="$PREBUILT_IMAGE"
|
||||
BUILD_IMAGE=false
|
||||
RUN_X86_64=true
|
||||
RUN_ARM64=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--build-image) BUILD_IMAGE=true; IMAGE_TAG="asteria-qt-ci-local:latest" ;;
|
||||
*) echo "Unknown argument: $arg"; exit 1 ;;
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--build-image) BUILD_IMAGE=true; IMAGE_TAG="asteria-qt-ci-local:latest"; shift ;;
|
||||
--image) IMAGE_TAG="$2"; shift 2 ;;
|
||||
--image=*) IMAGE_TAG="${1#*=}"; shift ;;
|
||||
--arm64) RUN_ARM64=true; shift ;;
|
||||
--only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;;
|
||||
*) echo "Unknown argument: $1"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -34,19 +41,19 @@ if [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "==> Building CI image from $DOCKERFILE"
|
||||
"$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg QT_VERSION=6.10.3 \
|
||||
--build-arg QT_VERSION=6.12.0 \
|
||||
-t "$IMAGE_TAG" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
else
|
||||
elif ! "$RUNTIME" image inspect "$IMAGE_TAG" &>/dev/null; then
|
||||
echo "==> Pulling prebuilt CI image: $IMAGE_TAG"
|
||||
"$RUNTIME" pull --platform linux/amd64 "$IMAGE_TAG"
|
||||
else
|
||||
echo "==> Using local image: $IMAGE_TAG"
|
||||
fi
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Helper: run a command inside the CI container
|
||||
# The project is copied into /src inside the container so the build is isolated.
|
||||
run_in_container() {
|
||||
local extra_args=("$@")
|
||||
"$RUNTIME" run --rm \
|
||||
@@ -63,22 +70,48 @@ run_in_container() {
|
||||
'
|
||||
}
|
||||
|
||||
# ── Linux build ───────────────────────────────────────────────────────────────
|
||||
echo "==> build-linux"
|
||||
CI_SCRIPT='
|
||||
# ── Linux x86_64 build, test, and package ────────────────────────────────────
|
||||
if [ "$RUN_X86_64" = true ]; then
|
||||
echo "==> build-linux & test-linux (x86_64)"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH="${QT_LINUX_DIR}"
|
||||
cmake --build build-linux --target asteria-qt
|
||||
cp build-linux/asteria-qt /out/
|
||||
cmake --build build-linux
|
||||
QT_QPA_PLATFORM=offscreen ctest --test-dir build-linux --output-on-failure
|
||||
rm -rf /out/build-linux
|
||||
cp -r build-linux /out/build-linux
|
||||
cp build-linux/asteria-qt /out/asteria-qt
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
|
||||
echo "==> package-linux"
|
||||
CI_SCRIPT='
|
||||
mkdir -p build-linux
|
||||
cp /out/asteria-qt build-linux/asteria-qt
|
||||
echo "==> package-linux (x86_64)"
|
||||
CI_SCRIPT='
|
||||
cp -r /out/build-linux build-linux
|
||||
chmod +x packaging/package-linux.sh
|
||||
packaging/package-linux.sh build-linux "${QT_LINUX_DIR}" /out
|
||||
packaging/package-linux.sh build-linux "${QT_LINUX_DIR}" /out x86_64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
# ── Linux ARM64 build and package ────────────────────────────────────────────
|
||||
if [ "$RUN_ARM64" = true ]; then
|
||||
echo "==> build-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux-arm64 -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=/src/scripts/linux-arm64-toolchain.cmake \
|
||||
-DCMAKE_PREFIX_PATH="${QT_LINUX_ARM64_DIR}" \
|
||||
-DQT_HOST_PATH="${QT_LINUX_DIR}"
|
||||
cmake --build build-linux-arm64 --target asteria-qt
|
||||
rm -rf /out/build-linux-arm64
|
||||
cp -r build-linux-arm64 /out/build-linux-arm64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
|
||||
echo "==> package-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
cp -r /out/build-linux-arm64 build-linux-arm64
|
||||
chmod +x packaging/package-linux.sh
|
||||
packaging/package-linux.sh build-linux-arm64 "${QT_LINUX_ARM64_DIR}" /out arm64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "==> Done. Artifacts in $OUTPUT_DIR/"
|
||||
|
||||
+34
-11
@@ -1,9 +1,10 @@
|
||||
#!/bin/bash
|
||||
# Run CI build/package jobs locally using podman or docker.
|
||||
# Usage: test-ci-windows.sh [--build-image] [--linux] [--arm64]
|
||||
# Usage: test-ci-windows.sh [--build-image] [--image <tag>] [--linux] [--arm64] [--only-arm64]
|
||||
# --build-image build the CI image from Dockerfile instead of pulling the prebuilt one
|
||||
# --linux also run build-linux + package-linux in addition to Windows jobs
|
||||
# --arm64 also run build-windows-arm64 + package-windows-arm64
|
||||
# --linux also run build-linux + package-linux (and arm64 if --arm64 is passed)
|
||||
# --arm64 also run arm64 build + package jobs
|
||||
# --only-arm64 run only arm64 build + package jobs
|
||||
set -euo pipefail
|
||||
|
||||
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
|
||||
@@ -46,7 +47,7 @@ if [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "==> Building CI image from $DOCKERFILE"
|
||||
"$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg QT_VERSION=6.10.3 \
|
||||
--build-arg QT_VERSION=6.12.0 \
|
||||
-t "$IMAGE_TAG" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
@@ -124,20 +125,42 @@ fi
|
||||
|
||||
# ── Linux build (optional) ───────────────────────────────────────────────────
|
||||
if [ "$RUN_LINUX" = true ]; then
|
||||
echo "==> build-linux"
|
||||
CI_SCRIPT='
|
||||
if [ "$RUN_X86_64" = true ]; then
|
||||
echo "==> build-linux (x86_64)"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH="${QT_LINUX_DIR}"
|
||||
cmake --build build-linux --target asteria-qt
|
||||
cp build-linux/asteria-qt /out/
|
||||
cp -r build-linux /out/build-linux
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
|
||||
echo "==> package-linux"
|
||||
CI_SCRIPT='
|
||||
cp /out/asteria-qt build-linux/asteria-qt
|
||||
echo "==> package-linux (x86_64)"
|
||||
CI_SCRIPT='
|
||||
cp -r /out/build-linux build-linux
|
||||
chmod +x packaging/package-linux.sh
|
||||
packaging/package-linux.sh build-linux "${QT_LINUX_DIR}" /out
|
||||
packaging/package-linux.sh build-linux "${QT_LINUX_DIR}" /out x86_64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
if [ "$RUN_ARM64" = true ]; then
|
||||
echo "==> build-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux-arm64 -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=/src/scripts/linux-arm64-toolchain.cmake \
|
||||
-DCMAKE_PREFIX_PATH="${QT_LINUX_ARM64_DIR}" \
|
||||
-DQT_HOST_PATH="${QT_LINUX_DIR}"
|
||||
cmake --build build-linux-arm64 --target asteria-qt
|
||||
cp -r build-linux-arm64 /out/build-linux-arm64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
|
||||
echo "==> package-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
cp -r /out/build-linux-arm64 build-linux-arm64
|
||||
chmod +x packaging/package-linux.sh
|
||||
packaging/package-linux.sh build-linux-arm64 "${QT_LINUX_ARM64_DIR}" /out arm64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
+259
-144
@@ -1,71 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Verifies that all PE DLL dependencies of an executable and its bundled plugins
|
||||
are satisfied within the target distribution directory.
|
||||
Bundles (optional) and verifies that all non-system PE (.exe / .dll) import
|
||||
dependencies in a Windows distribution folder are present inside the folder.
|
||||
|
||||
Usage:
|
||||
verify-windows-dlls.py /path/to/dist_dir
|
||||
verify-windows-dlls.py <dist-dir> [--bundle-from <dir> ...]
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import sys
|
||||
|
||||
# Standard Windows system and runtime libraries (case-insensitive)
|
||||
# Standard Windows OS system DLLs provided by Windows (System32)
|
||||
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
|
||||
"bcrypt.dll",
|
||||
"bcryptprimitives.dll",
|
||||
"cabinet.dll",
|
||||
"cfgmgr32.dll",
|
||||
"combase.dll",
|
||||
"comctl32.dll",
|
||||
"comdlg32.dll",
|
||||
"credui.dll",
|
||||
"crypt32.dll",
|
||||
"cryptbase.dll",
|
||||
"d2d1.dll",
|
||||
"d3d9.dll",
|
||||
"d3d10warp.dll",
|
||||
"d3d11.dll",
|
||||
"d3d12.dll",
|
||||
"dxgi.dll",
|
||||
"d2d1.dll",
|
||||
"d3dcompiler_47.dll",
|
||||
"dbghelp.dll",
|
||||
"dcomp.dll",
|
||||
"dhcpcsvc.dll",
|
||||
"dhcpcsvc6.dll",
|
||||
"dnsapi.dll",
|
||||
"dwmapi.dll",
|
||||
"dwrite.dll",
|
||||
"opengl32.dll",
|
||||
"dxcore.dll",
|
||||
"dxgi.dll",
|
||||
"gdi32.dll",
|
||||
"gdiplus.dll",
|
||||
"glu32.dll",
|
||||
# CRT / UCRT
|
||||
"hid.dll",
|
||||
"imagehlp.dll",
|
||||
"imm32.dll",
|
||||
"iphlpapi.dll",
|
||||
"kernel32.dll",
|
||||
"kernelbase.dll",
|
||||
"ksuser.dll",
|
||||
"mf.dll",
|
||||
"mfplat.dll",
|
||||
"mfreadwrite.dll",
|
||||
"mfuuid.dll",
|
||||
"mmdevapi.dll",
|
||||
"mpr.dll",
|
||||
"mscms.dll",
|
||||
"msimg32.dll",
|
||||
"msvcp_win.dll",
|
||||
"msvcrt.dll",
|
||||
"mswsock.dll",
|
||||
"ncrypt.dll",
|
||||
"netapi32.dll",
|
||||
"netutils.dll",
|
||||
"normaliz.dll",
|
||||
"ntdll.dll",
|
||||
"ole32.dll",
|
||||
"oleaut32.dll",
|
||||
"opengl32.dll",
|
||||
"pdh.dll",
|
||||
"powrprof.dll",
|
||||
"propsys.dll",
|
||||
"psapi.dll",
|
||||
"rpcrt4.dll",
|
||||
"runtimeobject.dll",
|
||||
"secur32.dll",
|
||||
"setupapi.dll",
|
||||
"shcore.dll",
|
||||
"shell32.dll",
|
||||
"shlwapi.dll",
|
||||
"srvcli.dll",
|
||||
"synchronization.dll",
|
||||
"ucrtbase.dll",
|
||||
"uiautomationcore.dll",
|
||||
"urlmon.dll",
|
||||
"user32.dll",
|
||||
"userenv.dll",
|
||||
"usp10.dll",
|
||||
"uxtheme.dll",
|
||||
"version.dll",
|
||||
"vulkan-1.dll",
|
||||
"wevtapi.dll",
|
||||
"winhttp.dll",
|
||||
"wininet.dll",
|
||||
"winmm.dll",
|
||||
"winspool.drv",
|
||||
"wkscli.dll",
|
||||
"wldap32.dll",
|
||||
"ws2_32.dll",
|
||||
"wtsapi32.dll",
|
||||
"xinput1_4.dll",
|
||||
"xmllite.dll",
|
||||
}
|
||||
|
||||
|
||||
@@ -78,137 +116,214 @@ def is_system_dll(name):
|
||||
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 []
|
||||
def rva_to_offset(rva, sections):
|
||||
for vaddr, vsize, raw_ptr, raw_size in sections:
|
||||
size = max(vsize, raw_size)
|
||||
if vaddr <= rva < vaddr + size:
|
||||
return raw_ptr + (rva - vaddr)
|
||||
return None
|
||||
|
||||
|
||||
def read_cstring(data, offset):
|
||||
if offset is None or offset < 0 or offset >= len(data):
|
||||
return None
|
||||
end = data.find(b"\x00", offset)
|
||||
if end == -1:
|
||||
return None
|
||||
return data[offset:end].decode("ascii", errors="replace")
|
||||
|
||||
|
||||
def get_pe_imports(filepath):
|
||||
with open(filepath, "rb") as f:
|
||||
data = f.read()
|
||||
|
||||
if len(data) < 0x40 or data[:2] != b"MZ":
|
||||
return []
|
||||
|
||||
pe_offset = struct.unpack_from("<I", data, 0x3c)[0]
|
||||
if pe_offset + 24 > len(data) or data[pe_offset:pe_offset+4] != b"PE\x00\x00":
|
||||
return []
|
||||
|
||||
magic = struct.unpack_from("<H", data, pe_offset + 24)[0]
|
||||
if magic == 0x20b: # PE32+ (64-bit)
|
||||
import_rva_offset = pe_offset + 24 + 120
|
||||
elif magic == 0x10b: # PE32 (32-bit)
|
||||
import_rva_offset = pe_offset + 24 + 104
|
||||
else:
|
||||
return []
|
||||
|
||||
if import_rva_offset + 8 > len(data):
|
||||
return []
|
||||
|
||||
import_rva, import_size = struct.unpack_from("<II", data, import_rva_offset)
|
||||
if import_rva == 0 or import_size == 0:
|
||||
pe_offset = struct.unpack_from("<I", data, 0x3C)[0]
|
||||
if pe_offset + 24 > len(data) or data[pe_offset : pe_offset + 4] != b"PE\x00\x00":
|
||||
return []
|
||||
|
||||
num_sections = struct.unpack_from("<H", data, pe_offset + 6)[0]
|
||||
size_of_opt_header = struct.unpack_from("<H", data, pe_offset + 20)[0]
|
||||
sec_offset = pe_offset + 24 + size_of_opt_header
|
||||
opt_header_size = struct.unpack_from("<H", data, pe_offset + 20)[0]
|
||||
opt_offset = pe_offset + 24
|
||||
|
||||
if opt_offset + opt_header_size > len(data):
|
||||
return []
|
||||
|
||||
magic = struct.unpack_from("<H", data, opt_offset)[0]
|
||||
if magic == 0x20B: # PE32+ (64-bit: x86_64 / ARM64)
|
||||
dd_offset = opt_offset + 112
|
||||
elif magic == 0x10B: # PE32 (32-bit)
|
||||
dd_offset = opt_offset + 96
|
||||
else:
|
||||
return []
|
||||
|
||||
num_rva = struct.unpack_from("<I", data, dd_offset - 4)[0]
|
||||
if num_rva < 2:
|
||||
return []
|
||||
|
||||
import_rva, import_size = struct.unpack_from("<II", data, dd_offset + 8)
|
||||
if import_rva == 0 or import_size == 0:
|
||||
return []
|
||||
|
||||
sec_offset = opt_offset + opt_header_size
|
||||
sections = []
|
||||
for i in range(num_sections):
|
||||
sec = data[sec_offset + i * 40 : sec_offset + (i + 1) * 40]
|
||||
if len(sec) < 40:
|
||||
s_off = sec_offset + i * 40
|
||||
if s_off + 40 > len(data):
|
||||
break
|
||||
vsize, vrva, rsize, roffset = struct.unpack_from("<IIII", sec, 8)
|
||||
sections.append((vrva, vsize, roffset, rsize))
|
||||
vsize, vaddr, raw_size, raw_ptr = struct.unpack_from("<IIII", data, s_off + 8)
|
||||
sections.append((vaddr, vsize, raw_ptr, raw_size))
|
||||
|
||||
def rva_to_off(rva):
|
||||
for vrva, vsize, roffset, rsize in sections:
|
||||
if vrva <= rva < vrva + max(vsize, rsize):
|
||||
return roffset + (rva - vrva)
|
||||
return None
|
||||
|
||||
import_off = rva_to_off(import_rva)
|
||||
if not import_off:
|
||||
imp_offset = rva_to_offset(import_rva, sections)
|
||||
if imp_offset is None:
|
||||
return []
|
||||
|
||||
imports = []
|
||||
while import_off + 20 <= len(data):
|
||||
desc = data[import_off : import_off + 20]
|
||||
if desc == b"\x00" * 20:
|
||||
pos = imp_offset
|
||||
while pos + 20 <= len(data):
|
||||
orig_thunk, ts, fwd, name_rva, first_thunk = struct.unpack_from("<IIIII", data, pos)
|
||||
if orig_thunk == 0 and name_rva == 0 and first_thunk == 0:
|
||||
break
|
||||
name_rva = struct.unpack_from("<I", desc, 12)[0]
|
||||
name_off = rva_to_off(name_rva)
|
||||
if name_off and name_off < len(data):
|
||||
name = data[name_off:].split(b"\x00", 1)[0].decode("latin1", errors="ignore")
|
||||
if name:
|
||||
imports.append(name)
|
||||
import_off += 20
|
||||
name_off = rva_to_offset(name_rva, sections)
|
||||
dll_name = read_cstring(data, name_off)
|
||||
if dll_name:
|
||||
imports.append(dll_name)
|
||||
pos += 20
|
||||
|
||||
return imports
|
||||
|
||||
|
||||
def verify_dist_directory(dist_dir):
|
||||
if not os.path.isdir(dist_dir):
|
||||
print(f"Error: directory does not exist: {dist_dir}", file=sys.stderr)
|
||||
return False
|
||||
def collect_pe_files(dist_dir):
|
||||
pe_files = []
|
||||
for root, _, files in os.walk(dist_dir):
|
||||
for fname in files:
|
||||
lower = fname.lower()
|
||||
if lower.endswith(".dll") or lower.endswith(".exe"):
|
||||
pe_files.append(os.path.join(root, fname))
|
||||
return sorted(pe_files)
|
||||
|
||||
# Collect all available DLLs in the dist directory (case-insensitive)
|
||||
available_dlls = {}
|
||||
binaries = []
|
||||
|
||||
def bundle_transitive_dlls(dist_dir, search_dirs):
|
||||
"""
|
||||
Walks all PE files in dist_dir and recursively copies required non-system DLLs
|
||||
from search_dirs into dist_dir root.
|
||||
"""
|
||||
# Build case-insensitive lookup index of available DLLs in search_dirs
|
||||
available = {}
|
||||
for sdir in search_dirs:
|
||||
if not sdir or not os.path.isdir(sdir):
|
||||
continue
|
||||
for fname in os.listdir(sdir):
|
||||
if fname.lower().endswith(".dll"):
|
||||
lower = fname.lower()
|
||||
if lower not in available:
|
||||
available[lower] = os.path.join(sdir, fname)
|
||||
|
||||
# Track DLLs already present in dist_dir
|
||||
present = set()
|
||||
queue = []
|
||||
for full_path in collect_pe_files(dist_dir):
|
||||
present.add(os.path.basename(full_path).lower())
|
||||
queue.append(full_path)
|
||||
|
||||
copied_count = 0
|
||||
while queue:
|
||||
current_pe = queue.pop(0)
|
||||
current_dir = os.path.dirname(current_pe)
|
||||
local_dlls = {
|
||||
f.lower()
|
||||
for f in os.listdir(current_dir)
|
||||
if f.lower().endswith(".dll") or f.lower().endswith(".exe")
|
||||
}
|
||||
|
||||
for imp in get_pe_imports(current_pe):
|
||||
imp_lower = imp.lower()
|
||||
if is_system_dll(imp_lower):
|
||||
continue
|
||||
if imp_lower in present or imp_lower in local_dlls:
|
||||
continue
|
||||
if imp_lower in available:
|
||||
src_dll = available[imp_lower]
|
||||
dst_dll = os.path.join(dist_dir, os.path.basename(src_dll))
|
||||
shutil.copy2(src_dll, dst_dll)
|
||||
present.add(imp_lower)
|
||||
queue.append(dst_dll)
|
||||
copied_count += 1
|
||||
|
||||
print(f"==> Bundled {copied_count} transitive runtime DLLs into {dist_dir}")
|
||||
|
||||
|
||||
def verify_dist_directory(dist_dir):
|
||||
root_dlls = set()
|
||||
all_pe_files = []
|
||||
|
||||
for root, _, files in os.walk(dist_dir):
|
||||
for f in files:
|
||||
lower = f.lower()
|
||||
rel_path = os.path.relpath(os.path.join(root, f), dist_dir)
|
||||
if lower.endswith(".dll"):
|
||||
available_dlls[lower] = rel_path
|
||||
binaries.append(os.path.join(root, f))
|
||||
elif lower.endswith(".exe"):
|
||||
binaries.append(os.path.join(root, f))
|
||||
for fname in files:
|
||||
lower = fname.lower()
|
||||
if lower.endswith(".dll") or lower.endswith(".exe"):
|
||||
full_path = os.path.join(root, fname)
|
||||
all_pe_files.append(full_path)
|
||||
if os.path.abspath(root) == os.path.abspath(dist_dir):
|
||||
root_dlls.add(lower)
|
||||
|
||||
if not binaries:
|
||||
print(f"Error: no .exe or .dll binaries found in {dist_dir}", file=sys.stderr)
|
||||
return False
|
||||
if not all_pe_files:
|
||||
raise RuntimeError(f"No .exe or .dll files found in {dist_dir}")
|
||||
|
||||
missing_deps = []
|
||||
checked_count = len(binaries)
|
||||
missing_by_dll = {}
|
||||
for pe_file in sorted(all_pe_files):
|
||||
rel_pe = os.path.relpath(pe_file, dist_dir)
|
||||
local_dir = os.path.dirname(pe_file)
|
||||
local_dlls = {
|
||||
f.lower()
|
||||
for f in os.listdir(local_dir)
|
||||
if f.lower().endswith(".dll") or f.lower().endswith(".exe")
|
||||
}
|
||||
|
||||
for bin_path in binaries:
|
||||
rel_bin = os.path.relpath(bin_path, dist_dir)
|
||||
imports = get_pe_imports(bin_path)
|
||||
for imp in imports:
|
||||
if is_system_dll(imp):
|
||||
for imp in get_pe_imports(pe_file):
|
||||
imp_lower = imp.lower()
|
||||
if is_system_dll(imp_lower):
|
||||
continue
|
||||
if imp.lower() not in available_dlls:
|
||||
missing_deps.append((rel_bin, imp))
|
||||
if imp_lower not in root_dlls and imp_lower not in local_dlls:
|
||||
missing_by_dll.setdefault(imp, []).append(rel_pe)
|
||||
|
||||
if missing_deps:
|
||||
print(f"FAILED: Found {len(missing_deps)} missing DLL dependencies in {dist_dir}:", file=sys.stderr)
|
||||
# Deduplicate and group by missing DLL
|
||||
missing_by_dll = {}
|
||||
for rel_bin, imp in missing_deps:
|
||||
missing_by_dll.setdefault(imp, []).append(rel_bin)
|
||||
if missing_by_dll:
|
||||
print(f"FAILED: Found {len(missing_by_dll)} missing DLL dependencies in {dist_dir}:", file=sys.stderr)
|
||||
for dll, importers in sorted(missing_by_dll.items()):
|
||||
print(f" [MISSING] {dll} needed by:", file=sys.stderr)
|
||||
for importer in importers[:5]:
|
||||
print(f" - {importer}", file=sys.stderr)
|
||||
if len(importers) > 5:
|
||||
print(f" ... and {len(importers) - 5} more", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
for imp, users in sorted(missing_by_dll.items()):
|
||||
print(f" [MISSING] {imp} needed by:", file=sys.stderr)
|
||||
for u in users[:5]:
|
||||
print(f" - {u}", file=sys.stderr)
|
||||
if len(users) > 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
|
||||
print(
|
||||
f"==> DLL verification passed: scanned {len(all_pe_files)} binaries in {dist_dir}, "
|
||||
"0 missing dependencies."
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: verify-windows-dlls.py <dist-dir>", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
parser = argparse.ArgumentParser(description="Bundle and verify PE DLL imports in a Windows dist directory")
|
||||
parser.add_argument("dist_dir", help="Path to the distribution directory containing asteria-qt.exe")
|
||||
parser.add_argument(
|
||||
"--bundle-from",
|
||||
nargs="+",
|
||||
default=[],
|
||||
help="Optional list of bin directories to copy transitive DLL dependencies from before verifying",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
dist_dir = sys.argv[1]
|
||||
if not verify_dist_directory(dist_dir):
|
||||
if not os.path.isdir(args.dist_dir):
|
||||
print(f"Error: directory does not exist: {args.dist_dir}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if args.bundle_from:
|
||||
bundle_transitive_dlls(args.dist_dir, args.bundle_from)
|
||||
|
||||
verify_dist_directory(args.dist_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user