Skip to content

Commit b9f417e

Browse files
committed
ci: fix cross
1 parent 45919da commit b9f417e

File tree

4 files changed

+91
-49
lines changed

4 files changed

+91
-49
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -250,50 +250,14 @@ 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+
- run: pip instal nox
260+
- run: nox -s test-cross
297261

298262
test-zigbuild:
299263
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
@@ -136,6 +138,77 @@ def test_crossenv(session: nox.Session):
136138
)
137139

138140

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

0 commit comments

Comments
 (0)