Skip to content

Commit

Permalink
Add "freethreaded" Python support (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro authored Dec 16, 2024
1 parent 5871eee commit 7cbc1f1
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 51 deletions.
132 changes: 132 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: build

on: workflow_dispatch

env:
PY_ALL: 3.9 3.10 3.11 3.12 3.13 3.13t pypy3.9 pypy3.10

jobs:
wheels:
name: wheel ${{ matrix.platform || matrix.os }}(${{ matrix.target }}) - ${{ matrix.manylinux || 'auto' }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
target: [x86_64, aarch64]
manylinux: [auto]
include:
- os: ubuntu
platform: linux
- os: ubuntu
platform: linux
target: x86_64
manylinux: auto
interpreter: pypy3.9 pypy3.10
- os: macos
target: x86_64
interpreter: pypy3.9 pypy3.10
- os: macos
target: aarch64
interpreter: pypy3.9 pypy3.10
- os: ubuntu
platform: linux
target: aarch64
container: messense/manylinux_2_24-cross:aarch64
- os: ubuntu
platform: linux
target: x86_64
manylinux: musllinux_1_1
- os: ubuntu
platform: linux
target: aarch64
manylinux: musllinux_1_1
- os: windows
target: x86_64
interpreter: pypy3.9 pypy3.10
exclude:
- os: windows
target: aarch64
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- uses: pyo3/maturin-action@v1
with:
rust-toolchain: stable
command: build
args: --release --out dist --interpreter ${{ matrix.interpreter || env.PY_ALL }}
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }}
container: ${{ matrix.container }}
docker-options: -e CI
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

wheels-pgo:
name: pgo-wheel ${{ matrix.platform || matrix.os }} (${{ matrix.interpreter}})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
manylinux: [auto]
interpreter: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.13t"]
include:
- os: ubuntu-latest
platform: linux
- os: windows-latest
platform: windows

runs-on: ${{ matrix.os }}
env:
UV_PYTHON: ${{ matrix.interpreter }}
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v4
with:
enable-cache: false
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools
- name: prepare profiling directory
shell: bash
run: mkdir -p ${{ github.workspace }}/profdata
- name: Build initial wheel
uses: PyO3/maturin-action@v1
with:
rust-toolchain: stable
command: build
args: --release --out pgo_wheel --interpreter ${{ matrix.interpreter }}
manylinux: ${{ matrix.manylinux || 'auto' }}
docker-options: -e CI
env:
RUSTFLAGS: "-Cprofile-generate=${{ github.workspace }}/profdata"
- run: |
RUST_HOST=$(rustc -Vv | grep host | cut -d ' ' -f 2) rustup run stable bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/$RUST_HOST/bin/llvm-profdata >> "$GITHUB_ENV"'
shell: bash
- name: Generate PGO data
shell: bash
run: |
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv pip install pytest pytest-asyncio
uv pip install emmett-core --no-index --no-deps --find-links pgo_wheel --force-reinstall
LLVM_PROFILE_FILE=${{ github.workspace }}/profdata/emtc_%m_%p.profraw uv run --no-sync pytest tests/cryptography tests/multipart tests/routing
- name: merge PGO data
run: ${{ env.LLVM_PROFDATA }} merge --failure-mode=all -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata
- name: Build PGO wheel
uses: PyO3/maturin-action@v1
with:
command: build
args: --release --out dist --interpreter ${{ matrix.interpreter }}
manylinux: ${{ matrix.manylinux || 'auto' }}
rust-toolchain: stable
docker-options: -e CI
env:
RUSTFLAGS: "-Cprofile-use=${{ github.workspace }}/merged.profdata"
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
44 changes: 20 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ on:
- v*.*.*

env:
PY_ALL: 3.9 3.10 3.11 3.12 3.13 pypy3.9 pypy3.10
PY_ALL: 3.9 3.10 3.11 3.12 3.13 3.13t pypy3.9 pypy3.10

jobs:
sdist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pyo3/maturin-action@v1
with:
rust-toolchain: stable
Expand All @@ -31,7 +27,6 @@ jobs:

wheels:
name: wheel ${{ matrix.platform || matrix.os }}(${{ matrix.target }}) - ${{ matrix.manylinux || 'auto' }}
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -51,7 +46,7 @@ jobs:
interpreter: pypy3.9 pypy3.10
- os: macos
target: aarch64
interpreter: 3.9 pypy3.9 pypy3.10
interpreter: pypy3.9 pypy3.10
- os: ubuntu
platform: linux
target: aarch64
Expand All @@ -70,14 +65,7 @@ jobs:
exclude:
- os: windows
target: aarch64
# PGO builds
# - os: ubuntu
# target: x86_64
# manylinux: auto
# - os: macos
# target: x86_64
# - os: windows
# target: x86_64
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- uses: pyo3/maturin-action@v1
Expand All @@ -96,27 +84,33 @@ jobs:
path: dist

wheels-pgo:
name: pgo-wheel ${{ matrix.os }} (${{ matrix.interpreter}})
name: pgo-wheel ${{ matrix.platform || matrix.os }} (${{ matrix.interpreter}})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
manylinux: [auto]
interpreter: ["3.9", "3.10", "3.11", "3.12", "3.13"]
interpreter: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.13t"]
include:
- os: ubuntu-latest
platform: linux
- os: windows-latest
platform: windows

runs-on: ${{ matrix.os }}
env:
UV_PYTHON: ${{ matrix.interpreter }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.interpreter }}
allow-prereleases: true
enable-cache: false
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools
- name: prepare profiling directory
shell: bash
run: mkdir -p ${{ github.workspace }}/profdata
- name: Build initial wheel
uses: PyO3/maturin-action@v1
with:
Expand All @@ -133,11 +127,13 @@ jobs:
- name: Generate PGO data
shell: bash
run: |
pip install .[test]
pip install emmett-core --no-index --no-deps --find-links pgo_wheel --force-reinstall
pytest tests/cryptography tests/multipart tests/routing
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv pip install pytest pytest-asyncio
uv pip install emmett-core --no-index --no-deps --find-links pgo_wheel --force-reinstall
LLVM_PROFILE_FILE=${{ github.workspace }}/profdata/emtc_%m_%p.profraw uv run --no-sync pytest tests/cryptography tests/multipart tests/routing
- name: merge PGO data
run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata
run: ${{ env.LLVM_PROFDATA }} merge --failure-mode=all -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata
- name: Build PGO wheel
uses: PyO3/maturin-action@v1
with:
Expand Down
54 changes: 28 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
enable-cache: false
- name: Install
run: |
python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin develop --extras=test
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv pip install maturin
uv run --no-sync maturin develop --uv --extras=test
- name: Test
run: |
source .venv/bin/activate
Expand All @@ -51,20 +52,21 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
enable-cache: false
- name: Install
run: |
python -m venv .venv
source .venv/bin/activate
pip install maturin
maturin develop --extras=test
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv pip install maturin
uv run --no-sync maturin develop --uv --extras=test
- name: Test
run: |
source .venv/bin/activate
Expand All @@ -81,21 +83,21 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'

env:
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
enable-cache: false
- name: Install
run: |
python -m venv venv
venv/Scripts/Activate.ps1
pip install maturin pytest
maturin develop --extras=test
uv python install ${{ env.UV_PYTHON }}
uv venv .venv
uv pip install maturin
uv run --no-sync maturin develop --uv --extras=test
- name: Test
run: |
venv/Scripts/Activate.ps1
make test
uv run --no-sync make test
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ known-first-party = ['emmett_core', 'tests']

[tool.pytest.ini_options]
asyncio_mode = 'auto'

[tool.uv]
package = false
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn get_lib_version() -> &'static str {
})
}

#[pymodule]
#[pymodule(gil_used = false)]
fn _emmett_core(py: Python, module: &Bound<PyModule>) -> PyResult<()> {
module.add("__version__", get_lib_version())?;

Expand Down

0 comments on commit 7cbc1f1

Please sign in to comment.