setuptools-rust icon indicating copy to clipboard operation
setuptools-rust copied to clipboard

Ability to specify rust_extensions via setup.cfg

Open alex opened this issue 3 years ago • 7 comments
trafficstars

Currently one specifies rust_extensions in setup.py, imperatively (e.g. https://github.com/pyca/cryptography/blob/main/setup.py#L43-L56). Nowadays, setuptools lets one specify many options declaratively in setup.cfg (e.g. https://github.com/pyca/cryptography/blob/main/setup.cfg). It'd be great if rust_extensions could also be specified in setup.cfg -- though truthfully I have no idea if that is possible!

alex avatar Feb 26 '22 14:02 alex

I agree that this would be great. I think that this needs support from setuptools maintainers. As far as I know, this page describes all the valid setup.cfg fields and I'm not aware of a mechanism for plugins like setuptools_rust to define additional fields.

davidhewitt avatar Feb 26 '22 19:02 davidhewitt

FYI: a related upstream issue: https://github.com/pypa/setuptools/issues/1272

messense avatar Mar 20 '22 05:03 messense

Although we can not extend setup.cfg, we can certainly extend pyproject.toml to add a [tool.setuptools-rust] section, for example

[[tool.setuptools-rust.rust-extensions]]
target = "example"
binding = "pyo3"

Then we can implement a PEP 517 backend in setuptools-rust to read it and generate a corresponding setup.py.

[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
build-backend = "setuptools_rust"

messense avatar Jul 31 '22 03:07 messense

At least for my use case I need the build backend to be setuptools itself, since I also have cffi extensions that need its setuptools extension.

I don't we can do configuration in pyproject.toml without overriding build-backend?

alex avatar Jul 31 '22 03:07 alex

Right, but it should work after merging https://github.com/pyca/cryptography/pull/7164

messense avatar Jul 31 '22 03:07 messense

Good point! Though that's still a ways off since it needs patches to rust and pypy.

alex avatar Jul 31 '22 03:07 alex

Or we can add a [tool.setuptools-rust.extra-setup-args] that can add arbitrary arguments to the generated setup.py.

[tool.setuptools-rust.extra-setup-args]
cffi_modules = ["src/_cffi_src/build_openssl.py:ffi"]

messense avatar Jul 31 '22 03:07 messense

I think it'd be also great if the use of the rust_extensions keyword arg did not require me to also import RustExtension()... I'm not sure how setuptools handles it nowadays, but importing a dependency in setup.py used to be a huge pain, because it might or might not be there on install.

nils-werner avatar Mar 31 '23 08:03 nils-werner

I saw the help-wanted label in this issue and I gave it a try in #348. Please feel free to ignore/close if that is not what the project is looking for.

abravalheri avatar Aug 03 '23 18:08 abravalheri

I think this is resolved now. Thank you!

alex avatar Aug 11 '23 12:08 alex