Files
eric 80aa37b21e
build / build (push) Successful in 5m23s
wheel: une roue par CPython 3.10 à 3.14 (uv), patchelf de PyPI pour auditwheel
Run 10 : les deux paquets Debian sortent ; auditwheel refusait le patchelf
0.14.3 d'Ubuntu (>= 0.14.5 requis). Et une seule roue cp310 ne servirait
pas DGX OS (Python 3.12) : uv fournit chaque interpréteur.
2026-09-24 18:56:05 +02:00

130 lines
5.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Construction de CTranslate2 avec CUDA pour Linux aarch64 : paquets Debian
# (libctranslate2-4, libctranslate2-dev) puis roue Python liée à la même
# bibliothèque. Tourne dans l'image CUDA (CI, Dockerfile) ou sur un hôte
# qui a nvcc. Étapes : deps | source | deb | wheel | check | all.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")" && pwd)
# shellcheck source=versions.env
. "$ROOT/versions.env"
JOBS=${JOBS:-$(nproc)} # en CI, borné à la part de CPU du conteneur
WORK=${WORK:-$ROOT/work}
DIST=${DIST:-$ROOT/dist}
SRC=$WORK/CTranslate2
STAGE=$WORK/stage # vue « prefix » de l'installation Debian
export DEBIAN_FRONTEND=noninteractive
log() { printf '\n== %s\n' "$*" >&2; }
etape_deps() {
log "dépendances de construction"
if [ "$(id -u)" -ne 0 ]; then SUDO=sudo; else SUDO=; fi
$SUDO apt-get update -q
$SUDO apt-get install -y -q --no-install-recommends \
build-essential cmake ninja-build git ca-certificates pkg-config \
libopenblas-dev libgomp1 \
debhelper devscripts fakeroot lintian \
python3-dev python3-venv python3-pip patchelf
command -v nvcc >/dev/null || export PATH=/usr/local/cuda/bin:$PATH
nvcc --version | tail -1
}
etape_source() {
log "sources CTranslate2 v$CT2_VERSION (sous-modules inclus : ruy, cpu_features…)"
mkdir -p "$WORK"
if [ ! -d "$SRC/.git" ]; then
git clone --recursive --depth 1 --branch "v$CT2_VERSION" "$CT2_UPSTREAM" "$SRC"
fi
git -C "$SRC" describe --tags
rm -rf "$SRC/debian"
cp -a "$ROOT/debian" "$SRC/debian"
}
etape_deb() {
log "paquets Debian (dpkg-buildpackage, $JOBS tâches)"
command -v nvcc >/dev/null || export PATH=/usr/local/cuda/bin:$PATH
cd "$SRC"
export CUDA_ARCH_LIST CUDA_NVCC_EXTRA
# -b : binaires seulement (pas de tarball orig) ; -nc : ne pas nettoyer,
# une relance reprend la compilation là où elle s'est arrêtée.
dpkg-buildpackage -b -us -uc -nc -j"$JOBS"
mkdir -p "$DIST"
mv -f "$WORK"/*.deb "$DIST"/
mv -f "$WORK"/*.buildinfo "$WORK"/*.changes "$DIST"/ 2>/dev/null || true
ls -la "$DIST"
}
etape_wheel() {
log "roue Python liée à la bibliothèque du paquet"
# setup.py cherche include/ et lib/ sous CTRANSLATE2_ROOT ; Debian installe
# sous lib/aarch64-linux-gnu, d'où cette vue par liens symboliques.
TMP=$SRC/debian/tmp/usr
[ -e "$TMP/include/ctranslate2" ] || { echo "installation Debian absente : lancer l'étape deb" >&2; exit 1; }
rm -rf "$STAGE" && mkdir -p "$STAGE"
ln -s "$TMP/include" "$STAGE/include"
ln -s "$TMP/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)" "$STAGE/lib"
# Outillage : uv fournit les CPython demandés (l'image n'a que le 3.10
# d'Ubuntu 22.04), patchelf de PyPI remplace le 0.14.3 d'Ubuntu, trop
# vieux pour auditwheel (>= 0.14.5).
python3 -m venv "$WORK/venv"
# shellcheck disable=SC1091
. "$WORK/venv/bin/activate"
pip install -q -U pip auditwheel patchelf uv
export UV_PYTHON_INSTALL_DIR=$WORK/pythons
# Étiquette manylinux d'après la glibc de l'image (2.35 → manylinux_2_35).
GLIBC=$(ldd --version | head -1 | grep -oE '[0-9]+\.[0-9]+$' | tr . _)
mkdir -p "$DIST"
for py in $PYTHON_VERSIONS; do
log "roue pour CPython $py"
uv venv -q --python "$py" "$WORK/venv-$py"
uv pip install -q --python "$WORK/venv-$py/bin/python" setuptools wheel pybind11
rm -rf "$WORK/wheel-raw-$py"
CTRANSLATE2_ROOT=$STAGE "$WORK/venv-$py/bin/python" -m pip wheel -q --no-deps --no-build-isolation \
"$SRC/python" -w "$WORK/wheel-raw-$py" 2>/dev/null \
|| { uv pip install -q --python "$WORK/venv-$py/bin/python" pip \
&& CTRANSLATE2_ROOT=$STAGE "$WORK/venv-$py/bin/python" -m pip wheel -q --no-deps --no-build-isolation \
"$SRC/python" -w "$WORK/wheel-raw-$py"; }
# Les bibliothèques CUDA ne sont PAS embarquées : CTranslate2 les charge
# dynamiquement (CUDA_DYNAMIC_LOADING) depuis le toolkit ou les paquets
# pip nvidia-*. Seules libctranslate2 et OpenBLAS entrent dans la roue.
LD_LIBRARY_PATH=$STAGE/lib auditwheel repair \
--plat "manylinux_${GLIBC}_aarch64" \
--exclude 'libcuda.so.1' --exclude 'libcublas*' --exclude 'libcublasLt*' \
--exclude 'libcudnn*' --exclude 'libcudart*' \
-w "$DIST" "$WORK/wheel-raw-$py"/*.whl
done
ls -la "$DIST"/*.whl
}
etape_check() {
log "contrôles sans GPU"
# shellcheck disable=SC1091
. "$WORK/venv/bin/activate"
pip install -q "$DIST"/ctranslate2-*-cp310-*.whl numpy pyyaml
python3 - <<'PY'
import ctranslate2, subprocess, glob, os
print("ctranslate2", ctranslate2.__version__)
lib = glob.glob(os.path.join(os.path.dirname(ctranslate2.__file__), "..", "ctranslate2.libs", "libctranslate2*"))[0]
syms = subprocess.run(["nm", "-D", lib], capture_output=True, text=True).stdout
assert "cublas" in syms.lower() or "cuda" in syms.lower(), "bibliothèque sans symboles CUDA"
print("symboles CUDA présents dans", os.path.basename(lib))
print("GPU visibles ici (0 attendu en CI) :", ctranslate2.get_cuda_device_count())
PY
dpkg-deb -I "$DIST"/libctranslate2-4_*.deb | sed -n '1,25p'
lintian --no-tag-display-limit "$DIST"/*.deb || true
}
case "${1:-all}" in
deps) etape_deps ;;
source) etape_source ;;
deb) etape_deb ;;
wheel) etape_wheel ;;
check) etape_check ;;
all) etape_deps; etape_source; etape_deb; etape_wheel; etape_check ;;
*) echo "usage : $0 {deps|source|deb|wheel|check|all}" >&2; exit 2 ;;
esac