|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +usage() { |
| 6 | + cat <<'EOF' |
| 7 | +Usage: ./container-build.sh [x86_64|aarch64] |
| 8 | +
|
| 9 | +Build and repair one Python-independent manylinux_2_28 wheel. The architecture |
| 10 | +defaults to the Docker host architecture. Cross-architecture builds require |
| 11 | +Docker's corresponding binfmt/QEMU support. |
| 12 | +
|
| 13 | +Outputs: |
| 14 | + dist/*.whl Unrepaired Linux wheel |
| 15 | + wheelhouse/*.whl Repaired manylinux wheel |
| 16 | +EOF |
| 17 | +} |
| 18 | + |
| 19 | +if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then |
| 20 | + usage |
| 21 | + exit 0 |
| 22 | +fi |
| 23 | + |
| 24 | +case "${1:-$(uname -m)}" in |
| 25 | + x86_64|amd64) |
| 26 | + ARCH="x86_64" |
| 27 | + PLATFORM="linux/amd64" |
| 28 | + ;; |
| 29 | + aarch64|arm64) |
| 30 | + ARCH="aarch64" |
| 31 | + PLATFORM="linux/arm64" |
| 32 | + ;; |
| 33 | + *) |
| 34 | + echo "Unsupported architecture: ${1:-$(uname -m)}" >&2 |
| 35 | + usage >&2 |
| 36 | + exit 1 |
| 37 | + ;; |
| 38 | +esac |
| 39 | + |
| 40 | +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 41 | +if command -v git >/dev/null 2>&1; then |
| 42 | + REPO_ROOT="$(git -C "${SCRIPT_DIR}" rev-parse --show-toplevel 2>/dev/null || echo "${SCRIPT_DIR}")" |
| 43 | +else |
| 44 | + REPO_ROOT="${SCRIPT_DIR}" |
| 45 | +fi |
| 46 | + |
| 47 | +if [[ ! -f "${REPO_ROOT}/pyproject.toml" || ! -f "${REPO_ROOT}/CMakeLists.txt" ]]; then |
| 48 | + echo "Could not identify the spicedmodel repository root: ${REPO_ROOT}" >&2 |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +IMAGE="quay.io/pypa/manylinux_2_28_${ARCH}:latest" |
| 53 | + |
| 54 | +echo "Building ${ARCH} wheel with ${IMAGE}" |
| 55 | +echo "Repository root: ${REPO_ROOT}" |
| 56 | + |
| 57 | +rm -rf "${REPO_ROOT}/dist" "${REPO_ROOT}/wheelhouse" |
| 58 | +mkdir -p "${REPO_ROOT}/dist" "${REPO_ROOT}/wheelhouse" |
| 59 | + |
| 60 | +docker run --rm \ |
| 61 | + --platform "${PLATFORM}" \ |
| 62 | + -e AUDITWHEEL_PLAT="manylinux_2_28_${ARCH}" \ |
| 63 | + -e HOST_UID="$(id -u)" \ |
| 64 | + -e HOST_GID="$(id -g)" \ |
| 65 | + -v "${REPO_ROOT}:/io" \ |
| 66 | + -w /io \ |
| 67 | + "${IMAGE}" \ |
| 68 | + /bin/bash -lc ' |
| 69 | + set -euo pipefail |
| 70 | +
|
| 71 | + # The interpreter is only a build frontend. wheel.py-api="py3" ensures |
| 72 | + # that neither its Python version nor its ABI appears in the wheel tag. |
| 73 | + PYTHON=/opt/python/cp314-cp314/bin/python |
| 74 | + "${PYTHON}" -m pip install --upgrade build |
| 75 | + "${PYTHON}" -m build --wheel --outdir /tmp/dist /io |
| 76 | + cp /tmp/dist/*.whl /io/dist/ |
| 77 | + auditwheel repair --plat "${AUDITWHEEL_PLAT}" /tmp/dist/*.whl \ |
| 78 | + --wheel-dir /io/wheelhouse |
| 79 | + chown -R "${HOST_UID}:${HOST_GID}" /io/dist /io/wheelhouse || true |
| 80 | + ' |
| 81 | + |
| 82 | +echo "Done. Repaired wheel:" |
| 83 | +ls -1 "${REPO_ROOT}/wheelhouse"/*.whl |
0 commit comments