Debian Codegraph @

.github/workflows/ci.yml

raw
1 name: CI
2 on:
3 push:
4 branches:
5 - main
6 pull_request:
7
8 concurrency:
9 group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
10 cancel-in-progress: true
11
12 # Setting a fixed target dir ensures that all builds of examples re-use the same common dependencies
13 env:
14 CARGO_TARGET_DIR: ${{ github.workspace }}/target
15
16 jobs:
17 ruff:
18 runs-on: "ubuntu-latest"
19 steps:
20 - uses: actions/checkout@v4
21
22 - name: Set up Python
23 uses: actions/setup-python@v5
24 with:
25 python-version: "3.x"
26
27 - run: pip install nox
28
29 - run: nox -s ruff
30
31 mypy:
32 runs-on: "ubuntu-latest"
33 steps:
34 - uses: actions/checkout@v4
35
36 - name: Set up Python
37 uses: actions/setup-python@v5
38 with:
39 python-version: "3.x"
40
41 - run: pip install nox
42
43 - run: nox -s mypy
44
45 pytest:
46 runs-on: "ubuntu-latest"
47 steps:
48 - uses: actions/checkout@v4
49
50 - name: Set up Python
51 uses: actions/setup-python@v5
52 with:
53 python-version: "3.x"
54
55 - name: Install Rust toolchain
56 uses: dtolnay/rust-toolchain@stable
57
58 - run: pip install nox
59
60 - run: nox -s test
61
62 build:
63 name: ${{ matrix.python-version }} ${{ matrix.platform.os }}-${{ matrix.platform.python-architecture }}
64 runs-on: ${{ matrix.platform.os }}
65 strategy:
66 # If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
67 fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
68 matrix:
69 python-version:
70 ["3.9", "3.10", "3.11", "3.12", "3.13", "3.13t", pypy-3.10, pypy-3.11]
71 platform:
72 [
73 {
74 os: "macos-latest",
75 python-architecture: "arm64",
76 rust-target: "aarch64-apple-darwin",
77 },
78 {
79 os: "ubuntu-latest",
80 python-architecture: "x64",
81 rust-target: "x86_64-unknown-linux-gnu",
82 },
83 {
84 os: "windows-latest",
85 python-architecture: "x64",
86 rust-target: "x86_64-pc-windows-msvc",
87 },
88 ]
89 include:
90 # Just test one x86 Windows Python for simplicity
91 - python-version: 3.12
92 platform:
93 {
94 os: "windows-latest",
95 python-architecture: "x86",
96 rust-target: "i686-pc-windows-msvc",
97 }
98 # Just test one x64 macOS Python for simplicity
99 - python-version: 3.12
100 platform:
101 {
102 os: "macos-13",
103 python-architecture: "x64",
104 rust-target: "x86_64-apple-darwin",
105 }
106 # Just test one x64 macOS Python for simplicity
107 exclude:
108 # macOS arm doesn't have Python builds before 3.10
109 - python-version: 3.9
110 platform:
111 {
112 os: "macos-latest",
113 python-architecture: "arm64",
114 rust-target: "aarch64-apple-darwin",
115 }
116
117 env:
118 SETUPTOOLS_RUST_CARGO_PROFILE: dev
119 steps:
120 - uses: actions/checkout@v4
121
122 - name: Set up Python ${{ matrix.python-version }}
123 uses: actions/setup-python@v5
124 with:
125 python-version: ${{ matrix.python-version }}
126 architecture: ${{ matrix.platform.python-architecture }}
127 allow-prereleases: true
128
129 - name: Install Rust toolchain
130 uses: dtolnay/rust-toolchain@stable
131 with:
132 targets: ${{ matrix.platform.rust-target }}
133
134 - name: Install test dependencies
135 run: pip install --upgrade nox
136
137 - name: Build package
138 run: pip install -e .
139
140 - name: Test examples
141 shell: bash
142 env:
143 PYTHON: ${{ matrix.python-version }}
144 run: nox -s test-examples
145
146 - name: Test macOS universal2
147 if: ${{ startsWith(matrix.platform.os, 'macos') && !startsWith(matrix.python-version, 'pypy') }}
148 shell: bash
149 env:
150 MACOSX_DEPLOYMENT_TARGET: "10.9"
151 ARCHFLAGS: -arch x86_64 -arch arm64
152 run: |
153 rustup target add aarch64-apple-darwin
154 rustup target add x86_64-apple-darwin
155 cd examples/namespace_package
156 pip install build 'setuptools>=70.1'
157 python -m build --no-isolation
158 ls -l dist/
159 pip install --force-reinstall dist/namespace_package*_universal2.whl
160 cd -
161 python -c "from namespace_package import rust; assert rust.rust_func() == 14"
162 python -c "from namespace_package import python; assert python.python_func() == 15"
163
164 - name: Test sdist vendor Rust crates
165 shell: bash
166 run: nox -s test-sdist-vendor
167 env:
168 CARGO_BUILD_TARGET: ${{ matrix.platform.rust-target }}
169
170 test-abi3:
171 runs-on: ${{ matrix.os }}
172 strategy:
173 # If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
174 fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
175 matrix:
176 os: [ubuntu-latest, macos-latest, windows-latest]
177 steps:
178 - uses: actions/checkout@v4
179 - name: Setup python
180 uses: actions/setup-python@v5
181 with:
182 python-version: 3.9
183
184 - uses: dtolnay/rust-toolchain@stable
185
186 - name: Build package
187 run: pip install -e .
188
189 - name: Build an abi3 wheel
190 shell: bash
191 env:
192 # https://github.com/actions/setup-python/issues/26
193 MACOSX_DEPLOYMENT_TARGET: 10.9
194 DIST_EXTRA_CONFIG: /tmp/build-opts.cfg
195 run: |
196 set -e
197 cd examples/rust_with_cffi/
198 python --version
199 pip install -U build cffi 'setuptools>=70.1'
200 echo -e "[bdist_wheel]\npy_limited_api=cp39" > $DIST_EXTRA_CONFIG
201 python -m build --no-isolation
202 ls -la dist/
203
204 # Now we switch to a differnet Python version and ensure we can install
205 # the wheel we just built.
206 - name: Setup python
207 uses: actions/setup-python@v5
208 with:
209 python-version: "3.10"
210
211 - name: Install abi3 wheel and run tests
212 shell: bash
213 run: |
214 set -e
215 cd examples/
216 python --version
217 pip install rust_with_cffi/dist/rust_with_cffi*.whl
218 python -c "from rust_with_cffi import rust; assert rust.rust_func() == 14"
219 python -c "from rust_with_cffi.cffi import lib; assert lib.cffi_func() == 15"
220
221 - name: Run abi3audit
222 shell: bash
223 run: |
224 set -e
225 pip install abi3audit
226 cd examples/
227 abi3audit rust_with_cffi/dist/rust_with_cffi*.whl
228
229 test-crossenv:
230 runs-on: ubuntu-latest
231 strategy:
232 # If one platform fails, allow the rest to keep testing if `CI-no-fail-fast` label is present
233 fail-fast: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast') }}
234 matrix:
235 platform: [{ arch: "aarch64" }, { arch: "armv7" }]
236 steps:
237 - uses: actions/checkout@v4
238 - name: Set up Python
239 uses: actions/setup-python@v5
240 with:
241 python-version: "3.x"
242 - uses: docker/setup-qemu-action@v3
243 - run: pip install nox
244 - run: nox -s test-crossenv -- ${{ matrix.platform.arch }}
245
246 test-cross:
247 runs-on: ubuntu-latest
248 steps:
249 - uses: actions/checkout@v4
250 - name: Setup python
251 uses: actions/setup-python@v5
252 with:
253 python-version: "3.x"
254 - uses: dtolnay/rust-toolchain@stable
255 - name: Install cross
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
262
263 test-zigbuild:
264 runs-on: ubuntu-latest
265 steps:
266 - uses: actions/checkout@v4
267 - name: Setup python
268 uses: actions/setup-python@v5
269 with:
270 python-version: "3.10" # must match the ubuntu version in the install, and also the version copied out of the docker image below
271 - uses: dtolnay/rust-toolchain@stable
272 with:
273 targets: aarch64-unknown-linux-gnu
274 - name: Install cargo-zigbuild
275 run: |
276 python3 -m pip install cargo-zigbuild
277 - name: Build package
278 run: pip install -e .
279 - name: Build wheel using cargo-zigbuild
280 shell: bash
281 env:
282 CARGO: cargo-zigbuild
283 CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu
284 PYO3_CROSS_LIB_DIR: /opt/python/cp310-cp310/lib
285 DIST_EXTRA_CONFIG: /tmp/build-opts.cfg
286 run: |
287 mkdir -p $PYO3_CROSS_LIB_DIR
288 docker cp -L $(docker create --rm quay.io/pypa/manylinux2014_aarch64:latest):/opt/python/cp310-cp310 /opt/python
289 cd examples/namespace_package
290 python -m pip install build wheel
291 echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG
292 python -m build --no-isolation
293 ls -la dist/
294 unzip -l dist/*.whl # debug all files inside wheel file
295 - uses: uraimo/[email protected]
296 name: Install built wheel
297 with:
298 arch: aarch64
299 distro: ubuntu22.04
300 dockerRunArgs: |
301 --volume "${PWD}/examples/namespace_package:/io"
302 install: |
303 apt-get update
304 apt-get install -y --no-install-recommends python3 python3-venv python3-pip
305 run: |
306 python3 -m venv .venv
307 source .venv/bin/activate
308 pip install namespace_package --no-index --find-links /io/dist/ --force-reinstall
309 python -c "from namespace_package import rust; assert rust.rust_func() == 14"
310 python -c "from namespace_package import python; assert python.python_func() == 15"
311
312 test-cibuildwheel:
313 runs-on: macos-latest
314 steps:
315 - uses: actions/checkout@v4
316 - uses: dtolnay/rust-toolchain@stable
317 with:
318 targets: aarch64-apple-darwin,x86_64-apple-darwin
319 - uses: pypa/[email protected]
320 env:
321 CIBW_BUILD: cp39-*
322 CIBW_BEFORE_BUILD: >
323 pip install -U 'pip>=23.2.1' 'setuptools>=70.1.0' 'auditwheel>=5.4.0'
324 && pip install -e .
325 && pip list
326 CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
327 CIBW_BUILD_VERBOSITY: 3
328 CIBW_BUILD_FRONTEND: "build; args: --no-isolation"
329 MACOSX_DEPLOYMENT_TARGET: 10.12
330 with:
331 package-dir: examples/namespace_package
332
333 test-mingw:
334 runs-on: windows-latest
335 name: ${{ matrix.python-version }} mingw-${{ matrix.arch }}
336 strategy:
337 fail-fast: false
338 matrix:
339 include:
340 [
341 {
342 msystem: MINGW64,
343 arch: x86_64,
344 path: mingw64,
345 rust_target: x86_64-pc-windows-gnu,
346 },
347 {
348 msystem: MINGW32,
349 arch: i686,
350 path: mingw32,
351 rust_target: i686-pc-windows-gnu,
352 },
353 ]
354 steps:
355 - uses: actions/checkout@v4
356 - name: Install MSys2 and dependencies
357 uses: msys2/setup-msys2@v2
358 with:
359 update: true
360 msystem: ${{ matrix.msystem }}
361 install: >-
362 git
363 mingw-w64-${{ matrix.arch }}-python
364 mingw-w64-${{ matrix.arch }}-python-pip
365 mingw-w64-${{ matrix.arch }}-openssl
366 mingw-w64-${{ matrix.arch }}-toolchain
367
368 - uses: dtolnay/rust-toolchain@master
369 with:
370 toolchain: stable-${{ matrix.rust_target }}
371
372 - name: Install test dependencies
373 shell: msys2 {0}
374 run: python -m pip install --upgrade pip nox
375
376 - name: Create libpython symlink
377 shell: msys2 {0}
378 run: |
379 PYTHON_MINOR_VER=$(python -c "import sys; print(sys.version_info.minor)")
380 ln -s /${{ matrix.path }}/lib/libpython3.${PYTHON_MINOR_VER}.dll.a /${{ matrix.path }}/lib/libpython3${PYTHON_MINOR_VER}.dll.a
381
382 - name: Test examples
383 shell: msys2 {0}
384 run: PATH="$PATH:/c/Users/runneradmin/.cargo/bin" nox -s test-examples
385
386 test-emscripten:
387 name: Test Emscripten
388 runs-on: ubuntu-latest
389 steps:
390 - uses: actions/checkout@v4
391 - uses: actions/setup-node@v4
392 with:
393 node-version: 18
394 - run: |
395 PYODIDE_VERSION=0.21.0
396
397 cd emscripten
398 npm i [email protected]
399 cd node_modules/pyodide/
400 npx -y prettier -w pyodide.asm.js
401 EMSCRIPTEN_VERSION=$(node -p "require('./repodata.json').info.platform.split('_').slice(1).join('.')")
402 PYTHON_VERSION=3.10
403
404 echo "PYODIDE_VERSION=$PYODIDE_VERSION" >> $GITHUB_ENV
405 echo "EMSCRIPTEN_VERSION=$EMSCRIPTEN_VERSION" >> $GITHUB_ENV
406 echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
407 echo "ORIG_PATH=$PATH" >> $GITHUB_ENV
408 - uses: dtolnay/rust-toolchain@nightly
409 with:
410 components: rust-src
411 targets: wasm32-unknown-emscripten
412 - uses: mymindstorm/setup-emsdk@v14
413 with:
414 version: ${{env.EMSCRIPTEN_VERSION}}
415 actions-cache-folder: emsdk-cache
416 - uses: actions/setup-python@v5
417 id: setup-python
418 with:
419 python-version: ${{env.PYTHON_VERSION}}
420 - run: pip install nox
421 - uses: actions/cache@v4
422 with:
423 path: |
424 tests/pyodide
425 key: ${{ hashFiles('tests/*.js') }} - ${{ hashFiles('noxfile.py') }} - ${{ steps.setup-python.outputs.python-path }}
426 - uses: Swatinem/rust-cache@v2
427 - name: Test
428 run: |
429 export PATH=$ORIG_PATH:$PATH
430 nox -s test-examples-emscripten