summaryrefslogtreecommitdiffstats
path: root/meta-python/classes
diff options
context:
space:
mode:
authorTim Orling <ticotimo@gmail.com>2022-01-15 21:28:59 -0800
committerKhem Raj <raj.khem@gmail.com>2022-01-18 12:53:38 -0800
commit5c7d63a4377f13e6415fa6e72503b072f898d6a8 (patch)
treee82f59c51c3e38d7280dc95d67261e70b619fda2 /meta-python/classes
parentbd4e4d2065f86103fc1e164bfa4c613e298cff90 (diff)
downloadmeta-openembedded-5c7d63a4377f13e6415fa6e72503b072f898d6a8.tar.gz
pyo3.bbclass: add class for PyO3 cross-compilation
PyO3 provides Rust bindings for Python, including tools for creating native Python extension modules. Running and interacting with Python code from a Rust binary is also supported. This class sets up the cross-compilation environment. Export PYO3_CROSS, PYO3_CROSS_LIB_DIR, PYO3_CROSS_INCLUDE_DIR and CARGO_BUILD_TARGET to inform tools like setuptools-rust we are cross-compiling. Export RUSTFLAGS so cargo can find 'std' and 'core' for target Dynamically generate PyO3 config file and export PYO3_CONFIG_FILE absolute path. This is the trick that finally made pyo3 work. Signed-off-by: Tim Orling <tim.orling@konsulko.com> Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com>
Diffstat (limited to 'meta-python/classes')
-rw-r--r--meta-python/classes/pyo3.bbclass30
1 files changed, 30 insertions, 0 deletions
diff --git a/meta-python/classes/pyo3.bbclass b/meta-python/classes/pyo3.bbclass
new file mode 100644
index 0000000000..6ce21329c2
--- /dev/null
+++ b/meta-python/classes/pyo3.bbclass
@@ -0,0 +1,30 @@
1#
2# This class helps make sure that Python extensions built with PyO3
3# and setuptools_rust properly set up the environment for cross compilation
4#
5
6inherit cargo python3-dir siteinfo
7
8export PYO3_CROSS="1"
9export PYO3_CROSS_PYTHON_VERSION="${PYTHON_BASEVERSION}"
10export PYO3_CROSS_LIB_DIR="${STAGING_LIBDIR}"
11export CARGO_BUILD_TARGET="${HOST_SYS}"
12export RUSTFLAGS
13export PYO3_PYTHON="${PYTHON}"
14export PYO3_CONFIG_FILE="${WORKDIR}/pyo3.config"
15
16pyo3_do_configure () {
17 cat > ${WORKDIR}/pyo3.config << EOF
18implementation=CPython
19version=${PYTHON_BASEVERSION}
20shared=true
21abi3=false
22lib_name=${PYTHON_DIR}
23lib_dir=${STAGING_LIBDIR}
24pointer_width=${SITEINFO_BITS}
25build_flags=WITH_THREAD
26suppress_build_script_link_lines=false
27EOF
28}
29
30EXPORT_FUNCTIONS do_configure