[meta-python,3/7] setuptools3_rust.bbclass: setuptoools Rust plugin

Message ID 360dbafb5ca9b4cfd646a1ee1f63cb5d85b3a974.1642309436.git.tim.orling@konsulko.com
State New
Headers show
Series [meta-python,1/7] python3-setuptools-rust-native: add v1.1.2 recipe | expand

Commit Message

Tim Orling Jan. 16, 2022, 5:29 a.m. UTC
setuptools-rust is a plugin for setuptools to build Rust Python extensions
implemented with PyO3 or rust-cpython.

Compile and distribute Python extensions written in Rust as easily as if
they were written in C.

This class inherits pyo3.bbclass (and therefore cargo.bbclass) and
setuptools3.bbclass to make it easier to build Python modules with Rust
extensions.

Need to call pyo3_do_configure to properly setup the PyO3 environment
for cross-compiling.

Need to call cargo_common_do_configure to setup cargo_home/config so
that the linker properly finds e.g. crti.o and crtbeginS.o

It is strongly recommended to provide crates needed for your recipe
using the crate:// fetcher. This can be helped with the cargo-bitbake
command [1].

If you choose not to use the crate fetcher, bitbake vendoring will not
work with setuptools-rust, as it errors out immediately because it cannot
find pyo3 or some other crate. The (strongly discouraged) workaround for
this is to set:

CARGO_DISABLE_BITBAKE_VENDORING = "1"

[1] https://crates.io/crates/cargo-bitbake

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 meta-python/classes/setuptools3_rust.bbclass | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 meta-python/classes/setuptools3_rust.bbclass

Patch

diff --git a/meta-python/classes/setuptools3_rust.bbclass b/meta-python/classes/setuptools3_rust.bbclass
new file mode 100644
index 0000000000..fb11f08f89
--- /dev/null
+++ b/meta-python/classes/setuptools3_rust.bbclass
@@ -0,0 +1,11 @@ 
+inherit pyo3 setuptools3
+
+DEPENDS += "python3-setuptools-rust-native"
+
+setuptools3_rust_do_configure() {
+    pyo3_do_configure
+    cargo_common_do_configure
+    setuptools3_do_configure
+}
+
+EXPORT_FUNCTIONS do_configure