Skip to content

Commit b1899b6

Browse files
authored
Merge branch 'main' into PyLongForBigInt
2 parents e2b22d6 + 126aa44 commit b1899b6

17 files changed

Lines changed: 364 additions & 172 deletions

File tree

.github/pull_request_template.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ Thank you for contributing to PyO3!
33
By submitting these contributions you agree for them to be dual-licensed under PyO3's [MIT OR Apache-2.0 license](https://github.com/PyO3/pyo3#license).
44

55
Please consider adding the following to your pull request:
6-
- an entry for this PR in newsfragments - see [https://pyo3.rs/main/contributing.html#documenting-changes]
6+
- an entry for this PR in newsfragments - see [Documenting changes](https://pyo3.rs/main/contributing.html#documenting-changes)
77
- or start the PR title with `docs:` if this is a docs-only change to skip the check
88
- or start the PR title with `ci:` if this is a ci-only change to skip the check
9+
- or start the PR title with `internal:` if this is an internal change to skip the check
10+
- or start the PR title with `refactor:` if this is a refactor change to skip the check
911
- docs to all new functions and / or detail in the guide
1012
- tests for all new or changed functions
1113

.github/workflows/ci-cache-warmup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
targets: x86_64-pc-windows-gnu,x86_64-pc-windows-msvc
1919
components: rust-src
20-
- uses: actions/cache/restore@v5
20+
- uses: actions/cache/restore@v6
2121
with:
2222
# https://github.com/PyO3/maturin/discussions/1953
2323
path: ~/.cache/cargo-xwin
@@ -28,7 +28,7 @@ jobs:
2828
sudo apt-get install -y mingw-w64 llvm
2929
pip install nox
3030
nox -s test-cross-compilation-windows
31-
- uses: actions/cache/save@v5
31+
- uses: actions/cache/save@v6
3232
with:
3333
path: ~/.cache/cargo-xwin
3434
key: cargo-xwin-cache

.github/workflows/ci.yml

Lines changed: 30 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,9 @@ jobs:
483483
runs-on: ubuntu-latest
484484
steps:
485485
- uses: actions/checkout@v7.0.0
486-
- uses: actions/setup-python@v6
486+
- uses: astral-sh/setup-uv@v7
487487
with:
488-
python-version: 3.14
489-
id: setup-python
488+
save-cache: ${{ needs.resolve.outputs.save-cache }}
490489
- name: Install Rust toolchain
491490
uses: dtolnay/rust-toolchain@stable
492491
with:
@@ -495,42 +494,37 @@ jobs:
495494
- uses: actions/setup-node@v6
496495
with:
497496
node-version: 24
498-
- run: python -m pip install --upgrade pip && pip install nox[uv]
499-
- uses: actions/cache/restore@v5
497+
- uses: actions/cache/restore@v6
500498
id: cache
501499
with:
502500
path: |
503501
.nox/emscripten
504-
key: emscripten-${{ hashFiles('emscripten/*') }}-${{ hashFiles('noxfile.py') }}-${{ steps.setup-python.outputs.python-path }}
502+
key: emscripten-${{ hashFiles('wasm/emscripten/*', 'wasm/common.mk') }}-${{ hashFiles('noxfile.py') }}-${{ env.UV_PYTHON }}
505503
- uses: Swatinem/rust-cache@v2
506504
with:
507505
save-if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
508506
- name: Build
509507
if: steps.cache.outputs.cache-hit != 'true'
510-
run: nox -s build-emscripten
508+
run: uvx nox -s build-emscripten
511509
- name: Test
512-
run: nox -s test-emscripten
513-
- uses: actions/cache/save@v5
510+
run: uvx nox -s test-emscripten
511+
- uses: actions/cache/save@v6
514512
if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
515513
with:
516514
path: |
517515
.nox/emscripten
518-
key: emscripten-${{ hashFiles('emscripten/*') }}-${{ hashFiles('noxfile.py') }}-${{ steps.setup-python.outputs.python-path }}
516+
key: emscripten-${{ hashFiles('wasm/emscripten/*', 'wasm/common.mk') }}-${{ hashFiles('noxfile.py') }}-${{ env.UV_PYTHON }}
519517

520518
wasm32-wasip1:
521519
name: wasm32-wasip1
522520
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
523521
needs: [fmt]
524522
runs-on: ubuntu-latest
525-
env:
526-
WASI_SDK_PATH: "/opt/wasi-sdk"
527-
CPYTHON_PATH: "${{ github.workspace }}/wasi/cpython"
528523
steps:
529524
- uses: actions/checkout@v7.0.0
530-
- uses: actions/setup-python@v6
525+
- uses: astral-sh/setup-uv@v7
531526
with:
532-
python-version: 3.14
533-
id: setup-python
527+
save-cache: ${{ needs.resolve.outputs.save-cache }}
534528
- name: Install Rust toolchain
535529
uses: dtolnay/rust-toolchain@stable
536530
with:
@@ -539,59 +533,32 @@ jobs:
539533
- name: "Install wasmtime"
540534
uses: bytecodealliance/actions/wasmtime/setup@v1
541535
- name: "Install WASI SDK"
542-
run: |
543-
mkdir ${{ env.WASI_SDK_PATH }} && \
544-
curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-x86_64-linux.tar.gz | \
545-
tar --strip-components 1 --directory ${{ env.WASI_SDK_PATH }} --extract --gunzip
546-
$WASI_SDK_PATH/bin/clang --version
547-
- uses: actions/cache/restore@v5
548-
id: cache-wasip1-python
549-
with:
550-
path: ${{ env.CPYTHON_PATH }}/cross-build/
551-
key: wasm32-wasip1-python
552-
- uses: actions/checkout@v7.0.0
536+
uses: bytecodealliance/setup-wasi-sdk-action@main
553537
with:
554-
repository: python/cpython
555-
ref: 3.14
556-
path: ${{ env.CPYTHON_PATH }}
557-
fetch-depth: 1
558-
- name: Build
559-
run: |
560-
cd ${{ env.CPYTHON_PATH }}
561-
cat >> Tools/wasm/wasi/config.site-wasm32-wasi <<'EOF'
562-
563-
# Force-disable POSIX dynamic loading for WASI
564-
ac_cv_func_dlopen=no
565-
ac_cv_lib_dl_dlopen=no
566-
EOF
567-
python Tools/wasm/wasi build --quiet -- --config-cache
568-
cp cross-build/wasm32-wasip1/libpython3.14.a \
569-
cross-build/wasm32-wasip1/Modules/_hacl/libHacl_HMAC.a \
570-
cross-build/wasm32-wasip1/Modules/_decimal/libmpdec/libmpdec.a \
571-
cross-build/wasm32-wasip1/Modules/expat/libexpat.a \
572-
cross-build/wasm32-wasip1/build/lib.wasi-wasm32-3.14/
538+
version: "24"
539+
# wasi sdk sets CC variables which break Python's configure script
540+
# (it also sets WASI_SDK_PATH even without `add-to-path`, which is sufficient)
541+
add-to-path: false
542+
- uses: actions/cache/restore@v6
543+
id: cache
544+
with:
545+
path: |
546+
.nox/wasi
547+
key: wasi-${{ hashFiles('wasm/wasi/*', 'wasm/common.mk') }}-${{ hashFiles('noxfile.py') }}-${{ env.UV_PYTHON }}
573548
- uses: Swatinem/rust-cache@v2
574549
with:
575550
save-if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
551+
- name: Build
552+
if: steps.cache.outputs.cache-hit != 'true'
553+
run: uvx nox -s build-wasm
576554
- name: Test
577-
env:
578-
PYO3_CROSS_LIB_DIR: ${{ env.CPYTHON_PATH }}/cross-build/wasm32-wasip1/build/lib.wasi-wasm32-3.14/
579-
CARGO_BUILD_TARGET: wasm32-wasip1
580-
CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime run --dir ${{ env.CPYTHON_PATH }}::/ --env PYTHONPATH=/lib
581-
RUSTFLAGS: >
582-
-C link-arg=-L${{ env.WASI_SDK_PATH }}/share/wasi-sysroot/lib/wasm32-wasi
583-
-C link-arg=-lwasi-emulated-signal
584-
-C link-arg=-lwasi-emulated-process-clocks
585-
-C link-arg=-lwasi-emulated-getpid
586-
-C link-arg=-lmpdec
587-
-C link-arg=-lHacl_HMAC
588-
-C link-arg=-lexpat
589-
run: RUSTDOCFLAGS=$RUSTFLAGS cargo test
590-
- uses: actions/cache/save@v5
555+
run: uvx nox -s test-wasm
556+
- uses: actions/cache/save@v6
591557
if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
592558
with:
593-
path: ${{ env.CPYTHON_PATH }}/cross-build/
594-
key: ${{ steps.cache-wasip1-python.outputs.cache-primary-key }}
559+
path: |
560+
.nox/wasi
561+
key: wasi-${{ hashFiles('wasm/wasi/*', 'wasm/common.mk') }}-${{ hashFiles('noxfile.py') }}-${{ env.UV_PYTHON }}
595562

596563
test-debug:
597564
if: ${{ contains(github.event.pull_request.labels.*.name, 'CI-build-full') || github.event_name != 'pull_request' }}
@@ -775,7 +742,7 @@ jobs:
775742
targets: x86_64-pc-windows-gnu,x86_64-pc-windows-msvc
776743
components: rust-src
777744
# load cache (prepared in ci-cache-warmup.yml)
778-
- uses: actions/cache/restore@v5
745+
- uses: actions/cache/restore@v6
779746
with:
780747
path: ~/.cache/cargo-xwin
781748
key: cargo-xwin-cache

.github/workflows/netlify-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
4040
- name: Restore lychee cache
4141
id: restore-cache
42-
uses: actions/cache/restore@v5
42+
uses: actions/cache/restore@v6
4343
with:
4444
path: .lycheecache
4545
key: lychee-${{ github.run_id }}
@@ -56,7 +56,7 @@ jobs:
5656
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757

5858
- name: Save lychee cache
59-
uses: actions/cache/save@v5
59+
uses: actions/cache/save@v6
6060
if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'CI-save-pr-cache') }}
6161
with:
6262
path: .lycheecache

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,12 @@ about this topic.
219219
- [opendal](https://github.com/apache/opendal/tree/main/bindings/python) _A data access layer that allows users to easily and efficiently retrieve data from various storage services in a unified way._
220220
- [orjson](https://github.com/ijl/orjson) _Fast Python JSON library._
221221
- [ormsgpack](https://github.com/aviramha/ormsgpack) _Fast Python msgpack library._
222+
- [pdfcrate](https://github.com/ratazzi/pdfcrate) _An ergonomic, high-level PDF generation library for Rust and Python — a Prawn-style layout API for composing documents, not low-level PDF plumbing._
222223
- [polars](https://github.com/pola-rs/polars) _Fast multi-threaded DataFrame library in Rust | Python | Node.js._
223224
- [pycrdt](https://github.com/jupyter-server/pycrdt) _Python bindings for the Rust CRDT implementation [Yrs](https://github.com/y-crdt/y-crdt)._
224225
- [pydantic-core](https://github.com/pydantic/pydantic-core) _Core validation logic for pydantic written in Rust._
225226
- [primp](https://github.com/deedy5/primp) _The fastest python HTTP client that can impersonate web browsers by mimicking their headers and TLS/JA3/JA4/HTTP2 fingerprints._
227+
- [quebec](https://github.com/ratazzi/quebec) _A database-backed background job queue for Python, inspired by Rails' Solid Queue._
226228
- [radiate](https://github.com/pkalivas/radiate): _A high-performance evolution engine for genetic programming and evolutionary algorithms._
227229
- [rateslib](https://github.com/attack68/rateslib) _A fixed income library for Python using Rust extensions._
228230
- [river](https://github.com/online-ml/river) _Online machine learning in python, the computationally heavy statistics algorithms are implemented in Rust._

emscripten/Makefile

Lines changed: 0 additions & 85 deletions
This file was deleted.

newsfragments/6152.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add init config to `ffi` crate

noxfile.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def contributors(session: nox.Session) -> None:
426426

427427
class EmscriptenInfo:
428428
def __init__(self):
429-
self.emscripten_dir = PYO3_DIR / "emscripten"
429+
self.emscripten_dir = PYO3_DIR / "wasm" / "emscripten"
430430
self.builddir = PYO3_DIR / ".nox/emscripten"
431431
self.builddir.mkdir(exist_ok=True, parents=True)
432432

@@ -503,6 +503,75 @@ def test_emscripten(session: nox.Session):
503503
)
504504

505505

506+
class WasiInfo:
507+
def __init__(self):
508+
self.wasi_dir = PYO3_DIR / "wasm" / "wasi"
509+
self.builddir = PYO3_DIR / ".nox/wasi"
510+
self.builddir.mkdir(exist_ok=True, parents=True)
511+
512+
self.pyversion = sys.version.split()[0]
513+
self.pymajor, self.pyminor = self.pyversion.split(".")[:2]
514+
self.pymajorminor = f"{self.pymajor}.{self.pyminor}"
515+
516+
# In CI the WASI SDK is installed by setup-wasi-sdk-action (sets WASI_SDK_PATH);
517+
# otherwise the Makefile downloads it into the build dir.
518+
wasi_sdk_env = os.environ.get("WASI_SDK_PATH")
519+
self.wasi_sdk = (
520+
Path(wasi_sdk_env) if wasi_sdk_env else self.builddir / "wasi-sdk"
521+
)
522+
self.cpython_dir = self.builddir / "build" / f"Python-{self.pyversion}"
523+
crossbuild_dir = self.cpython_dir / "cross-build" / "wasm32-wasip1"
524+
self.libdir = crossbuild_dir / "build" / f"lib.wasi-wasm32-{self.pymajorminor}"
525+
526+
527+
@nox.session(name="build-wasm", venv_backend="none")
528+
def build_wasm(session: nox.Session):
529+
info = WasiInfo()
530+
_run(
531+
session,
532+
"make",
533+
"-C",
534+
str(info.wasi_dir),
535+
f"PYTHON={sys.executable}",
536+
f"BUILDROOT={info.builddir}",
537+
f"PYMAJORMINORMICRO={info.pyversion}",
538+
external=True,
539+
)
540+
541+
542+
@nox.session(name="test-wasm", venv_backend="none")
543+
def test_wasm(session: nox.Session):
544+
info = WasiInfo()
545+
546+
target = "wasm32-wasip1"
547+
548+
# if wasmtime was installed by build-wasm, this is where it would be;
549+
# in CI it is installed by the wasmtime/setup action
550+
session.env["PATH"] = (
551+
f"{info.builddir / 'wasmtime'}{os.pathsep}{os.environ['PATH']}"
552+
)
553+
session.env["PYO3_CROSS_LIB_DIR"] = str(info.libdir)
554+
session.env["CARGO_BUILD_TARGET"] = target
555+
session.env["CARGO_TARGET_WASM32_WASIP1_RUNNER"] = (
556+
f"wasmtime run --dir {info.cpython_dir}::/ --env PYTHONPATH=/lib"
557+
)
558+
session.env["RUSTFLAGS"] = " ".join(
559+
[
560+
f"-C link-arg=-L{info.wasi_sdk}/share/wasi-sysroot/lib/wasm32-wasi",
561+
"-C link-arg=-lwasi-emulated-signal",
562+
"-C link-arg=-lwasi-emulated-process-clocks",
563+
"-C link-arg=-lwasi-emulated-getpid",
564+
"-C link-arg=-lmpdec",
565+
"-C link-arg=-lHacl_HMAC",
566+
"-C link-arg=-lexpat",
567+
]
568+
)
569+
session.env["RUSTDOCFLAGS"] = session.env["RUSTFLAGS"]
570+
_run(session, "rustup", "target", "add", target, "--toolchain", "stable")
571+
572+
_run(session, "cargo", "test", *session.posargs, external=True)
573+
574+
506575
@nox.session(name="test-cross-compilation-windows")
507576
def test_cross_compilation_windows(session: nox.Session):
508577
session.install("cargo-xwin")

pyo3-benches/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pyo3 = { path = "../", features = ["auto-initialize", "full"] }
1313
pyo3-build-config = { path = "../pyo3-build-config" }
1414

1515
[dev-dependencies]
16-
codspeed-criterion-compat = "4.0"
16+
codspeed-criterion-compat = "5.0"
1717
criterion = "0.8.0"
1818
num-bigint = "0.4.3"
1919
rust_decimal = { version = "1.0.0", default-features = false }

0 commit comments

Comments
 (0)