Skip to content

Commit 4ac2048

Browse files
committed
move crossenv test into noxfile
1 parent 322d5f8 commit 4ac2048

File tree

2 files changed

+92
-49
lines changed

2 files changed

+92
-49
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -202,58 +202,13 @@ jobs:
202202
fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
203203
matrix:
204204
platform: [
205-
{ target: "aarch64-unknown-linux-gnu", arch: "aarch64" },
206-
{ target: "armv7-unknown-linux-gnueabihf", arch: "armv7" },
205+
{ arch: "aarch64" },
206+
{ arch: "armv7" },
207207
]
208208
steps:
209209
- uses: actions/checkout@v3
210-
- name: Build wheels
211-
run: |
212-
echo 'set -ex
213-
curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
214-
source ~/.cargo/env
215-
rustup target add ${{ matrix.platform.target }}
216-
217-
# https://github.com/pypa/setuptools_scm/issues/707
218-
git config --global --add safe.directory /io
219-
220-
cd examples/rust_with_cffi/
221-
python3.9 -m pip install crossenv
222-
python3.9 -m crossenv "/opt/python/cp39-cp39/bin/python3" --cc $TARGET_CC --cxx $TARGET_CXX --sysroot $TARGET_SYSROOT --env LIBRARY_PATH= --manylinux manylinux1 venv
223-
. venv/bin/activate
224-
225-
build-pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1
226-
cross-pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1
227-
build-pip install cffi
228-
cross-expose cffi
229-
cross-pip install -e ../../
230-
cross-pip list
231-
232-
export DIST_EXTRA_CONFIG=/tmp/build-opts.cfg
233-
echo -e "[bdist_wheel]\npy_limited_api=cp37" > $DIST_EXTRA_CONFIG
234-
235-
cross-pip wheel --no-build-isolation --no-deps --wheel-dir dist . -vv
236-
ls -la dist/
237-
python -m zipfile -l dist/*.whl # debug all files inside wheel file
238-
' > build-wheels.sh
239-
240-
docker run --rm -v "$PWD":/io -w /io messense/manylinux2014-cross:${{ matrix.platform.arch }} bash build-wheels.sh
241-
- name: Install abi3 wheel and run tests
242-
uses: uraimo/[email protected]
243-
with:
244-
arch: ${{ matrix.platform.arch }}
245-
distro: ubuntu20.04
246-
dockerRunArgs: |
247-
--volume "${PWD}/examples:/examples"
248-
install: |
249-
apt-get update
250-
apt-get install -y --no-install-recommends python3 python3-dev python3-pip build-essential libffi-dev
251-
run: |
252-
cd /examples
253-
python3 --version
254-
pip3 install rust_with_cffi/dist/rust_with_cffi*.whl
255-
python3 -c "from rust_with_cffi import rust; assert rust.rust_func() == 14"
256-
python3 -c "from rust_with_cffi.cffi import lib; assert lib.cffi_func() == 15"
210+
- run: pip install nox
211+
- run: nox -s test-crossenv -- ${{ matrix.platform.arch }}
257212

258213
test-cross:
259214
runs-on: ubuntu-latest

noxfile.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,94 @@ def test_sdist_vendor(session: nox.Session):
3939
session.run("cargo", "build", "--offline", external=True)
4040

4141

42+
@nox.session(name="test-crossenv", venv_backend=None)
43+
def test_crossenv(session: nox.Session):
44+
try:
45+
arch = session.posargs[0]
46+
except IndexError:
47+
arch = "aarch64"
48+
print(arch)
49+
50+
if arch == "aarch64":
51+
rust_target = "aarch64-unknown-linux-gnu"
52+
docker_platform = "aarch64"
53+
elif arch == "armv7":
54+
rust_target = "armv7-unknown-linux-gnueabihf"
55+
docker_platform = "linux/arm/v7"
56+
else:
57+
raise RuntimeError("don't know rust target for arch: " + arch)
58+
59+
script_build = f"""set -ex
60+
curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
61+
source ~/.cargo/env
62+
rustup target add {rust_target}
63+
64+
# https://github.com/pypa/setuptools_scm/issues/707
65+
git config --global --add safe.directory /io
66+
67+
cd examples/rust_with_cffi/
68+
python3.9 -m pip install crossenv
69+
python3.9 -m crossenv "/opt/python/cp39-cp39/bin/python3" --cc $TARGET_CC --cxx $TARGET_CXX --sysroot $TARGET_SYSROOT --env LIBRARY_PATH= --manylinux manylinux1 venv
70+
. venv/bin/activate
71+
72+
build-pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1
73+
cross-pip install -U pip>=23.2.1 setuptools>=68.0.0 wheel>=0.41.1
74+
build-pip install cffi
75+
cross-expose cffi
76+
cross-pip install -e ../../
77+
cross-pip list
78+
79+
export DIST_EXTRA_CONFIG=/tmp/build-opts.cfg
80+
echo -e "[bdist_wheel]\npy_limited_api=cp37" > $DIST_EXTRA_CONFIG
81+
82+
rm -rf dist/*
83+
cross-pip wheel --no-build-isolation --no-deps --wheel-dir dist . -vv
84+
ls -la dist/
85+
python -m zipfile -l dist/*.whl # debug all files inside wheel file
86+
"""
87+
88+
pwd = os.getcwd()
89+
session.run(
90+
"docker",
91+
"run",
92+
"--rm",
93+
"-v",
94+
f"{pwd}:/io",
95+
"-w",
96+
"/io",
97+
f"messense/manylinux2014-cross:{arch}",
98+
"bash",
99+
"-c",
100+
script_build,
101+
external=True,
102+
)
103+
104+
script_check = """set -ex
105+
cd /io/examples
106+
python3 --version
107+
pip3 install rust_with_cffi/dist/rust_with_cffi*.whl
108+
python3 -c "from rust_with_cffi import rust; assert rust.rust_func() == 14"
109+
python3 -c "from rust_with_cffi.cffi import lib; assert lib.cffi_func() == 15"
110+
"""
111+
112+
session.run(
113+
"docker",
114+
"run",
115+
"--rm",
116+
"-v",
117+
f"{pwd}:/io",
118+
"-w",
119+
"/io",
120+
"--platform",
121+
docker_platform,
122+
"python:3.9",
123+
"bash",
124+
"-c",
125+
script_check,
126+
external=True,
127+
)
128+
129+
42130
@nox.session()
43131
def mypy(session: nox.Session):
44132
session.install("mypy", "fat_macho", "types-setuptools", ".")

0 commit comments

Comments
 (0)