package/pkg-python: add setuptools-rust infrastructure
PATCH v3 1/2 package/pkg-python: add setuptools-rust infrastructure
The setuptools-rust package infrastructure is essentially a variant of the setuptools package infrastructure which sets up the env and download hooks required for building setuptools-rust packages.
--- package/pkg-python.mk | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)
package/pkg-python.mk +43 -3
@@ -110,6 +110,24 @@ HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \ --root=/ \ --single-version-externally-managed +# Target setuptools-rust-based packages +PKG_PYTHON_SETUPTOOLS_RUST_ENV = \ + $(PKG_PYTHON_SETUPTOOLS_ENV) \ + $(PKG_CARGO_ENV) \ + PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" + +PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = \ + $(PKG_CARGO_ENV) + +# Host setuptools-rust-based packages +HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \ + $(HOST_PKG_PYTHON_SETUPTOOLS_ENV) \ + $(HOST_PKG_CARGO_ENV) \ + PYO3_CROSS_LIB_DIR="$(HOST_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" + +HOST_PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = \ + $(HOST_PKG_CARGO_ENV) + # Target pep517-based packages PKG_PYTHON_PEP517_ENV = \ $(PKG_PYTHON_ENV)
@@ -177,14 +195,30 @@ $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS) endif # Setuptools -else ifeq ($$($(2)_SETUP_TYPE),setuptools) +else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),) ifeq ($(4),target) +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_ENV) +$(2)_DL_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV) +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_CARGO_MANIFEST_PATH) +else $(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_ENV) +endif $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_TARGET_CMD = setup.py install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS) $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS) else +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV) +$(2)_DL_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV) +ifndef $(2)_CARGO_MANIFEST_PATH +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(3)_CARGO_MANIFEST_PATH) +else +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_CARGO_MANIFEST_PATH) +endif +else $(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_ENV) +endif $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) endif
@@ -208,7 +242,7 @@ $(2)_BASE_BUILD_CMD = -m flit_core.wheel $(2)_BASE_INSTALL_CMD ?= -m installer dist/* endif else -$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools', 'pep517' or 'flit'.") +$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools', 'setuptools-rust', 'pep517' or 'flit'.") endif # Target packages need both the python interpreter on the target (for
@@ -225,8 +259,14 @@ endif # ($(4),target) # Setuptools based packages will need setuptools for the host Python # interpreter (both host and target). # -ifeq ($$($(2)_SETUP_TYPE),setuptools) +ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),) $(2)_DEPENDENCIES += $$(if $$(filter host-python-setuptools,$(1)),,host-python-setuptools) +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_DEPENDENCIES += host-python-setuptools-rust host-rustc +# We need to vendor the Cargo crates at download time +$(2)_DOWNLOAD_POST_PROCESS = cargo +$(2)_DOWNLOAD_DEPENDENCIES = host-rustc +endif else ifneq ($$(filter flit pep517,$$($(2)_SETUP_TYPE)),) $(2)_DEPENDENCIES += host-python-pypa-build host-python-installer ifeq ($$($(2)_SETUP_TYPE),flit)
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v3 2/2 package/python-cryptography: migrate to setuptools-rust infrastructure
We can now significantly simplify the python-cryptography build using the new setuptools-rust setup type introduced in the python package infrastructure.
---
Changes v2 -> v3:
- rebase
--- .../python-cryptography.mk | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-)
package/python-cryptography/python-cryptography.mk +4 -26
@@ -7,36 +7,14 @@ PYTHON_CRYPTOGRAPHY_VERSION = 37.0.1 PYTHON_CRYPTOGRAPHY_SOURCE = cryptography-$(PYTHON_CRYPTOGRAPHY_VERSION).tar.gz PYTHON_CRYPTOGRAPHY_SITE = https://files.pythonhosted.org/packages/3d/5f/addb8b91fd356792d28e59a8275fec833323cb28604fb3a497c35d7cf0a3 -PYTHON_CRYPTOGRAPHY_SETUP_TYPE = setuptools +PYTHON_CRYPTOGRAPHY_SETUP_TYPE = setuptools-rust PYTHON_CRYPTOGRAPHY_LICENSE = Apache-2.0 or BSD-3-Clause PYTHON_CRYPTOGRAPHY_LICENSE_FILES = LICENSE LICENSE.APACHE LICENSE.BSD PYTHON_CRYPTOGRAPHY_CPE_ID_VENDOR = cryptography_project PYTHON_CRYPTOGRAPHY_CPE_ID_PRODUCT = cryptography -PYTHON_CRYPTOGRAPHY_DEPENDENCIES = \ - host-python-setuptools-rust \ - host-python-cffi \ - host-rustc \ - openssl -HOST_PYTHON_CRYPTOGRAPHY_DEPENDENCIES = \ - host-python-setuptools-rust \ - host-python-cffi \ - host-rustc \ - host-openssl -PYTHON_CRYPTOGRAPHY_ENV = \ - $(PKG_CARGO_ENV) \ - PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" -HOST_PYTHON_CRYPTOGRAPHY_ENV = \ - $(HOST_PKG_CARGO_ENV) \ - PYO3_CROSS_LIB_DIR="$(HOST_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" -# We need to vendor the Cargo crates at download time -PYTHON_CRYPTOGRAPHY_DOWNLOAD_POST_PROCESS = cargo -PYTHON_CRYPTOGRAPHY_DOWNLOAD_DEPENDENCIES = host-rustc -PYTHON_CRYPTOGRAPHY_DL_ENV = \ - $(PKG_CARGO_ENV) \ - BR_CARGO_MANIFEST_PATH=src/rust/Cargo.toml -HOST_PYTHON_CRYPTOGRAPHY_DL_ENV = \ - $(HOST_PKG_CARGO_ENV) \ - BR_CARGO_MANIFEST_PATH=src/rust/Cargo.toml +PYTHON_CRYPTOGRAPHY_CARGO_MANIFEST_PATH = src/rust/Cargo.toml +PYTHON_CRYPTOGRAPHY_DEPENDENCIES = host-python-cffi openssl +HOST_PYTHON_CRYPTOGRAPHY_DEPENDENCIES = host-python-cffi host-openssl $(eval $(python-package)) $(eval $(host-python-package))
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
James, All,
On 2022-05-01 01:44 -0600, James Hilliard spake thusly:
Quoted 5 lines
The setuptools-rust package infrastructure is essentially a variant of the setuptools package infrastructure which sets up the env and download hooks required for building setuptools-rust packages.
Signed-off-by James Hilliard <[email protected]>
First, thanks a lot for working on this topic; this is greatly appreciated.
However, I believe this one is going a bit too far, at least for now. Indeed, in Buildroot, we try to wait for until we have a few examples of a specific package type before we add infrastructure support for it. Usually, that rounds at about 5-ish packages.
For now, we have a single python package that is partly written in rust, and it is not very complex, so we can live with it for now, and it serves as a pretty good example of what is needed.
However, what I am afraid of, is that even non-python packages may end having parts of them written in rust, and so maybe we would need a more generic solution, with something that's be used like $(kernel-module) or just with variables...
Until we have more such examples, then it is hard to be sure that a new type of python packages is ther good approach or not.
Regards,
Yann E. MORIN.
Quoted 97 lines
--- package/pkg-python.mk | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)package/pkg-python.mk +43
-3@@ -110,6 +110,24 @@ HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \ --root=/ \ --single-version-externally-managed +# Target setuptools-rust-based packages +PKG_PYTHON_SETUPTOOLS_RUST_ENV = \ + $(PKG_PYTHON_SETUPTOOLS_ENV) \ + $(PKG_CARGO_ENV) \ + PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" + +PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = \ + $(PKG_CARGO_ENV) + +# Host setuptools-rust-based packages +HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \ + $(HOST_PKG_PYTHON_SETUPTOOLS_ENV) \ + $(HOST_PKG_CARGO_ENV) \ + PYO3_CROSS_LIB_DIR="$(HOST_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" + +HOST_PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = \ + $(HOST_PKG_CARGO_ENV) + # Target pep517-based packages PKG_PYTHON_PEP517_ENV = \ $(PKG_PYTHON_ENV)@@ -177,14 +195,30 @@ $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS) endif # Setuptools -else ifeq ($$($(2)_SETUP_TYPE),setuptools) +else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),) ifeq ($(4),target) +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_ENV) +$(2)_DL_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV) +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_CARGO_MANIFEST_PATH) +else $(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_ENV) +endif $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_TARGET_CMD = setup.py install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS) $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS) else +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV) +$(2)_DL_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV) +ifndef $(2)_CARGO_MANIFEST_PATH +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(3)_CARGO_MANIFEST_PATH) +else +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_CARGO_MANIFEST_PATH) +endif +else $(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_ENV) +endif $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) endif@@ -208,7 +242,7 @@ $(2)_BASE_BUILD_CMD = -m flit_core.wheel $(2)_BASE_INSTALL_CMD ?= -m installer dist/* endif else -$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools', 'pep517' or 'flit'.") +$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools', 'setuptools-rust', 'pep517' or 'flit'.") endif # Target packages need both the python interpreter on the target (for@@ -225,8 +259,14 @@ endif # ($(4),target) # Setuptools based packages will need setuptools for the host Python # interpreter (both host and target). # -ifeq ($$($(2)_SETUP_TYPE),setuptools) +ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),) $(2)_DEPENDENCIES += $$(if $$(filter host-python-setuptools,$(1)),,host-python-setuptools) +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_DEPENDENCIES += host-python-setuptools-rust host-rustc +# We need to vendor the Cargo crates at download time +$(2)_DOWNLOAD_POST_PROCESS = cargo +$(2)_DOWNLOAD_DEPENDENCIES = host-rustc +endif else ifneq ($$(filter flit pep517,$$($(2)_SETUP_TYPE)),) $(2)_DEPENDENCIES += host-python-pypa-build host-python-installer ifeq ($$($(2)_SETUP_TYPE),flit)Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 13 lines · Yann E. MORIN
James, All,
On 2022-05-01 01:44 -0600, James Hilliard spake thusly:
Quoted 5 lines
The setuptools-rust package infrastructure is essentially a variant of the setuptools package infrastructure which sets up the env and download hooks required for building setuptools-rust packages.
Signed-off-by James Hilliard <[email protected]>First, thanks a lot for working on this topic; this is greatly appreciated.
Quoted 8 lines
However, I believe this one is going a bit too far, at least for now. Indeed, in Buildroot, we try to wait for until we have a few examples of a specific package type before we add infrastructure support for it. Usually, that rounds at about 5-ish packages.
For now, we have a single python package that is partly written in rust, and it is not very complex, so we can live with it for now, and it serves as a pretty good example of what is needed.
I found it wasn't very clear in differentiating what variables/deps are specific to setuptools-rust and what are specific to python-cryptography.
Quoted 5 lines
However, what I am afraid of, is that even non-python packages may end having parts of them written in rust, and so maybe we would need a more generic solution, with something that's be used like $(kernel-module) or just with variables...
The setuptools-rust SETUP_TYPE is meant to be used with packages using the setuptools-rust extension(https://github.com/PyO3/setuptools-rust), it's not something generic that would make sense for non-python packages or even python packages using a different type of rust integration as some of the env variables are specific to the setuptools-rust extension(although there may be some common env variables that can be shared in that case).
Other python based build systems like meson have some rust support as well but they would not make use of this as setuptools-rust is not how they implement their rust integrations
Quoted 3 lines
Until we have more such examples, then it is hard to be sure that a new type of python packages is ther good approach or not.
Let me see if there's any other packages we have that may be migrating to setuptools-rust.
Quoted 104 lines
Regards,
Yann E. MORIN.Quoted 93 lines
--- package/pkg-python.mk | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)package/pkg-python.mk +43
-4@@ -110,6 +110,24 @@ HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \ --root=/ \ --single-version-externally-managed +# Target setuptools-rust-based packages +PKG_PYTHON_SETUPTOOLS_RUST_ENV = \ + $(PKG_PYTHON_SETUPTOOLS_ENV) \ + $(PKG_CARGO_ENV) \ + PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" + +PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = \ + $(PKG_CARGO_ENV) + +# Host setuptools-rust-based packages +HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \ + $(HOST_PKG_PYTHON_SETUPTOOLS_ENV) \ + $(HOST_PKG_CARGO_ENV) \ + PYO3_CROSS_LIB_DIR="$(HOST_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)" + +HOST_PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV = \ + $(HOST_PKG_CARGO_ENV) + # Target pep517-based packages PKG_PYTHON_PEP517_ENV = \ $(PKG_PYTHON_ENV)@@ -177,14 +195,30 @@ $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS) endif # Setuptools -else ifeq ($$($(2)_SETUP_TYPE),setuptools) +else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),) ifeq ($(4),target) +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_ENV) +$(2)_DL_ENV = $$(PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV) +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_CARGO_MANIFEST_PATH) +else $(2)_BASE_ENV = $$(PKG_PYTHON_SETUPTOOLS_ENV) +endif $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_TARGET_CMD = setup.py install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS) $(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS) else +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV) +$(2)_DL_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_RUST_DL_ENV) +ifndef $(2)_CARGO_MANIFEST_PATH +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(3)_CARGO_MANIFEST_PATH) +else +$(2)_DL_ENV += BR_CARGO_MANIFEST_PATH=$$($(2)_CARGO_MANIFEST_PATH) +endif +else $(2)_BASE_ENV = $$(HOST_PKG_PYTHON_SETUPTOOLS_ENV) +endif $(2)_BASE_BUILD_CMD = setup.py build $(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS) endif@@ -208,7 +242,7 @@ $(2)_BASE_BUILD_CMD = -m flit_core.wheel $(2)_BASE_INSTALL_CMD ?= -m installer dist/* endif else -$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools', 'pep517' or 'flit'.") +$$(error "Invalid $(2)_SETUP_TYPE. Valid options are 'distutils', 'setuptools', 'setuptools-rust', 'pep517' or 'flit'.") endif # Target packages need both the python interpreter on the target (for@@ -225,8 +259,14 @@ endif # ($(4),target) # Setuptools based packages will need setuptools for the host Python # interpreter (both host and target). # -ifeq ($$($(2)_SETUP_TYPE),setuptools) +ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),) $(2)_DEPENDENCIES += $$(if $$(filter host-python-setuptools,$(1)),,host-python-setuptools) +ifeq ($$($(2)_SETUP_TYPE),setuptools-rust) +$(2)_DEPENDENCIES += host-python-setuptools-rust host-rustc +# We need to vendor the Cargo crates at download time +$(2)_DOWNLOAD_POST_PROCESS = cargo +$(2)_DOWNLOAD_DEPENDENCIES = host-rustc +endif else ifneq ($$(filter flit pep517,$$($(2)_SETUP_TYPE)),) $(2)_DEPENDENCIES += host-python-pypa-build host-python-installer ifeq ($$($(2)_SETUP_TYPE),flit) --2.25.1
Quoted 4 lines
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot--
.-----------------.--------------------.------------------.--------------------.
Quoted 5 lines
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot