PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Other
11.83k stars 726 forks source link

Provide support for HPy #1113

Open thedrow opened 4 years ago

thedrow commented 4 years ago

HPy is a better Python API written in C. The project's goal is to hide CPython's implementation details so that any Python implementation will be able to support C extensions with ease.

One of the main goals of the project is to allow PyPy to support C extensions without emulating CPython's API.

We should consider providing a backend that uses HPy instead of directly using the CPython API. We can use a feature toggle to activate it.

Since HPy's API can be mixed with CPython's API we can gradually migrate more and more code to HPy's API as it evolves.

A first attempt to provide Rust bindings to HPy was made in pyhandle/hpy#20.

davidhewitt commented 4 years ago

It would be interesting to see support for it. One other consideration is that CPython is aiming to move itself towards a much leaner API which might be easily supported by PyPy (https://pythoncapi.readthedocs.io/)

thedrow commented 4 years ago

The authors of that document are part of the HPy effort.

adsharma commented 3 years ago

This is of interest to py2many, a python -> rust transpiler (apart from 6 other languages).

https://github.com/adsharma/py2many/issues/62

cirospaciari commented 1 year ago

Any plans or roadmap to supporting HPy? CPython API slows down a lot in PyPy

davidhewitt commented 1 year ago

While this would be cool, it's low on the list of things which I would to be getting to, so help needed realistically for the foreseeable future.

cirospaciari commented 1 year ago

While this would be cool, it's low on the list of things which I would to be getting to, so help needed realistically for the foreseeable future.

I see, thanks for the update, Thinking of starting HPy.rs project to be a 1-to-1 with HPy., I will put it in my work queue.

thedrow commented 1 year ago

@cirospaciari The HPy project will likely accept a contribution that provides a Rust API automatically using code generation.

davidhewitt commented 1 year ago

That sounds like a great first step, if the HPy project generated an hpy-sys crate (perhaps) which could be used instead of pyo3-ffi when desired.

cirospaciari commented 1 year ago

That sounds like a great first step, if the HPy project generated an hpy-sys crate (perhaps) which could be used instead of pyo3-ffi when desired.

I will try to do this ;)

messense commented 1 year ago

I've put together a rough hpy-sys crate generated via bindgen: https://github.com/messense/hpy/tree/rust/hpy/devel/rust/hpy-sys, there are some issues with this approach, mostly related to cross compilation:

I'm thinking about generating the ffi bindings using bindgen cli for each abi modes instead and commit them in git to avoid these issues.

mattip commented 9 months ago

@cirospaciari how is the work to support HPy going? Is there anything I could do to help?

mattip commented 9 months ago

@messense in hpyproject/hpy#325, @thedrow shows some bindgen output. I don't know rust, is this a step in the right direction?