moaaar ci changes
This commit is contained in:
7 files changed
+555
-227
No files matched your search
@@ -9,6 +9,7 @@ Usage:
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import concurrent.futures
|
||||
import glob
|
||||
import io
|
||||
import os
|
||||
@@ -17,6 +18,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
@@ -176,40 +178,77 @@ def resolve_dependencies(packages, provides_map, pkg_prefix):
|
||||
return sorted(resolved)
|
||||
|
||||
|
||||
def _download_single_package(pkg_info, repo, download_dir):
|
||||
idx, total, filename = pkg_info
|
||||
last_err = None
|
||||
dest_file = os.path.join(download_dir, os.path.basename(filename))
|
||||
|
||||
for base in MIRROR_BASES:
|
||||
pkg_url = f"{base}/{repo}/{filename}"
|
||||
try:
|
||||
data = fetch_url(pkg_url, timeout=60)
|
||||
with open(dest_file, "wb") as f:
|
||||
f.write(data)
|
||||
print(f"[{idx}/{total}] Downloaded {filename}")
|
||||
return filename, dest_file
|
||||
except Exception as e:
|
||||
last_err = e
|
||||
print(f" Failed {filename} from {base}/{repo} ({e}), trying next mirror...", file=sys.stderr)
|
||||
|
||||
raise RuntimeError(f"Failed to download {filename}: {last_err}")
|
||||
|
||||
|
||||
def download_and_extract_packages(resolved, repo, dest_dir):
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
temp_pkg = f"/tmp/msys2_{repo}_pkg.tar.zst"
|
||||
total = len(resolved)
|
||||
|
||||
for i, (pkg_name, filename) in enumerate(resolved, 1):
|
||||
print(f"[{i}/{len(resolved)}] Downloading {filename}...")
|
||||
downloaded = False
|
||||
last_err = None
|
||||
with tempfile.TemporaryDirectory(prefix=f"msys2_{repo}_") as download_dir:
|
||||
tasks = [(i, total, filename) for i, (_, filename) in enumerate(resolved, 1)]
|
||||
downloaded_files = []
|
||||
|
||||
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:
|
||||
f.write(data)
|
||||
downloaded = True
|
||||
break
|
||||
except Exception as e:
|
||||
last_err = e
|
||||
print(f" Failed from {base}/{repo} ({e}), trying next mirror...", file=sys.stderr)
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||
futures = [executor.submit(_download_single_package, task, repo, download_dir) for task in tasks]
|
||||
for future in concurrent.futures.as_completed(futures):
|
||||
downloaded_files.append(future.result())
|
||||
|
||||
if not downloaded:
|
||||
raise RuntimeError(f"Failed to download {filename}: {last_err}")
|
||||
# Extract sequentially in deterministic filename order
|
||||
for filename, pkg_path in sorted(downloaded_files):
|
||||
tar_res = subprocess.run(
|
||||
["tar", "-I", "zstd", "-xf", pkg_path, "--strip-components=1", "-C", dest_dir],
|
||||
capture_output=True,
|
||||
)
|
||||
os.remove(pkg_path)
|
||||
if tar_res.returncode != 0:
|
||||
err = tar_res.stderr.decode("utf-8", errors="replace")
|
||||
raise RuntimeError(f"Failed to extract {filename}: {err}")
|
||||
|
||||
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 prune_sysroot(abs_dest):
|
||||
# Remove docs, manuals, locales, translations, and examples
|
||||
prune_dirs = [
|
||||
os.path.join(abs_dest, "share", "doc"),
|
||||
os.path.join(abs_dest, "share", "man"),
|
||||
os.path.join(abs_dest, "share", "info"),
|
||||
os.path.join(abs_dest, "share", "locale"),
|
||||
os.path.join(abs_dest, "share", "qt6", "doc"),
|
||||
os.path.join(abs_dest, "share", "qt6", "examples"),
|
||||
os.path.join(abs_dest, "share", "qt6", "translations"),
|
||||
os.path.join(abs_dest, "share", "qt6", "phrasebooks"),
|
||||
]
|
||||
for unused_qml in ("LocalStorage", "Particles", "Pdf", "Scene2D", "Scene3D", "Timeline", "VirtualKeyboard", "tooling"):
|
||||
prune_dirs.append(os.path.join(abs_dest, "share", "qt6", "qml", "QtQuick", unused_qml))
|
||||
|
||||
for d in prune_dirs:
|
||||
if os.path.isdir(d):
|
||||
shutil.rmtree(d)
|
||||
|
||||
# Remove static .a archives when a corresponding .dll.a import library exists
|
||||
lib_dir = os.path.join(abs_dest, "lib")
|
||||
if os.path.isdir(lib_dir):
|
||||
for dll_a in glob.glob(os.path.join(lib_dir, "*.dll.a")):
|
||||
static_a = dll_a[: -len(".dll.a")] + ".a"
|
||||
if os.path.isfile(static_a):
|
||||
os.remove(static_a)
|
||||
|
||||
|
||||
def configure_sysroot(dest_dir, repo):
|
||||
@@ -241,6 +280,8 @@ def configure_sysroot(dest_dir, repo):
|
||||
if os.path.isdir(tools_dir):
|
||||
shutil.rmtree(tools_dir)
|
||||
|
||||
prune_sysroot(abs_dest)
|
||||
|
||||
|
||||
def verify_installation(dest_dir):
|
||||
bin_dir = os.path.join(dest_dir, "bin")
|
||||
|
||||
+130
-80
@@ -3,7 +3,7 @@
|
||||
# Run with sudo or as root.
|
||||
#
|
||||
# Usage:
|
||||
# sudo scripts/install-deps-ubuntu.sh [--with-arm64] [--with-sources]
|
||||
# sudo scripts/install-deps-ubuntu.sh [--with-arm64] [--only-arm64] [--skip-qt] [--prune-qt] [--with-sources]
|
||||
#
|
||||
# Environment variables:
|
||||
# QT_VERSION Qt version to install via aqtinstall (default: 6.12.0)
|
||||
@@ -14,15 +14,21 @@ set -euo pipefail
|
||||
QT_VERSION="${QT_VERSION:-6.12.0}"
|
||||
QT_INSTALL_DIR="${QT_INSTALL_DIR:-/opt/qt}"
|
||||
WITH_ARM64=false
|
||||
ONLY_ARM64=false
|
||||
SKIP_QT=false
|
||||
PRUNE_QT=false
|
||||
WITH_SOURCES=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--with-arm64) WITH_ARM64=true ;;
|
||||
--only-arm64) ONLY_ARM64=true; WITH_ARM64=true ;;
|
||||
--skip-qt) SKIP_QT=true ;;
|
||||
--prune-qt) PRUNE_QT=true ;;
|
||||
--with-sources) WITH_SOURCES=true ;;
|
||||
*)
|
||||
echo "Unknown option: $arg" >&2
|
||||
echo "Usage: $0 [--with-arm64] [--with-sources]" >&2
|
||||
echo "Usage: $0 [--with-arm64] [--only-arm64] [--skip-qt] [--prune-qt] [--with-sources]" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -55,58 +61,63 @@ 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
|
||||
)
|
||||
PACKAGES=()
|
||||
|
||||
if [ "$ONLY_ARM64" = false ]; then
|
||||
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
|
||||
)
|
||||
fi
|
||||
|
||||
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
|
||||
PACKAGES+=(
|
||||
gcc-aarch64-linux-gnu
|
||||
g++-aarch64-linux-gnu
|
||||
libarchive13t64:arm64
|
||||
libdbus-1-dev:arm64
|
||||
@@ -140,54 +151,93 @@ if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
|
||||
libxkbcommon-x11-0:arm64
|
||||
zlib1g-dev:arm64
|
||||
)
|
||||
if [ "$ONLY_ARM64" = true ]; then
|
||||
# Dedicated arm64 build environment has no conflicting amd64 libarchive-dev
|
||||
PACKAGES+=(libarchive-dev:arm64)
|
||||
fi
|
||||
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
|
||||
if [ "$ONLY_ARM64" = false ]; 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
|
||||
command -v aarch64-linux-gnu-gcc >/dev/null
|
||||
command -v aarch64-linux-gnu-g++ >/dev/null
|
||||
aarch64-linux-gnu-g++ --version
|
||||
PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig \
|
||||
pkg-config --exists minizip libarchive
|
||||
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
|
||||
prune_qt_dir() {
|
||||
local qt_dir="$1"
|
||||
if [ ! -d "$qt_dir" ]; then
|
||||
return
|
||||
fi
|
||||
rm -rf \
|
||||
"$qt_dir/doc" \
|
||||
"$qt_dir/examples" \
|
||||
"$qt_dir/phrasebooks" \
|
||||
"$qt_dir/translations" \
|
||||
"$qt_dir/qml/QtQuick/LocalStorage" \
|
||||
"$qt_dir/qml/QtQuick/Particles" \
|
||||
"$qt_dir/qml/QtQuick/Pdf" \
|
||||
"$qt_dir/qml/QtQuick/Scene2D" \
|
||||
"$qt_dir/qml/QtQuick/Scene3D" \
|
||||
"$qt_dir/qml/QtQuick/Timeline" \
|
||||
"$qt_dir/qml/QtQuick/VirtualKeyboard" \
|
||||
"$qt_dir/qml/QtQuick/tooling"
|
||||
}
|
||||
|
||||
QT_NATIVE_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64"
|
||||
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"
|
||||
fi
|
||||
|
||||
if [ "$WITH_ARM64" = true ]; then
|
||||
echo "==> Installing Qt ${QT_VERSION} (Linux arm64) via aqtinstall -> ${QT_INSTALL_DIR}..."
|
||||
if [ "$SKIP_QT" = false ]; then
|
||||
echo "==> Installing Qt ${QT_VERSION} via aqtinstall -> ${QT_INSTALL_DIR}..."
|
||||
python3 -m venv /tmp/aqt-venv
|
||||
/tmp/aqt-venv/bin/pip install --quiet aqtinstall
|
||||
|
||||
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}"
|
||||
[ "$PRUNE_QT" = true ] && prune_qt_dir "${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
|
||||
else
|
||||
if [ "$ONLY_ARM64" = false ]; then
|
||||
/tmp/aqt-venv/bin/aqt install-qt linux desktop "${QT_VERSION}" linux_gcc_64 \
|
||||
-m qtimageformats --outputdir "${QT_INSTALL_DIR}"
|
||||
[ "$PRUNE_QT" = true ] && prune_qt_dir "${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64"
|
||||
fi
|
||||
|
||||
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}"
|
||||
[ "$PRUNE_QT" = true ] && prune_qt_dir "${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
|
||||
fi
|
||||
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
|
||||
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
|
||||
rm -rf /tmp/aqt-venv
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "==> All Ubuntu dependencies installed."
|
||||
echo " Qt ${QT_VERSION} native path: ${QT_NATIVE_DIR}"
|
||||
if [ "$ONLY_ARM64" = false ]; then
|
||||
echo " Qt ${QT_VERSION} native path: ${QT_NATIVE_DIR}"
|
||||
fi
|
||||
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=${QT_NATIVE_DIR}"
|
||||
echo " cmake --build build --parallel"
|
||||
+40
-24
@@ -9,17 +9,17 @@ 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="${PREBUILT_IMAGE:-registry.gitlab.com/asteria-bookreader/asteria-qt/build-env:latest}"
|
||||
IMAGE_TAG="$PREBUILT_IMAGE"
|
||||
IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-registry.gitlab.com/asteria-bookreader/asteria-qt}"
|
||||
CUSTOM_IMAGE=""
|
||||
BUILD_IMAGE=false
|
||||
RUN_X86_64=true
|
||||
RUN_ARM64=false
|
||||
|
||||
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 ;;
|
||||
--build-image) BUILD_IMAGE=true; shift ;;
|
||||
--image) CUSTOM_IMAGE="$2"; shift 2 ;;
|
||||
--image=*) CUSTOM_IMAGE="${1#*=}"; shift ;;
|
||||
--arm64) RUN_ARM64=true; shift ;;
|
||||
--only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;;
|
||||
*) echo "Unknown argument: $1"; exit 1 ;;
|
||||
@@ -37,31 +37,39 @@ else
|
||||
fi
|
||||
echo "Using container runtime: $RUNTIME"
|
||||
|
||||
if [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "==> Building CI image from $DOCKERFILE"
|
||||
"$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg QT_VERSION=6.12.0 \
|
||||
-t "$IMAGE_TAG" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
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
|
||||
prepare_image() {
|
||||
local target="$1"
|
||||
local image_tag="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-${target}:latest}"
|
||||
if [ "$BUILD_IMAGE" = true ]; then
|
||||
image_tag="${CUSTOM_IMAGE:-asteria-qt-ci-${target}:latest}"
|
||||
echo "==> Building CI image target '$target' ($image_tag) from $DOCKERFILE"
|
||||
DOCKER_BUILDKIT=1 "$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg QT_VERSION=6.12.0 \
|
||||
--target "$target" \
|
||||
-t "$image_tag" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
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"
|
||||
|
||||
run_in_container() {
|
||||
local image_tag="$1"
|
||||
shift
|
||||
local extra_args=("$@")
|
||||
"$RUNTIME" run --rm \
|
||||
--platform linux/amd64 \
|
||||
--entrypoint bash \
|
||||
-v "$PROJECT_DIR:/src-ro:ro" \
|
||||
"${extra_args[@]}" \
|
||||
"$IMAGE_TAG" \
|
||||
"$image_tag" \
|
||||
-c '
|
||||
set -euo pipefail
|
||||
cp -r /src-ro /src
|
||||
@@ -72,6 +80,10 @@ run_in_container() {
|
||||
|
||||
# ── Linux x86_64 build, test, and package ────────────────────────────────────
|
||||
if [ "$RUN_X86_64" = true ]; then
|
||||
prepare_image "linux-x86_64"
|
||||
X64_IMAGE="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-linux-x86_64:latest}"
|
||||
[ "$BUILD_IMAGE" = true ] && X64_IMAGE="${CUSTOM_IMAGE:-asteria-qt-ci-linux-x86_64:latest}"
|
||||
|
||||
echo "==> build-linux & test-linux (x86_64)"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
@@ -81,18 +93,22 @@ 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"
|
||||
' run_in_container "$X64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
|
||||
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 x86_64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$X64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
# ── Linux ARM64 build and package ────────────────────────────────────────────
|
||||
if [ "$RUN_ARM64" = true ]; then
|
||||
prepare_image "linux-arm64"
|
||||
ARM64_IMAGE="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-linux-arm64:latest}"
|
||||
[ "$BUILD_IMAGE" = true ] && ARM64_IMAGE="${CUSTOM_IMAGE:-asteria-qt-ci-linux-arm64:latest}"
|
||||
|
||||
echo "==> build-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux-arm64 -G Ninja \
|
||||
@@ -103,14 +119,14 @@ cmake -B build-linux-arm64 -G Ninja \
|
||||
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"
|
||||
' run_in_container "$ARM64_IMAGE" -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"
|
||||
' run_in_container "$ARM64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
+60
-29
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
# Run CI build/package jobs locally using podman or docker.
|
||||
# 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
|
||||
# --build-image build the CI image target(s) from Dockerfile instead of pulling prebuilt ones
|
||||
# --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
|
||||
@@ -13,8 +13,8 @@ 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="${PREBUILT_IMAGE:-registry.gitlab.com/asteria-bookreader/asteria-qt/build-env:latest}"
|
||||
IMAGE_TAG="$PREBUILT_IMAGE"
|
||||
IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-registry.gitlab.com/asteria-bookreader/asteria-qt}"
|
||||
CUSTOM_IMAGE=""
|
||||
BUILD_IMAGE=false
|
||||
RUN_LINUX=false
|
||||
RUN_X86_64=true
|
||||
@@ -22,9 +22,9 @@ RUN_ARM64=false
|
||||
|
||||
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 ;;
|
||||
--build-image) BUILD_IMAGE=true; shift ;;
|
||||
--image) CUSTOM_IMAGE="$2"; shift 2 ;;
|
||||
--image=*) CUSTOM_IMAGE="${1#*=}"; shift ;;
|
||||
--linux) RUN_LINUX=true; shift ;;
|
||||
--arm64) RUN_ARM64=true; shift ;;
|
||||
--only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;;
|
||||
@@ -43,20 +43,37 @@ else
|
||||
fi
|
||||
echo "Using container runtime: $RUNTIME"
|
||||
|
||||
if [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "==> Building CI image from $DOCKERFILE"
|
||||
"$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg QT_VERSION=6.12.0 \
|
||||
-t "$IMAGE_TAG" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
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
|
||||
resolve_image_tag() {
|
||||
local target="$1"
|
||||
if [ -n "$CUSTOM_IMAGE" ]; then
|
||||
echo "$CUSTOM_IMAGE"
|
||||
elif [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "asteria-qt-ci-${target}:latest"
|
||||
else
|
||||
echo "${IMAGE_PREFIX}/build-${target}:latest"
|
||||
fi
|
||||
}
|
||||
|
||||
prepare_image() {
|
||||
local target="$1"
|
||||
local image_tag
|
||||
image_tag="$(resolve_image_tag "$target")"
|
||||
if [ "$BUILD_IMAGE" = true ]; then
|
||||
echo "==> Building CI image target '$target' ($image_tag) from $DOCKERFILE"
|
||||
DOCKER_BUILDKIT=1 "$RUNTIME" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg QT_VERSION=6.12.0 \
|
||||
--target "$target" \
|
||||
-t "$image_tag" \
|
||||
-f "$DOCKERFILE" \
|
||||
"$PROJECT_DIR"
|
||||
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
|
||||
}
|
||||
|
||||
rm -rf "$OUTPUT_DIR"
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
@@ -64,13 +81,15 @@ 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 image_tag="$1"
|
||||
shift
|
||||
local extra_args=("$@")
|
||||
"$RUNTIME" run --rm \
|
||||
--platform linux/amd64 \
|
||||
--entrypoint bash \
|
||||
-v "$PROJECT_DIR:/src-ro:ro" \
|
||||
"${extra_args[@]}" \
|
||||
"$IMAGE_TAG" \
|
||||
"$image_tag" \
|
||||
-c '
|
||||
set -euo pipefail
|
||||
cp -r /src-ro /src
|
||||
@@ -81,6 +100,9 @@ run_in_container() {
|
||||
|
||||
# ── Windows x86_64 build ─────────────────────────────────────────────────────
|
||||
if [ "$RUN_X86_64" = true ]; then
|
||||
prepare_image "windows-x86_64"
|
||||
WIN_X64_IMAGE="$(resolve_image_tag "windows-x86_64")"
|
||||
|
||||
echo "==> build-windows (x86_64)"
|
||||
CI_SCRIPT='
|
||||
PKG_CONFIG_PATH="${MINGW_SYSROOT}/lib/pkgconfig" cmake -B build-windows -G Ninja \
|
||||
@@ -91,18 +113,21 @@ PKG_CONFIG_PATH="${MINGW_SYSROOT}/lib/pkgconfig" cmake -B build-windows -G Ninja
|
||||
-DQT_HOST_PATH="${QT_LINUX_DIR}"
|
||||
cmake --build build-windows --target asteria-qt
|
||||
cp -r build-windows /out/build-windows
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$WIN_X64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
|
||||
echo "==> package-windows (x86_64)"
|
||||
CI_SCRIPT='
|
||||
cp -r /out/build-windows build-windows
|
||||
chmod +x packaging/package-windows.sh
|
||||
packaging/package-windows.sh build-windows "${QT_WINDOWS_DIR}" "${MINGW_SYSROOT}" /out x86_64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$WIN_X64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
# ── Windows ARM64 build (optional) ───────────────────────────────────────────
|
||||
if [ "$RUN_ARM64" = true ]; then
|
||||
prepare_image "windows-arm64"
|
||||
WIN_ARM64_IMAGE="$(resolve_image_tag "windows-arm64")"
|
||||
|
||||
echo "==> build-windows-arm64"
|
||||
CI_SCRIPT='
|
||||
PKG_CONFIG_PATH="${MINGW_ARM64_SYSROOT}/lib/pkgconfig" cmake -B build-windows-arm64 -G Ninja \
|
||||
@@ -113,36 +138,42 @@ PKG_CONFIG_PATH="${MINGW_ARM64_SYSROOT}/lib/pkgconfig" cmake -B build-windows-ar
|
||||
-DQT_HOST_PATH="${QT_LINUX_DIR}"
|
||||
cmake --build build-windows-arm64 --target asteria-qt
|
||||
cp -r build-windows-arm64 /out/build-windows-arm64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$WIN_ARM64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
|
||||
echo "==> package-windows-arm64"
|
||||
CI_SCRIPT='
|
||||
cp -r /out/build-windows-arm64 build-windows-arm64
|
||||
chmod +x packaging/package-windows.sh
|
||||
packaging/package-windows.sh build-windows-arm64 "${QT_WINDOWS_ARM64_DIR}" "${MINGW_ARM64_SYSROOT}" /out arm64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$WIN_ARM64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
# ── Linux build (optional) ───────────────────────────────────────────────────
|
||||
if [ "$RUN_LINUX" = true ]; then
|
||||
if [ "$RUN_X86_64" = true ]; then
|
||||
prepare_image "linux-x86_64"
|
||||
LINUX_X64_IMAGE="$(resolve_image_tag "linux-x86_64")"
|
||||
|
||||
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 -r build-linux /out/build-linux
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$LINUX_X64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
|
||||
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 x86_64
|
||||
' run_in_container -v "$OUTPUT_DIR:/out"
|
||||
' run_in_container "$LINUX_X64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
|
||||
if [ "$RUN_ARM64" = true ]; then
|
||||
prepare_image "linux-arm64"
|
||||
LINUX_ARM64_IMAGE="$(resolve_image_tag "linux-arm64")"
|
||||
|
||||
echo "==> build-linux-arm64"
|
||||
CI_SCRIPT='
|
||||
cmake -B build-linux-arm64 -G Ninja \
|
||||
@@ -152,14 +183,14 @@ cmake -B build-linux-arm64 -G Ninja \
|
||||
-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"
|
||||
' run_in_container "$LINUX_ARM64_IMAGE" -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"
|
||||
' run_in_container "$LINUX_ARM64_IMAGE" -v "$OUTPUT_DIR:/out"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in new issue
Block a user