Skip to content

Commit

Permalink
Use "uv" to compile wheels for more armv7l platforms
Browse files Browse the repository at this point in the history
I use the buster image, so the wheels should be compatible with any newer distro as well
  • Loading branch information
Lauszus committed Nov 14, 2024
1 parent 600e471 commit 5691a80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
docker_images: ['balenalib/armv7hf-debian:buster', 'balenalib/armv7hf-debian:bullseye', 'balenalib/armv7hf-debian:bookworm']
python-version: ['3.7', '3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- name: Build ${{ matrix.docker_images }} wheel
id: build
run: |
docker build -f Dockerfile.armv7l -t lauszus/socketsocketcan --build-arg APP_IMAGE="${{ matrix.docker_images }}" .
docker build -f Dockerfile.armv7l -t lauszus/socketsocketcan --build-arg PYTHON_VERSION="${{ matrix.python-version }}" .
docker cp "$(docker create lauszus/socketsocketcan)":/socketsocketcan-wheel .
# Copy over the wheel.
mkdir dist
cp socketsocketcan-wheel/socketsocketcan*.whl dist/
# Special characters are not allowed, so just use the Debian codename for the artifact name
name=$(echo -n "${{ matrix.docker_images }}" | cut -d ':' -f2)
echo "name=$name" >> "$GITHUB_OUTPUT"
- name: Upload wheel as artifact
uses: actions/upload-artifact@v4
with:
name: socketsocketcan-armv7l-${{ steps.build.outputs.name }}-${{ github.sha }}
name: socketsocketcan-armv7l-${{ matrix.python-version }}-${{ github.sha }}
path: dist
retention-days: 1
if-no-files-found: error
Expand Down
29 changes: 23 additions & 6 deletions Dockerfile.armv7l
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
ARG APP_IMAGE=balenalib/armv7hf-debian:stretch
ARG APP_IMAGE=balenalib/armv7hf-debian:buster
FROM $APP_IMAGE

ARG PYTHON_VERSION=3.7

ENV UV_PYTHON="$PYTHON_VERSION"
ENV UV_SYSTEM_PYTHON=1

COPY . /socketsocketcan

RUN [ "cross-build-start" ]

# Install uv.
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

# Get dependencies.
RUN apt-get -y update
RUN apt-get -y install apt-utils
RUN apt-get -y install build-essential python3-dev python3-pip
RUN apt-get -y install build-essential clang python3-dev python3-pip
RUN rm /usr/lib/python3.*/EXTERNALLY-MANAGED || true
RUN python3 -m pip install --extra-index-url=https://www.piwheels.org/simple -U pip setuptools wheel pybind11

# Install Python using uv if it is not the native one.
RUN if ! uv python find "$PYTHON_VERSION" >/dev/null 2>&1; then \
uv python install "$PYTHON_VERSION" \
else \
python3 -m pip install --extra-index-url=https://www.piwheels.org/simple -U pip setuptools wheel \
fi

# Install Python dependencies.
RUN uv pip install --extra-index-url=https://www.piwheels.org/simple pybind11

# Build the wheel.
RUN python3 -m pip -v wheel --wheel-dir=/socketsocketcan-wheel /socketsocketcan
RUN uv build --wheel --out-dir=/socketsocketcan-wheel /socketsocketcan

# Make sure the wheel is working.
RUN python3 -m pip install --no-index --find-links=/socketsocketcan-wheel socketsocketcan
RUN python3 -c "import socketsocketcan; print(dir(socketsocketcan))"
RUN uv pip install --no-index --find-links=/socketsocketcan-wheel socketsocketcan
RUN uv run -- python -c "import socketsocketcan; print(dir(socketsocketcan))"

RUN [ "cross-build-end" ]

0 comments on commit 5691a80

Please sign in to comment.