From f9fdeb6ac76435a9822f0e40d65ba1904830cebf Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:20:15 +0000 Subject: [PATCH] Fix build for PyO3 0.28 and maturin 1.x Port the module function to the Bound API (the &PyModule form was removed in PyO3 0.23), drop maturin flags removed in 1.x (--no-sdist, --universal2), give each job's wheel artifact a unique name, and let the sdist build with maturin 1.x. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/CI.yml | 13 ++-- Cargo.lock | 133 +++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- src/lib.rs | 5 +- 4 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 Cargo.lock diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0dd7150..7952fec 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,7 +17,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v7 with: - name: wheels + name: wheels-linux path: dist windows: @@ -27,11 +27,11 @@ jobs: - uses: messense/maturin-action@v1 with: command: build - args: --release --no-sdist -o dist + args: --release -o dist - name: Upload wheels uses: actions/upload-artifact@v7 with: - name: wheels + name: wheels-windows path: dist macos: @@ -41,11 +41,11 @@ jobs: - uses: messense/maturin-action@v1 with: command: build - args: --release --no-sdist -o dist --universal2 + args: --release -o dist --target universal2-apple-darwin - name: Upload wheels uses: actions/upload-artifact@v7 with: - name: wheels + name: wheels-macos path: dist release: @@ -56,7 +56,8 @@ jobs: steps: - uses: actions/download-artifact@v8 with: - name: wheels + pattern: wheels-* + merge-multiple: true - name: Publish to PyPI uses: messense/maturin-action@v1 env: diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7fc4f0c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,133 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pyo3" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12" +dependencies = [ + "libc", + "once_cell", + "portable-atomic", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", +] + +[[package]] +name = "pyo3-build-config" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e" +dependencies = [ + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb" +dependencies = [ + "heck", + "proc-macro2", + "pyo3-build-config", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rust-python-extension" +version = "0.1.0" +dependencies = [ + "pyo3", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" diff --git a/pyproject.toml b/pyproject.toml index 2a29370..a120f63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.12,<0.13"] +requires = ["maturin>=1.0,<2.0"] build-backend = "maturin" [project] diff --git a/src/lib.rs b/src/lib.rs index 585f713..9d7a995 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ - use pyo3::prelude::*; /// Formats the sum of two numbers as string. @@ -9,7 +8,7 @@ fn sum_as_string(a: usize, b: usize) -> PyResult { /// A Python module implemented in Rust. #[pymodule] -fn rust_python_extension(_py: Python, m: &PyModule) -> PyResult<()> { +fn rust_python_extension(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; Ok(()) -} \ No newline at end of file +}