diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b433c46..8df302a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -50,6 +50,18 @@ jobs: args: --release --out dist ${{ matrix.extra-build-args || '' }} sccache: 'true' manylinux: auto + - name: Build free-threaded wheels + uses: PyO3/maturin-action@v1 + env: + # Make psm compile, see https://github.com/rust-lang/stacker/issues/79 + CFLAGS_s390x_unknown_linux_gnu: "-march=z10" + # Workaround ring 0.17 build issue + CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8" + with: + target: ${{ matrix.target }} + args: --release --out dist -i python3.13t ${{ matrix.extra-build-args || '' }} + sccache: 'true' + manylinux: auto - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -74,6 +86,13 @@ jobs: target: ${{ matrix.target }} args: --release --out dist sccache: 'true' + - name: Build free-threaded wheels + uses: PyO3/maturin-action@v1 + with: + maturin-version: '1.7.7-beta.1' + target: ${{ matrix.target }} + args: --release --out dist -i python3.13t + sccache: 'true' - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -97,6 +116,12 @@ jobs: target: ${{ matrix.target }} args: --release --out dist sccache: 'true' + - name: Build free-threaded wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + args: --release --out dist -i python3.13t + sccache: 'true' - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -124,7 +149,7 @@ jobs: id-token: write name: Release runs-on: ubuntu-latest - if: "startsWith(github.ref, 'refs/tags/')" + if: startsWith(github.ref, 'refs/tags/') needs: [linux, windows, macos, sdist] steps: - uses: actions/download-artifact@v3 diff --git a/Cargo.lock b/Cargo.lock index f04bf3b..54b93ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -1449,9 +1449,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.22.5" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d922163ba1f79c04bc49073ba7b32fd5a8d3b76a87c955921234b8e77333c51" +checksum = "f54b3d09cbdd1f8c20650b28e7b09e338881482f4aa908a5f61a00c98fba2690" dependencies = [ "cfg-if", "indoc", @@ -1467,19 +1467,20 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.5" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc38c5feeb496c8321091edf3d63e9a6829eab4b863b4a6a65f26f3e9cc6b179" +checksum = "3015cf985888fe66cfb63ce0e321c603706cd541b7aec7ddd35c281390af45d8" dependencies = [ "once_cell", + "python3-dll-a", "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.22.5" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94845622d88ae274d2729fcefc850e63d7a3ddff5e3ce11bd88486db9f1d357d" +checksum = "6fca7cd8fd809b5ac4eefb89c1f98f7a7651d3739dfb341ca6980090f554c270" dependencies = [ "libc", "pyo3-build-config", @@ -1487,9 +1488,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.5" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e655aad15e09b94ffdb3ce3d217acf652e26bbc37697ef012f5e5e348c716e5e" +checksum = "34e657fa5379a79151b6ff5328d9216a84f55dc93b17b08e7c3609a969b73aa0" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -1499,9 +1500,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.5" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1e3f09eecd94618f60a455a23def79f79eba4dc561a97324bf9ac8c6df30ce" +checksum = "295548d5ffd95fd1981d2d3cf4458831b21d60af046b729b6fd143b0ba7aee2f" dependencies = [ "heck", "proc-macro2", @@ -1510,6 +1511,15 @@ dependencies = [ "syn", ] +[[package]] +name = "python3-dll-a" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0b78171a90d808b319acfad166c4790d9e9759bbc14ac8273fe133673dd41b" +dependencies = [ + "cc", +] + [[package]] name = "qcms" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index c01adff..6706764 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ filetime = "0.2.22" flate2 = "1" fontdb = "0.21.0" pathdiff = "0.2" -pyo3 = { version = "0.22.5", features = ["abi3-py37"] } +pyo3 = { version = "0.23.2", features = ["abi3-py38", "generate-import-lib"] } same-file = "1" serde = { version = "1.0.209", features = ["derive"] } serde_json = "1" diff --git a/pyproject.toml b/pyproject.toml index 6d986c0..fe2177c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,13 +4,14 @@ build-backend = "maturin" [project] name = "typst" -requires-python = ">=3.7" +requires-python = ">=3.8" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] dependencies = ["importlib-resources; python_version < '3.9'"] +dynamic = ["version"] [tool.maturin] module-name = "typst._typst" diff --git a/src/lib.rs b/src/lib.rs index 7a0fb70..03c36d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,9 +46,9 @@ mod output_template { } fn resources_path(py: Python<'_>, package: &str) -> PyResult { - let resources = match py.import_bound("importlib.resources") { + let resources = match py.import("importlib.resources") { Ok(module) => module, - Err(_) => py.import_bound("importlib_resources")?, + Err(_) => py.import("importlib_resources")?, }; let files = resources.call_method1("files", (package,))?; let files = resources.call_method1("as_file", (files,))?; @@ -63,11 +63,7 @@ fn resources_path(py: Python<'_>, package: &str) -> PyResult { files .call_method1( "__exit__", - ( - err.get_type_bound(py), - err.value_bound(py), - err.traceback_bound(py), - ), + (err.get_type(py), err.value(py), err.traceback(py)), ) .unwrap(); @@ -219,11 +215,11 @@ impl Compiler { let buffers = py.allow_threads(|| self.compile(format, ppi))?; if buffers.len() == 1 { // Return a single buffer as a single byte string - Ok(PyBytes::new_bound(py, &buffers[0]).into()) + Ok(PyBytes::new(py, &buffers[0]).into()) } else { - let list = PyList::empty_bound(py); + let list = PyList::empty(py); for buffer in buffers { - list.append(PyBytes::new_bound(py, &buffer))?; + list.append(PyBytes::new(py, &buffer))?; } Ok(list.into()) } @@ -241,7 +237,7 @@ impl Compiler { format: Option<&str>, ) -> PyResult { py.allow_threads(|| self.query(selector, field, one, format)) - .map(|s| PyString::new_bound(py, &s).into()) + .map(|s| PyString::new(py, &s).into()) } } @@ -283,7 +279,7 @@ fn py_query( } /// Python binding to typst -#[pymodule] +#[pymodule(gil_used = false)] fn _typst(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add("__version__", env!("CARGO_PKG_VERSION"))?; m.add_class::()?;