moaaar ci changes

This commit is contained in:
Agel committed 2026-11-13 11:41:27 +01:00
1 parent 1ef94b910a
commit 1c83b4cb6b
7 files changed
+459 -131

No files matched your search

+84 -14
View File
@@ -21,6 +21,7 @@ workflow:
CI_PIPELINE_TYPE: normal CI_PIPELINE_TYPE: normal
- changes: - changes:
- docker/Dockerfile.build - docker/Dockerfile.build
- docker/entrypoint.sh
- scripts/download-mingw-arm64-qt.py - scripts/download-mingw-arm64-qt.py
- scripts/install-deps-ubuntu.sh - scripts/install-deps-ubuntu.sh
- scripts/linux-arm64-toolchain.cmake - scripts/linux-arm64-toolchain.cmake
@@ -40,31 +41,100 @@ stages:
variables: variables:
GIT_CLEAN_FLAGS: -fdx GIT_CLEAN_FLAGS: -fdx
# ── Build the runner image and push to registry ──────────────────────────────── # ── Build split runner images and push to registry ─────────────────────────────
build-docker: .build-docker-base:
stage: build stage: build
image: docker:27 image: docker:27
services: services:
- docker:27-dind - docker:27-dind
variables: variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
DOCKER_IMAGE: "${CI_REGISTRY_IMAGE}/build-env:latest" DOCKER_BUILDKIT: "1"
before_script: before_script:
- docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}"
script: script:
- docker build - docker build
--pull
--build-arg QT_VERSION=6.12.0 --build-arg QT_VERSION=6.12.0
--build-arg BUILDKIT_INLINE_CACHE=1
--cache-from "${DOCKER_IMAGE}"
--target "${DOCKER_TARGET}"
-t "${DOCKER_IMAGE}" -t "${DOCKER_IMAGE}"
-f docker/Dockerfile.build . -f docker/Dockerfile.build .
- docker push "${DOCKER_IMAGE}" - docker push "${DOCKER_IMAGE}"
build-docker-linux-x86_64:
extends: .build-docker-base
variables:
DOCKER_TARGET: "linux-x86_64"
DOCKER_IMAGE: "${CI_REGISTRY_IMAGE}/build-linux-x86_64:latest"
rules: rules:
- if: $CI_PIPELINE_TYPE == "image-rebuild" - if: $CI_PIPELINE_TYPE != "image-rebuild"
when: never
- if: '"$[[ inputs.FORCE_REBUILD_IMAGE ]]" == "true" || $FORCE_REBUILD_IMAGE == "true"'
when: on_success
- changes:
- docker/Dockerfile.build
- docker/entrypoint.sh
- scripts/install-deps-ubuntu.sh
when: on_success
build-docker-linux-arm64:
extends: .build-docker-base
variables:
DOCKER_TARGET: "linux-arm64"
DOCKER_IMAGE: "${CI_REGISTRY_IMAGE}/build-linux-arm64:latest"
rules:
- if: $CI_PIPELINE_TYPE != "image-rebuild"
when: never
- if: '"$[[ inputs.FORCE_REBUILD_IMAGE ]]" == "true" || $FORCE_REBUILD_IMAGE == "true"'
when: on_success
- changes:
- docker/Dockerfile.build
- docker/entrypoint.sh
- scripts/install-deps-ubuntu.sh
- scripts/linux-arm64-toolchain.cmake
when: on_success
build-docker-windows-x86_64:
extends: .build-docker-base
variables:
DOCKER_TARGET: "windows-x86_64"
DOCKER_IMAGE: "${CI_REGISTRY_IMAGE}/build-windows-x86_64:latest"
rules:
- if: $CI_PIPELINE_TYPE != "image-rebuild"
when: never
- if: '"$[[ inputs.FORCE_REBUILD_IMAGE ]]" == "true" || $FORCE_REBUILD_IMAGE == "true"'
when: on_success
- changes:
- docker/Dockerfile.build
- docker/entrypoint.sh
- scripts/download-mingw-arm64-qt.py
- scripts/mingw-w64-toolchain.cmake
when: on_success
build-docker-windows-arm64:
extends: .build-docker-base
variables:
DOCKER_TARGET: "windows-arm64"
DOCKER_IMAGE: "${CI_REGISTRY_IMAGE}/build-windows-arm64:latest"
rules:
- if: $CI_PIPELINE_TYPE != "image-rebuild"
when: never
- if: '"$[[ inputs.FORCE_REBUILD_IMAGE ]]" == "true" || $FORCE_REBUILD_IMAGE == "true"'
when: on_success
- changes:
- docker/Dockerfile.build
- docker/entrypoint.sh
- scripts/download-mingw-arm64-qt.py
- scripts/mingw-w64-arm64-toolchain.cmake
when: on_success
# ── Linux native build (x86_64) ──────────────────────────────────────────────── # ── Linux native build (x86_64) ────────────────────────────────────────────────
build-linux: build-linux:
interruptible: true interruptible: true
tags: tags:
- linux-qt - linux-x86_64
stage: build stage: build
script: script:
- cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release - cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release
@@ -85,7 +155,7 @@ build-linux:
build-linux-arm64: build-linux-arm64:
interruptible: true interruptible: true
tags: tags:
- linux-qt - linux-arm64
stage: build stage: build
script: script:
- cmake -B build-linux-arm64 -G Ninja - cmake -B build-linux-arm64 -G Ninja
@@ -109,7 +179,7 @@ build-linux-arm64:
build-windows: build-windows:
interruptible: true interruptible: true
tags: tags:
- linux-qt - windows-x86_64
stage: build stage: build
script: script:
- PKG_CONFIG_PATH="${MINGW_SYSROOT}/lib/pkgconfig" cmake -B build-windows -G Ninja - PKG_CONFIG_PATH="${MINGW_SYSROOT}/lib/pkgconfig" cmake -B build-windows -G Ninja
@@ -134,7 +204,7 @@ build-windows:
build-windows-arm64: build-windows-arm64:
interruptible: true interruptible: true
tags: tags:
- linux-qt - windows-arm64
stage: build stage: build
script: script:
- PKG_CONFIG_PATH="${MINGW_ARM64_SYSROOT}/lib/pkgconfig" cmake -B build-windows-arm64 -G Ninja - PKG_CONFIG_PATH="${MINGW_ARM64_SYSROOT}/lib/pkgconfig" cmake -B build-windows-arm64 -G Ninja
@@ -184,7 +254,7 @@ build-macos:
test-linux: test-linux:
interruptible: true interruptible: true
tags: tags:
- linux-qt - linux-x86_64
stage: test stage: test
needs: [] needs: []
script: script:
@@ -222,7 +292,7 @@ test-macos:
package-linux: package-linux:
interruptible: true interruptible: true
tags: tags:
- linux-qt - linux-x86_64
stage: package stage: package
needs: needs:
- build-linux - build-linux
@@ -245,7 +315,7 @@ package-linux:
package-linux-arm64: package-linux-arm64:
interruptible: true interruptible: true
tags: tags:
- linux-qt - linux-arm64
stage: package stage: package
needs: needs:
- build-linux-arm64 - build-linux-arm64
@@ -268,7 +338,7 @@ package-linux-arm64:
package-windows: package-windows:
interruptible: true interruptible: true
tags: tags:
- linux-qt - windows-x86_64
stage: package stage: package
needs: needs:
- build-windows - build-windows
@@ -290,7 +360,7 @@ package-windows:
package-windows-arm64: package-windows-arm64:
interruptible: true interruptible: true
tags: tags:
- linux-qt - windows-arm64
stage: package stage: package
needs: needs:
- build-windows-arm64 - build-windows-arm64
@@ -340,7 +410,7 @@ package-macos:
update-wiki: update-wiki:
stage: wiki stage: wiki
tags: tags:
- linux-qt - linux-x86_64
needs: needs:
- package-linux - package-linux
- package-linux-arm64 - package-linux-arm64
+11 -1
View File
@@ -97,7 +97,7 @@ packaging/package-windows.sh build-windows-arm64 /opt/qt/6.12.0/mingw_arm64 /opt
``` ```
### Linux Build Environment (Ubuntu 24.04 — x86_64 & ARM64) ### Linux Build Environment (Ubuntu 24.04 — x86_64 & ARM64)
Setup via `sudo scripts/install-deps-ubuntu.sh` (add `--with-arm64` to also install Ubuntu `arm64` multiarch packages and `linux_gcc_arm64` Qt 6.12.0): Setup via `sudo scripts/install-deps-ubuntu.sh` (add `--with-arm64` to also install Ubuntu `arm64` multiarch packages and `linux_gcc_arm64` Qt 6.12.0; CI targets also use `--skip-qt`, `--only-arm64`, and `--prune-qt`):
```bash ```bash
# Native x86_64 build & tests # Native x86_64 build & tests
cmake -S . -B build -G Ninja \ cmake -S . -B build -G Ninja \
@@ -120,6 +120,16 @@ packaging/package-linux.sh build-linux /opt/qt/6.12.0/gcc_64 dist x86_64
packaging/package-linux.sh build-linux-arm64 /opt/qt/6.12.0/gcc_arm64 dist arm64 packaging/package-linux.sh build-linux-arm64 /opt/qt/6.12.0/gcc_arm64 dist arm64
``` ```
### GitLab CI Split Docker Images (`docker/Dockerfile.build`)
The CI environment is split into 4 multi-stage targets on `ubuntu:24.04` sharing a common `base` layer (core CLI tools, host `QT_LINUX_DIR` for `QT_HOST_PATH`, and `gitlab-runner`) plus `linux-base` / `windows-base` intermediate layers:
| Image | Docker `--target` | Runner Tag | Purpose |
|---|---|---|---|
| `${CI_REGISTRY_IMAGE}/build-linux-x86_64:latest` | `linux-x86_64` | `linux-x86_64` | `build-linux`, `test-linux`, `package-linux`, `update-wiki` |
| `${CI_REGISTRY_IMAGE}/build-linux-arm64:latest` | `linux-arm64` | `linux-arm64` | `build-linux-arm64`, `package-linux-arm64` |
| `${CI_REGISTRY_IMAGE}/build-windows-x86_64:latest` | `windows-x86_64` | `windows-x86_64` | `build-windows`, `package-windows` |
| `${CI_REGISTRY_IMAGE}/build-windows-arm64:latest` | `windows-arm64` | `windows-arm64` | `build-windows-arm64`, `package-windows-arm64` |
In `.gitlab-ci.yml`, `image-rebuild` pipelines rebuild only the affected target image(s) when relevant files change, or all 4 in parallel when `FORCE_REBUILD_IMAGE=true`.
### macOS Build Environment ### macOS Build Environment
```bash ```bash
scripts/install-deps-macos.sh scripts/install-deps-macos.sh
+162 -52
View File
@@ -1,64 +1,63 @@
FROM ubuntu:24.04 # Multi-stage CI runner images for asteria-qt (all sharing the `base` layer).
# Targets:
# - linux-x86_64 : Native Linux x86_64 build, CTest, AppImage packaging, and wiki jobs
# - linux-arm64 : Cross-compiled Linux ARM64 build and AppImage packaging
# - windows-x86_64 : Cross-compiled Windows x86_64 build and portable zip packaging
# - windows-arm64 : Cross-compiled Windows ARM64 build and portable zip packaging
FROM ubuntu:24.04 AS base
ARG QT_VERSION=6.12.0 ARG QT_VERSION=6.12.0
ARG QT_INSTALL_DIR=/opt/qt ARG QT_INSTALL_DIR=/opt/qt
ARG LLVM_MINGW_VERSION=20240917
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
ENV QT_VERSION=${QT_VERSION} ENV QT_VERSION=${QT_VERSION}
ENV QT_INSTALL_DIR=${QT_INSTALL_DIR} ENV QT_INSTALL_DIR=${QT_INSTALL_DIR}
ENV QT_LINUX_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64 ENV QT_LINUX_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64
ENV QT_LINUX_ARM64_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64
ENV QT_WINDOWS_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/mingw_64
ENV QT_WINDOWS_ARM64_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/mingw_arm64
ENV MINGW_SYSROOT=${QT_WINDOWS_DIR}
ENV MINGW_ARM64_SYSROOT=${QT_WINDOWS_ARM64_DIR}
# ── Linux x86_64 & ARM64 dependencies + Qt 6 (via install-deps-ubuntu.sh) ────── # ── Core CLI tools, Qt host runtime libs, and host Qt 6 (QT_HOST_PATH) ─────────
COPY scripts/install-deps-ubuntu.sh /tmp/install-deps-ubuntu.sh RUN apt-get update -qq && \
RUN chmod +x /tmp/install-deps-ubuntu.sh && \ apt-get install -y --no-install-recommends \
QT_VERSION=${QT_VERSION} QT_INSTALL_DIR=${QT_INSTALL_DIR} /tmp/install-deps-ubuntu.sh --with-arm64 && \ ca-certificates \
rm -rf /tmp/install-deps-ubuntu.sh /var/lib/apt/lists/* cmake \
curl \
# ── llvm-mingw cross-compiler (targets both x86_64-w64-mingw32 & aarch64-w64-mingw32) ── file \
RUN wget -q https://github.com/mstorsjo/llvm-mingw/releases/download/${LLVM_MINGW_VERSION}/llvm-mingw-${LLVM_MINGW_VERSION}-ucrt-ubuntu-20.04-x86_64.tar.xz \ git \
-O /tmp/llvm-mingw.tar.xz && \ jq \
tar -xf /tmp/llvm-mingw.tar.xz -C /opt && \ libdbus-1-3 \
mv /opt/llvm-mingw-${LLVM_MINGW_VERSION}-ucrt-ubuntu-20.04-x86_64 /opt/llvm-mingw && \ libegl1 \
rm /tmp/llvm-mingw.tar.xz libfontconfig1 \
libfreetype6 \
ENV PATH="/opt/llvm-mingw/bin:${PATH}" libgl1 \
libglib2.0-0t64 \
# ── Windows x86_64 & ARM64 prebuilt MSYS2 sysroots (Qt 6 + third-party libs) ─── libxkbcommon0 \
COPY scripts/download-mingw-arm64-qt.py /tmp/download-mingw-arm64-qt.py ninja-build \
RUN chmod +x /tmp/download-mingw-arm64-qt.py && \ pkg-config \
python3 /tmp/download-mingw-arm64-qt.py --arch x86_64 --dest "${QT_WINDOWS_DIR}" && \ python3 \
python3 /tmp/download-mingw-arm64-qt.py --arch arm64 --dest "${QT_WINDOWS_ARM64_DIR}" && \ python3-venv \
ln -sfn "${QT_WINDOWS_DIR}" /opt/mingw-sysroot && \ wget \
ln -sfn "${QT_WINDOWS_ARM64_DIR}" /opt/mingw-arm64-sysroot && \ xz-utils \
rm /tmp/download-mingw-arm64-qt.py zip \
zstd \
# ── CMake cross-compilation toolchain files ──────────────────────────────────── && rm -rf /var/lib/apt/lists/* \
COPY scripts/mingw-w64-toolchain.cmake /opt/mingw-w64-toolchain.cmake && python3 -m venv /tmp/aqt-venv \
COPY scripts/mingw-w64-arm64-toolchain.cmake /opt/mingw-w64-arm64-toolchain.cmake && /tmp/aqt-venv/bin/pip install --quiet aqtinstall \
COPY scripts/linux-arm64-toolchain.cmake /opt/linux-arm64-toolchain.cmake && /tmp/aqt-venv/bin/aqt install-qt linux desktop "${QT_VERSION}" linux_gcc_64 \
-m qtimageformats --outputdir "${QT_INSTALL_DIR}" \
# ── appimagetool & static AppImage runtimes (x86_64 & aarch64) ───────────────── && rm -rf /tmp/aqt-venv \
# Note: Zeroing AppImage magic bytes 8-10 allows extraction under both native Linux and Rosetta 2 && rm -rf \
RUN mkdir -p /opt/appimage && \ "${QT_LINUX_DIR}/doc" \
wget -q https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage \ "${QT_LINUX_DIR}/examples" \
-O /tmp/appimagetool && \ "${QT_LINUX_DIR}/phrasebooks" \
chmod +x /tmp/appimagetool && \ "${QT_LINUX_DIR}/translations" \
printf '\000\000\000' | dd of=/tmp/appimagetool bs=1 seek=8 count=3 conv=notrunc && \ "${QT_LINUX_DIR}/qml/QtQuick/LocalStorage" \
cd /tmp && /tmp/appimagetool --appimage-extract && \ "${QT_LINUX_DIR}/qml/QtQuick/Particles" \
mv squashfs-root /opt/appimagetool && \ "${QT_LINUX_DIR}/qml/QtQuick/Pdf" \
ln -sf /opt/appimagetool/AppRun /usr/local/bin/appimagetool && \ "${QT_LINUX_DIR}/qml/QtQuick/Scene2D" \
rm /tmp/appimagetool && \ "${QT_LINUX_DIR}/qml/QtQuick/Scene3D" \
wget -q https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-x86_64 \ "${QT_LINUX_DIR}/qml/QtQuick/Timeline" \
-O /opt/appimage/runtime-x86_64 && \ "${QT_LINUX_DIR}/qml/QtQuick/VirtualKeyboard" \
wget -q https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-aarch64 \ "${QT_LINUX_DIR}/qml/QtQuick/tooling"
-O /opt/appimage/runtime-aarch64 && \
chmod +x /opt/appimage/runtime-x86_64 /opt/appimage/runtime-aarch64
# ── gitlab-runner (shell executor) ───────────────────────────────────────────── # ── gitlab-runner (shell executor) ─────────────────────────────────────────────
RUN wget -q https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 \ RUN wget -q https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 \
@@ -72,3 +71,114 @@ RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD [] CMD []
# ==============================================================================
# Shared Linux packaging layer (patchelf + binutils/readelf + appimagetool)
# ==============================================================================
FROM base AS linux-base
# Note: Zeroing AppImage magic bytes 8-10 allows extraction under both native Linux and Rosetta 2
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends binutils patchelf && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /opt/appimage && \
wget -q https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage \
-O /tmp/appimagetool && \
chmod +x /tmp/appimagetool && \
printf '\000\000\000' | dd of=/tmp/appimagetool bs=1 seek=8 count=3 conv=notrunc && \
cd /tmp && /tmp/appimagetool --appimage-extract && \
mv squashfs-root /opt/appimagetool && \
ln -sf /opt/appimagetool/AppRun /usr/local/bin/appimagetool && \
rm /tmp/appimagetool
# ==============================================================================
# Target 1: Linux x86_64 (native build, CTest, AppImage, wiki)
# ==============================================================================
FROM linux-base AS linux-x86_64
COPY scripts/install-deps-ubuntu.sh /tmp/install-deps-ubuntu.sh
RUN chmod +x /tmp/install-deps-ubuntu.sh && \
QT_VERSION=${QT_VERSION} QT_INSTALL_DIR=${QT_INSTALL_DIR} \
/tmp/install-deps-ubuntu.sh --skip-qt && \
rm -rf /tmp/install-deps-ubuntu.sh /var/lib/apt/lists/* && \
wget -q https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-x86_64 \
-O /opt/appimage/runtime-x86_64 && \
chmod +x /opt/appimage/runtime-x86_64 && \
g++ --version
# ==============================================================================
# Target 2: Linux ARM64 (aarch64 cross-compile + AppImage)
# ==============================================================================
FROM linux-base AS linux-arm64
ENV QT_LINUX_ARM64_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64
COPY scripts/install-deps-ubuntu.sh /tmp/install-deps-ubuntu.sh
RUN chmod +x /tmp/install-deps-ubuntu.sh && \
QT_VERSION=${QT_VERSION} QT_INSTALL_DIR=${QT_INSTALL_DIR} \
/tmp/install-deps-ubuntu.sh --only-arm64 --prune-qt && \
rm -rf /tmp/install-deps-ubuntu.sh /var/lib/apt/lists/* && \
wget -q https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-aarch64 \
-O /opt/appimage/runtime-aarch64 && \
chmod +x /opt/appimage/runtime-aarch64
COPY scripts/linux-arm64-toolchain.cmake /opt/linux-arm64-toolchain.cmake
# ==============================================================================
# Shared Windows cross-compilation base (llvm-mingw pruned to 64-bit targets)
# ==============================================================================
FROM base AS windows-base
ARG LLVM_MINGW_VERSION=20240917
RUN wget -q https://github.com/mstorsjo/llvm-mingw/releases/download/${LLVM_MINGW_VERSION}/llvm-mingw-${LLVM_MINGW_VERSION}-ucrt-ubuntu-20.04-x86_64.tar.xz \
-O /tmp/llvm-mingw.tar.xz && \
tar -xf /tmp/llvm-mingw.tar.xz -C /opt && \
mv /opt/llvm-mingw-${LLVM_MINGW_VERSION}-ucrt-ubuntu-20.04-x86_64 /opt/llvm-mingw && \
rm -rf /tmp/llvm-mingw.tar.xz \
/opt/llvm-mingw/i686-w64-mingw32 \
/opt/llvm-mingw/armv7-w64-mingw32 \
/opt/llvm-mingw/bin/i686-* \
/opt/llvm-mingw/bin/armv7-*
ENV PATH="/opt/llvm-mingw/bin:${PATH}"
# ==============================================================================
# Target 3: Windows x86_64 (LLVM-MinGW + MSYS2 clang64 Qt 6)
# ==============================================================================
FROM windows-base AS windows-x86_64
ENV QT_WINDOWS_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/mingw_64
ENV MINGW_SYSROOT=${QT_WINDOWS_DIR}
COPY scripts/download-mingw-arm64-qt.py /tmp/download-mingw-arm64-qt.py
RUN chmod +x /tmp/download-mingw-arm64-qt.py && \
python3 /tmp/download-mingw-arm64-qt.py --arch x86_64 --dest "${QT_WINDOWS_DIR}" && \
ln -sfn "${QT_WINDOWS_DIR}" /opt/mingw-sysroot && \
rm /tmp/download-mingw-arm64-qt.py && \
x86_64-w64-mingw32-g++ --version
COPY scripts/mingw-w64-toolchain.cmake /opt/mingw-w64-toolchain.cmake
# ==============================================================================
# Target 4: Windows ARM64 (LLVM-MinGW + MSYS2 clangarm64 Qt 6)
# ==============================================================================
FROM windows-base AS windows-arm64
ENV QT_WINDOWS_ARM64_DIR=${QT_INSTALL_DIR}/${QT_VERSION}/mingw_arm64
ENV MINGW_ARM64_SYSROOT=${QT_WINDOWS_ARM64_DIR}
COPY scripts/download-mingw-arm64-qt.py /tmp/download-mingw-arm64-qt.py
RUN chmod +x /tmp/download-mingw-arm64-qt.py && \
python3 /tmp/download-mingw-arm64-qt.py --arch arm64 --dest "${QT_WINDOWS_ARM64_DIR}" && \
ln -sfn "${QT_WINDOWS_ARM64_DIR}" /opt/mingw-arm64-sysroot && \
rm /tmp/download-mingw-arm64-qt.py && \
aarch64-w64-mingw32-g++ --version
COPY scripts/mingw-w64-arm64-toolchain.cmake /opt/mingw-w64-arm64-toolchain.cmake
+57 -16
View File
@@ -9,6 +9,7 @@ Usage:
""" """
import argparse import argparse
import concurrent.futures
import glob import glob
import io import io
import os import os
@@ -17,6 +18,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import tarfile import tarfile
import tempfile
import urllib.error import urllib.error
import urllib.request import urllib.request
@@ -176,42 +178,79 @@ def resolve_dependencies(packages, provides_map, pkg_prefix):
return sorted(resolved) return sorted(resolved)
def download_and_extract_packages(resolved, repo, dest_dir): def _download_single_package(pkg_info, repo, download_dir):
os.makedirs(dest_dir, exist_ok=True) idx, total, filename = pkg_info
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 last_err = None
dest_file = os.path.join(download_dir, os.path.basename(filename))
for base in MIRROR_BASES: for base in MIRROR_BASES:
pkg_url = f"{base}/{repo}/{filename}" pkg_url = f"{base}/{repo}/{filename}"
try: try:
data = fetch_url(pkg_url, timeout=60) data = fetch_url(pkg_url, timeout=60)
with open(temp_pkg, "wb") as f: with open(dest_file, "wb") as f:
f.write(data) f.write(data)
downloaded = True print(f"[{idx}/{total}] Downloaded {filename}")
break return filename, dest_file
except Exception as e: except Exception as e:
last_err = e last_err = e
print(f" Failed from {base}/{repo} ({e}), trying next mirror...", file=sys.stderr) print(f" Failed {filename} from {base}/{repo} ({e}), trying next mirror...", file=sys.stderr)
if not downloaded:
raise RuntimeError(f"Failed to download {filename}: {last_err}") 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)
total = len(resolved)
with tempfile.TemporaryDirectory(prefix=f"msys2_{repo}_") as download_dir:
tasks = [(i, total, filename) for i, (_, filename) in enumerate(resolved, 1)]
downloaded_files = []
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())
# Extract sequentially in deterministic filename order
for filename, pkg_path in sorted(downloaded_files):
tar_res = subprocess.run( tar_res = subprocess.run(
["tar", "-I", "zstd", "-xf", temp_pkg, "--strip-components=1", "-C", dest_dir], ["tar", "-I", "zstd", "-xf", pkg_path, "--strip-components=1", "-C", dest_dir],
capture_output=True, capture_output=True,
) )
if os.path.exists(temp_pkg): os.remove(pkg_path)
os.remove(temp_pkg)
if tar_res.returncode != 0: if tar_res.returncode != 0:
err = tar_res.stderr.decode("utf-8", errors="replace") err = tar_res.stderr.decode("utf-8", errors="replace")
raise RuntimeError(f"Failed to extract {filename}: {err}") 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): def configure_sysroot(dest_dir, repo):
abs_dest = os.path.abspath(dest_dir) abs_dest = os.path.abspath(dest_dir)
@@ -241,6 +280,8 @@ def configure_sysroot(dest_dir, repo):
if os.path.isdir(tools_dir): if os.path.isdir(tools_dir):
shutil.rmtree(tools_dir) shutil.rmtree(tools_dir)
prune_sysroot(abs_dest)
def verify_installation(dest_dir): def verify_installation(dest_dir):
bin_dir = os.path.join(dest_dir, "bin") bin_dir = os.path.join(dest_dir, "bin")
+59 -9
View File
@@ -3,7 +3,7 @@
# Run with sudo or as root. # Run with sudo or as root.
# #
# Usage: # 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: # Environment variables:
# QT_VERSION Qt version to install via aqtinstall (default: 6.12.0) # 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_VERSION="${QT_VERSION:-6.12.0}"
QT_INSTALL_DIR="${QT_INSTALL_DIR:-/opt/qt}" QT_INSTALL_DIR="${QT_INSTALL_DIR:-/opt/qt}"
WITH_ARM64=false WITH_ARM64=false
ONLY_ARM64=false
SKIP_QT=false
PRUNE_QT=false
WITH_SOURCES=false WITH_SOURCES=false
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
--with-arm64) WITH_ARM64=true ;; --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 ;; --with-sources) WITH_SOURCES=true ;;
*) *)
echo "Unknown option: $arg" >&2 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 exit 1
;; ;;
esac esac
@@ -55,7 +61,10 @@ fi
echo "==> Installing system build tools and libraries..." echo "==> Installing system build tools and libraries..."
apt-get update -qq apt-get update -qq
PACKAGES=( PACKAGES=()
if [ "$ONLY_ARM64" = false ]; then
PACKAGES+=(
build-essential build-essential
ca-certificates ca-certificates
cmake cmake
@@ -104,9 +113,11 @@ PACKAGES=(
zlib1g-dev zlib1g-dev
zstd zstd
) )
fi
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
PACKAGES+=( PACKAGES+=(
gcc-aarch64-linux-gnu
g++-aarch64-linux-gnu g++-aarch64-linux-gnu
libarchive13t64:arm64 libarchive13t64:arm64
libdbus-1-dev:arm64 libdbus-1-dev:arm64
@@ -140,11 +151,16 @@ if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
libxkbcommon-x11-0:arm64 libxkbcommon-x11-0:arm64
zlib1g-dev: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 fi
apt-get install -y --no-install-recommends "${PACKAGES[@]}" apt-get install -y --no-install-recommends "${PACKAGES[@]}"
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
if [ "$ONLY_ARM64" = false ]; then
# libarchive-dev is not Multi-Arch: same on Ubuntu 24.04 (due to libext2fs-dev); # 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. # 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 ln -sf libarchive.so.13 /usr/lib/aarch64-linux-gnu/libarchive.so
@@ -153,7 +169,39 @@ if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
/usr/lib/x86_64-linux-gnu/pkgconfig/libarchive.pc \ /usr/lib/x86_64-linux-gnu/pkgconfig/libarchive.pc \
> /usr/lib/aarch64-linux-gnu/pkgconfig/libarchive.pc > /usr/lib/aarch64-linux-gnu/pkgconfig/libarchive.pc
fi 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
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
QT_NATIVE_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
fi
if [ "$SKIP_QT" = false ]; then
echo "==> Installing Qt ${QT_VERSION} via aqtinstall -> ${QT_INSTALL_DIR}..." echo "==> Installing Qt ${QT_VERSION} via aqtinstall -> ${QT_INSTALL_DIR}..."
python3 -m venv /tmp/aqt-venv python3 -m venv /tmp/aqt-venv
/tmp/aqt-venv/bin/pip install --quiet aqtinstall /tmp/aqt-venv/bin/pip install --quiet aqtinstall
@@ -161,16 +209,19 @@ python3 -m venv /tmp/aqt-venv
if [ "$HOST_ARCH" = "arm64" ]; then if [ "$HOST_ARCH" = "arm64" ]; then
/tmp/aqt-venv/bin/aqt install-qt linux_arm64 desktop "${QT_VERSION}" linux_gcc_arm64 \ /tmp/aqt-venv/bin/aqt install-qt linux_arm64 desktop "${QT_VERSION}" linux_gcc_arm64 \
-m qtimageformats --outputdir "${QT_INSTALL_DIR}" -m qtimageformats --outputdir "${QT_INSTALL_DIR}"
QT_NATIVE_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64" [ "$PRUNE_QT" = true ] && prune_qt_dir "${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
else else
if [ "$ONLY_ARM64" = false ]; then
/tmp/aqt-venv/bin/aqt install-qt linux desktop "${QT_VERSION}" linux_gcc_64 \ /tmp/aqt-venv/bin/aqt install-qt linux desktop "${QT_VERSION}" linux_gcc_64 \
-m qtimageformats --outputdir "${QT_INSTALL_DIR}" -m qtimageformats --outputdir "${QT_INSTALL_DIR}"
QT_NATIVE_DIR="${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64" [ "$PRUNE_QT" = true ] && prune_qt_dir "${QT_INSTALL_DIR}/${QT_VERSION}/gcc_64"
fi
if [ "$WITH_ARM64" = true ]; then if [ "$WITH_ARM64" = true ]; then
echo "==> Installing Qt ${QT_VERSION} (Linux arm64) via aqtinstall -> ${QT_INSTALL_DIR}..." 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 \ /tmp/aqt-venv/bin/aqt install-qt linux_arm64 desktop "${QT_VERSION}" linux_gcc_arm64 \
-m qtimageformats --outputdir "${QT_INSTALL_DIR}" -m qtimageformats --outputdir "${QT_INSTALL_DIR}"
[ "$PRUNE_QT" = true ] && prune_qt_dir "${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
fi fi
fi fi
@@ -180,14 +231,13 @@ if [ "$WITH_SOURCES" = true ]; then
fi fi
rm -rf /tmp/aqt-venv rm -rf /tmp/aqt-venv
fi
echo "" echo ""
echo "==> All Ubuntu dependencies installed." echo "==> All Ubuntu dependencies installed."
if [ "$ONLY_ARM64" = false ]; then
echo " Qt ${QT_VERSION} native path: ${QT_NATIVE_DIR}" echo " Qt ${QT_VERSION} native path: ${QT_NATIVE_DIR}"
fi
if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then if [ "$WITH_ARM64" = true ] && [ "$HOST_ARCH" = "amd64" ]; then
echo " Qt ${QT_VERSION} arm64 path: ${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64" echo " Qt ${QT_VERSION} arm64 path: ${QT_INSTALL_DIR}/${QT_VERSION}/gcc_arm64"
fi 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"
+33 -17
View File
@@ -9,17 +9,17 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
OUTPUT_DIR="$PROJECT_DIR/ci-output" OUTPUT_DIR="$PROJECT_DIR/ci-output"
DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build" DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build"
PREBUILT_IMAGE="${PREBUILT_IMAGE:-registry.gitlab.com/asteria-bookreader/asteria-qt/build-env:latest}" IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-registry.gitlab.com/asteria-bookreader/asteria-qt}"
IMAGE_TAG="$PREBUILT_IMAGE" CUSTOM_IMAGE=""
BUILD_IMAGE=false BUILD_IMAGE=false
RUN_X86_64=true RUN_X86_64=true
RUN_ARM64=false RUN_ARM64=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--build-image) BUILD_IMAGE=true; IMAGE_TAG="asteria-qt-ci-local:latest"; shift ;; --build-image) BUILD_IMAGE=true; shift ;;
--image) IMAGE_TAG="$2"; shift 2 ;; --image) CUSTOM_IMAGE="$2"; shift 2 ;;
--image=*) IMAGE_TAG="${1#*=}"; shift ;; --image=*) CUSTOM_IMAGE="${1#*=}"; shift ;;
--arm64) RUN_ARM64=true; shift ;; --arm64) RUN_ARM64=true; shift ;;
--only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;; --only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;;
*) echo "Unknown argument: $1"; exit 1 ;; *) echo "Unknown argument: $1"; exit 1 ;;
@@ -37,31 +37,39 @@ else
fi fi
echo "Using container runtime: $RUNTIME" echo "Using container runtime: $RUNTIME"
prepare_image() {
local target="$1"
local image_tag="${CUSTOM_IMAGE:-${IMAGE_PREFIX}/build-${target}:latest}"
if [ "$BUILD_IMAGE" = true ]; then if [ "$BUILD_IMAGE" = true ]; then
echo "==> Building CI image from $DOCKERFILE" image_tag="${CUSTOM_IMAGE:-asteria-qt-ci-${target}:latest}"
"$RUNTIME" build \ echo "==> Building CI image target '$target' ($image_tag) from $DOCKERFILE"
DOCKER_BUILDKIT=1 "$RUNTIME" build \
--platform linux/amd64 \ --platform linux/amd64 \
--build-arg QT_VERSION=6.12.0 \ --build-arg QT_VERSION=6.12.0 \
-t "$IMAGE_TAG" \ --target "$target" \
-t "$image_tag" \
-f "$DOCKERFILE" \ -f "$DOCKERFILE" \
"$PROJECT_DIR" "$PROJECT_DIR"
elif ! "$RUNTIME" image inspect "$IMAGE_TAG" &>/dev/null; then elif ! "$RUNTIME" image inspect "$image_tag" &>/dev/null; then
echo "==> Pulling prebuilt CI image: $IMAGE_TAG" echo "==> Pulling prebuilt CI image: $image_tag"
"$RUNTIME" pull --platform linux/amd64 "$IMAGE_TAG" "$RUNTIME" pull --platform linux/amd64 "$image_tag"
else else
echo "==> Using local image: $IMAGE_TAG" echo "==> Using local image: $image_tag"
fi fi
}
mkdir -p "$OUTPUT_DIR" mkdir -p "$OUTPUT_DIR"
run_in_container() { run_in_container() {
local image_tag="$1"
shift
local extra_args=("$@") local extra_args=("$@")
"$RUNTIME" run --rm \ "$RUNTIME" run --rm \
--platform linux/amd64 \ --platform linux/amd64 \
--entrypoint bash \ --entrypoint bash \
-v "$PROJECT_DIR:/src-ro:ro" \ -v "$PROJECT_DIR:/src-ro:ro" \
"${extra_args[@]}" \ "${extra_args[@]}" \
"$IMAGE_TAG" \ "$image_tag" \
-c ' -c '
set -euo pipefail set -euo pipefail
cp -r /src-ro /src cp -r /src-ro /src
@@ -72,6 +80,10 @@ run_in_container() {
# ── Linux x86_64 build, test, and package ──────────────────────────────────── # ── Linux x86_64 build, test, and package ────────────────────────────────────
if [ "$RUN_X86_64" = true ]; then 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)" echo "==> build-linux & test-linux (x86_64)"
CI_SCRIPT=' CI_SCRIPT='
cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release \ 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 rm -rf /out/build-linux
cp -r build-linux /out/build-linux cp -r build-linux /out/build-linux
cp build-linux/asteria-qt /out/asteria-qt 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)" echo "==> package-linux (x86_64)"
CI_SCRIPT=' CI_SCRIPT='
cp -r /out/build-linux build-linux cp -r /out/build-linux build-linux
chmod +x packaging/package-linux.sh chmod +x packaging/package-linux.sh
packaging/package-linux.sh build-linux "${QT_LINUX_DIR}" /out x86_64 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 fi
# ── Linux ARM64 build and package ──────────────────────────────────────────── # ── Linux ARM64 build and package ────────────────────────────────────────────
if [ "$RUN_ARM64" = true ]; then 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" echo "==> build-linux-arm64"
CI_SCRIPT=' CI_SCRIPT='
cmake -B build-linux-arm64 -G Ninja \ 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 cmake --build build-linux-arm64 --target asteria-qt
rm -rf /out/build-linux-arm64 rm -rf /out/build-linux-arm64
cp -r build-linux-arm64 /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" echo "==> package-linux-arm64"
CI_SCRIPT=' CI_SCRIPT='
cp -r /out/build-linux-arm64 build-linux-arm64 cp -r /out/build-linux-arm64 build-linux-arm64
chmod +x packaging/package-linux.sh chmod +x packaging/package-linux.sh
packaging/package-linux.sh build-linux-arm64 "${QT_LINUX_ARM64_DIR}" /out arm64 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 fi
echo "" echo ""
+53 -22
View File
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Run CI build/package jobs locally using podman or docker. # Run CI build/package jobs locally using podman or docker.
# Usage: test-ci-windows.sh [--build-image] [--image <tag>] [--linux] [--arm64] [--only-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 # --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) # --linux also run build-linux + package-linux (and arm64 if --arm64 is passed)
# --arm64 also run arm64 build + package jobs # --arm64 also run arm64 build + package jobs
# --only-arm64 run only 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)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
OUTPUT_DIR="$PROJECT_DIR/ci-output" OUTPUT_DIR="$PROJECT_DIR/ci-output"
DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build" DOCKERFILE="$PROJECT_DIR/docker/Dockerfile.build"
PREBUILT_IMAGE="${PREBUILT_IMAGE:-registry.gitlab.com/asteria-bookreader/asteria-qt/build-env:latest}" IMAGE_PREFIX="${PREBUILT_IMAGE_PREFIX:-registry.gitlab.com/asteria-bookreader/asteria-qt}"
IMAGE_TAG="$PREBUILT_IMAGE" CUSTOM_IMAGE=""
BUILD_IMAGE=false BUILD_IMAGE=false
RUN_LINUX=false RUN_LINUX=false
RUN_X86_64=true RUN_X86_64=true
@@ -22,9 +22,9 @@ RUN_ARM64=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--build-image) BUILD_IMAGE=true; IMAGE_TAG="asteria-qt-ci-local:latest"; shift ;; --build-image) BUILD_IMAGE=true; shift ;;
--image) IMAGE_TAG="$2"; shift 2 ;; --image) CUSTOM_IMAGE="$2"; shift 2 ;;
--image=*) IMAGE_TAG="${1#*=}"; shift ;; --image=*) CUSTOM_IMAGE="${1#*=}"; shift ;;
--linux) RUN_LINUX=true; shift ;; --linux) RUN_LINUX=true; shift ;;
--arm64) RUN_ARM64=true; shift ;; --arm64) RUN_ARM64=true; shift ;;
--only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;; --only-arm64) RUN_ARM64=true; RUN_X86_64=false; shift ;;
@@ -43,20 +43,37 @@ else
fi fi
echo "Using container runtime: $RUNTIME" echo "Using container runtime: $RUNTIME"
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 if [ "$BUILD_IMAGE" = true ]; then
echo "==> Building CI image from $DOCKERFILE" echo "==> Building CI image target '$target' ($image_tag) from $DOCKERFILE"
"$RUNTIME" build \ DOCKER_BUILDKIT=1 "$RUNTIME" build \
--platform linux/amd64 \ --platform linux/amd64 \
--build-arg QT_VERSION=6.12.0 \ --build-arg QT_VERSION=6.12.0 \
-t "$IMAGE_TAG" \ --target "$target" \
-t "$image_tag" \
-f "$DOCKERFILE" \ -f "$DOCKERFILE" \
"$PROJECT_DIR" "$PROJECT_DIR"
elif ! "$RUNTIME" image inspect "$IMAGE_TAG" &>/dev/null; then elif ! "$RUNTIME" image inspect "$image_tag" &>/dev/null; then
echo "==> Pulling prebuilt CI image: $IMAGE_TAG" echo "==> Pulling prebuilt CI image: $image_tag"
"$RUNTIME" pull --platform linux/amd64 "$IMAGE_TAG" "$RUNTIME" pull --platform linux/amd64 "$image_tag"
else else
echo "==> Using local image: $IMAGE_TAG" echo "==> Using local image: $image_tag"
fi fi
}
rm -rf "$OUTPUT_DIR" rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR" mkdir -p "$OUTPUT_DIR"
@@ -64,13 +81,15 @@ mkdir -p "$OUTPUT_DIR"
# Helper: run a command inside the CI container # Helper: run a command inside the CI container
# The project is copied into /src inside the container so the build is isolated. # The project is copied into /src inside the container so the build is isolated.
run_in_container() { run_in_container() {
local image_tag="$1"
shift
local extra_args=("$@") local extra_args=("$@")
"$RUNTIME" run --rm \ "$RUNTIME" run --rm \
--platform linux/amd64 \ --platform linux/amd64 \
--entrypoint bash \ --entrypoint bash \
-v "$PROJECT_DIR:/src-ro:ro" \ -v "$PROJECT_DIR:/src-ro:ro" \
"${extra_args[@]}" \ "${extra_args[@]}" \
"$IMAGE_TAG" \ "$image_tag" \
-c ' -c '
set -euo pipefail set -euo pipefail
cp -r /src-ro /src cp -r /src-ro /src
@@ -81,6 +100,9 @@ run_in_container() {
# ── Windows x86_64 build ───────────────────────────────────────────────────── # ── Windows x86_64 build ─────────────────────────────────────────────────────
if [ "$RUN_X86_64" = true ]; then 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)" echo "==> build-windows (x86_64)"
CI_SCRIPT=' CI_SCRIPT='
PKG_CONFIG_PATH="${MINGW_SYSROOT}/lib/pkgconfig" cmake -B build-windows -G Ninja \ 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}" -DQT_HOST_PATH="${QT_LINUX_DIR}"
cmake --build build-windows --target asteria-qt cmake --build build-windows --target asteria-qt
cp -r build-windows /out/build-windows 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)" echo "==> package-windows (x86_64)"
CI_SCRIPT=' CI_SCRIPT='
cp -r /out/build-windows build-windows cp -r /out/build-windows build-windows
chmod +x packaging/package-windows.sh chmod +x packaging/package-windows.sh
packaging/package-windows.sh build-windows "${QT_WINDOWS_DIR}" "${MINGW_SYSROOT}" /out x86_64 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 fi
# ── Windows ARM64 build (optional) ─────────────────────────────────────────── # ── Windows ARM64 build (optional) ───────────────────────────────────────────
if [ "$RUN_ARM64" = true ]; then if [ "$RUN_ARM64" = true ]; then
prepare_image "windows-arm64"
WIN_ARM64_IMAGE="$(resolve_image_tag "windows-arm64")"
echo "==> build-windows-arm64" echo "==> build-windows-arm64"
CI_SCRIPT=' CI_SCRIPT='
PKG_CONFIG_PATH="${MINGW_ARM64_SYSROOT}/lib/pkgconfig" cmake -B build-windows-arm64 -G Ninja \ 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}" -DQT_HOST_PATH="${QT_LINUX_DIR}"
cmake --build build-windows-arm64 --target asteria-qt cmake --build build-windows-arm64 --target asteria-qt
cp -r build-windows-arm64 /out/build-windows-arm64 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" echo "==> package-windows-arm64"
CI_SCRIPT=' CI_SCRIPT='
cp -r /out/build-windows-arm64 build-windows-arm64 cp -r /out/build-windows-arm64 build-windows-arm64
chmod +x packaging/package-windows.sh chmod +x packaging/package-windows.sh
packaging/package-windows.sh build-windows-arm64 "${QT_WINDOWS_ARM64_DIR}" "${MINGW_ARM64_SYSROOT}" /out arm64 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 fi
# ── Linux build (optional) ─────────────────────────────────────────────────── # ── Linux build (optional) ───────────────────────────────────────────────────
if [ "$RUN_LINUX" = true ]; then if [ "$RUN_LINUX" = true ]; then
if [ "$RUN_X86_64" = 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)" echo "==> build-linux (x86_64)"
CI_SCRIPT=' CI_SCRIPT='
cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release \ cmake -B build-linux -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="${QT_LINUX_DIR}" -DCMAKE_PREFIX_PATH="${QT_LINUX_DIR}"
cmake --build build-linux --target asteria-qt cmake --build build-linux --target asteria-qt
cp -r build-linux /out/build-linux 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)" echo "==> package-linux (x86_64)"
CI_SCRIPT=' CI_SCRIPT='
cp -r /out/build-linux build-linux cp -r /out/build-linux build-linux
chmod +x packaging/package-linux.sh chmod +x packaging/package-linux.sh
packaging/package-linux.sh build-linux "${QT_LINUX_DIR}" /out x86_64 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 fi
if [ "$RUN_ARM64" = true ]; then if [ "$RUN_ARM64" = true ]; then
prepare_image "linux-arm64"
LINUX_ARM64_IMAGE="$(resolve_image_tag "linux-arm64")"
echo "==> build-linux-arm64" echo "==> build-linux-arm64"
CI_SCRIPT=' CI_SCRIPT='
cmake -B build-linux-arm64 -G Ninja \ cmake -B build-linux-arm64 -G Ninja \
@@ -152,14 +183,14 @@ cmake -B build-linux-arm64 -G Ninja \
-DQT_HOST_PATH="${QT_LINUX_DIR}" -DQT_HOST_PATH="${QT_LINUX_DIR}"
cmake --build build-linux-arm64 --target asteria-qt cmake --build build-linux-arm64 --target asteria-qt
cp -r build-linux-arm64 /out/build-linux-arm64 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" echo "==> package-linux-arm64"
CI_SCRIPT=' CI_SCRIPT='
cp -r /out/build-linux-arm64 build-linux-arm64 cp -r /out/build-linux-arm64 build-linux-arm64
chmod +x packaging/package-linux.sh chmod +x packaging/package-linux.sh
packaging/package-linux.sh build-linux-arm64 "${QT_LINUX_ARM64_DIR}" /out arm64 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
fi fi