Skip to content

Commit 9847bdf

Browse files
authored
ci: fix cross (#542)
1 parent 432b473 commit 9847bdf

File tree

4 files changed

+92
-49
lines changed

4 files changed

+92
-49
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -250,50 +250,15 @@ jobs:
250250
- name: Setup python
251251
uses: actions/setup-python@v5
252252
with:
253-
python-version: "3.10" # must match the ubuntu version in the install, and also the STANDALONE_PYTHON_VERSION below
253+
python-version: "3.x"
254254
- uses: dtolnay/rust-toolchain@stable
255255
- name: Install cross
256-
uses: taiki-e/install-action@v2
257-
with:
258-
tool: cross
259-
- name: Build package
260-
run: pip install -e .
261-
- name: Build wheel using cross
262-
shell: bash
263-
env:
264-
CARGO: cross
265-
CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu
266-
PYO3_CROSS_LIB_DIR: /opt/python/cp310-cp310/lib
267-
DIST_EXTRA_CONFIG: /tmp/build-opts.cfg
268-
run: |
269-
cd examples/namespace_package
270-
docker build \
271-
--build-arg STANDALONE_PYTHON_VERSION=3.10.15 \
272-
--build-arg STANDALONE_PYTHON_RELEASE=20241016 \
273-
-t cross-pyo3:aarch64-unknown-linux-gnu \
274-
.
275-
python -m pip install build wheel
276-
echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG
277-
python -m build --no-isolation
278-
ls -la dist/
279-
unzip -l dist/*.whl # debug all files inside wheel file
280-
- uses: uraimo/[email protected]
281-
name: Install built wheel
282-
with:
283-
arch: aarch64
284-
distro: ubuntu22.04
285-
dockerRunArgs: |
286-
--volume "${PWD}/examples/namespace_package:/io"
287-
install: |
288-
apt-get update
289-
apt-get install -y --no-install-recommends python3 python3-venv python3-pip
290-
pip3 install -U pip
291-
run: |
292-
python3 -m venv .venv
293-
source .venv/bin/activate
294-
pip install namespace_package --no-index --find-links /io/dist/ --force-reinstall
295-
python -c "from namespace_package import rust; assert rust.rust_func() == 14"
296-
python -c "from namespace_package import python; assert python.python_func() == 15"
256+
# need cross HEAD for https://github.com/cross-rs/cross/issues/1645
257+
# will probably be ok to use released cross from 0.3
258+
run: cargo install cross --git https://github.com/cross-rs/cross
259+
- uses: docker/setup-qemu-action@v3
260+
- run: pip install nox
261+
- run: nox -s test-cross
297262

298263
test-zigbuild:
299264
runs-on: ubuntu-latest

examples/namespace_package/Cross.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
[target.aarch64-unknown-linux-gnu]
22
image = "cross-pyo3:aarch64-unknown-linux-gnu"
33
env.passthrough = [
4+
"PYO3_PRINT_CONFIG",
45
"RUST_BACKTRACE",
56
"RUST_LOG",
67
"PYO3_CROSS_LIB_DIR",
78
]
9+
10+
# This avoids cross picking up custom linker from host ~/.cargo/config.toml
11+
# See: https://github.com/cross-rs/cross/issues/621
12+
[build.env]
13+
passthrough = [
14+
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc",
15+
"RUSTFLAGS",
16+
]

examples/namespace_package/Dockerfile

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ FROM quay.io/pypa/manylinux2014_aarch64 AS manylinux
22

33
FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge
44

5-
ARG STANDALONE_PYTHON_RELEASE
6-
ARG STANDALONE_PYTHON_VERSION
7-
8-
RUN test -n "$STANDALONE_PYTHON_RELEASE" || (echo "STANDALONE_PYTHON_RELEASE not set" && false)
9-
RUN test -n "$STANDALONE_PYTHON_VERSION" || (echo "STANDALONE_PYTHON_VERSION not set" && false)
10-
11-
RUN curl -L https://github.com/indygreg/python-build-standalone/releases/download/${STANDALONE_PYTHON_RELEASE}/cpython-${STANDALONE_PYTHON_VERSION}+${STANDALONE_PYTHON_RELEASE}-x86_64-unknown-linux-gnu-install_only.tar.gz | tar -xz -C /usr/local
5+
# PyO3 needs a host Python interpreter to parse the sysconfigdata of the
6+
# cross-compile interpreter found in /opt/python
7+
RUN apt-get update && apt-get --assume-yes install python3
128

139
ENV PATH=/usr/local/python/bin:$PATH
1410

noxfile.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from inspect import cleandoc as heredoc
33
from glob import glob
44
from pathlib import Path
5+
import shutil
6+
import sys
57

68
import nox
79
import nox.command
@@ -135,6 +137,77 @@ def test_crossenv(session: nox.Session):
135137
)
136138

137139

140+
@nox.session(name="test-cross")
141+
def test_cross(session: nox.Session):
142+
session.install(".")
143+
session.install("-U", "setuptools", "build")
144+
145+
shutil.rmtree("examples/namespace_package/dist", ignore_errors=True)
146+
147+
namespace_package = Path(__file__).parent / "examples" / "namespace_package"
148+
os.chdir(namespace_package)
149+
session.run(
150+
"docker",
151+
"build",
152+
"-t",
153+
"cross-pyo3:aarch64-unknown-linux-gnu",
154+
".",
155+
external=True,
156+
)
157+
158+
major_version = sys.version_info[0]
159+
minor_version = sys.version_info[1]
160+
161+
cpXY = f"cp{major_version}{minor_version}"
162+
163+
tmp = Path(session.create_tmp())
164+
extra_config = tmp / "build-opts.cfg"
165+
build_config = """
166+
[bdist_wheel]
167+
plat_name = manylinux2014_aarch64
168+
"""
169+
extra_config.write_text(heredoc(build_config), encoding="utf-8")
170+
171+
build_env = os.environ.copy()
172+
build_env["DIST_EXTRA_CONFIG"] = str(extra_config.absolute())
173+
build_env["CARGO"] = "cross"
174+
build_env["CARGO_BUILD_TARGET"] = "aarch64-unknown-linux-gnu"
175+
build_env["PYO3_CROSS_LIB_DIR"] = f"/opt/python/{cpXY}-{cpXY}/lib"
176+
177+
# build wheel using cross
178+
#
179+
# if this step fails, you may need to install cross:
180+
# cargo install cross --git https://github.com/cross-rs/cross
181+
session.run("python", "-m", "build", "--no-isolation", env=build_env)
182+
183+
script_check = """
184+
set -eux
185+
python3 --version
186+
python3 -m venv .venv
187+
source .venv/bin/activate
188+
pip install namespace_package --no-index --find-links /io/dist/ --force-reinstall
189+
python -c "from namespace_package import rust; assert rust.rust_func() == 14"
190+
python -c "from namespace_package import python; assert python.python_func() == 15"
191+
"""
192+
193+
session.run(
194+
"docker",
195+
"run",
196+
"--rm",
197+
"-v",
198+
f"{namespace_package}:/io",
199+
"-w",
200+
"/io",
201+
"--platform",
202+
"aarch64",
203+
f"python:3.{minor_version}",
204+
"bash",
205+
"-c",
206+
script_check,
207+
external=True,
208+
)
209+
210+
138211
@nox.session()
139212
def ruff(session: nox.Session):
140213
session.install("ruff")

0 commit comments

Comments
 (0)