Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade pyo3 to 0.23 and build free-threaded wheels #70

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 8 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ mod output_template {
}

fn resources_path(py: Python<'_>, package: &str) -> PyResult<PathBuf> {
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,))?;
Expand All @@ -63,11 +63,7 @@ fn resources_path(py: Python<'_>, package: &str) -> PyResult<PathBuf> {
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();

Expand Down Expand Up @@ -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())
}
Expand All @@ -241,7 +237,7 @@ impl Compiler {
format: Option<&str>,
) -> PyResult<PyObject> {
py.allow_threads(|| self.query(selector, field, one, format))
.map(|s| PyString::new_bound(py, &s).into())
.map(|s| PyString::new(py, &s).into())
}
}

Expand Down Expand Up @@ -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::<Compiler>()?;
Expand Down