All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Orling <ticotimo@gmail.com>
To: openembedded-devel@lists.openembedded.org
Subject: [meta-python][PATCH 2/7] pyo3.bbclass: add class for PyO3 cross-compilation
Date: Sat, 15 Jan 2022 21:28:59 -0800	[thread overview]
Message-ID: <2847980b4d497b069460a298853cb7f59fab662e.1642309436.git.tim.orling@konsulko.com> (raw)
In-Reply-To: <cover.1642309436.git.tim.orling@konsulko.com>

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>
---
 meta-python/classes/pyo3.bbclass | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 meta-python/classes/pyo3.bbclass

diff --git a/meta-python/classes/pyo3.bbclass b/meta-python/classes/pyo3.bbclass
new file mode 100644
index 0000000000..4bae0949e5
--- /dev/null
+++ b/meta-python/classes/pyo3.bbclass
@@ -0,0 +1,30 @@
+#
+# This class helps make sure that Python extensions built with PyO3
+# and setuptools_rust properly set up the environment for cross compilation
+#
+
+inherit cargo python3-dir siteinfo
+
+export PYO3_CROSS="1"
+export PYO3_CROSS_PYTHON_VERSION="${PYTHON_BASEVERSION}"
+export PYO3_CROSS_LIB_DIR="${STAGING_LIBDIR}"
+export CARGO_BUILD_TARGET="${HOST_SYS}"
+export RUSTFLAGS
+export PYO3_PYTHON="${PYTHON}"
+export PYO3_CONFIG_FILE="${WORKDIR}/pyo3.config"
+
+pyo3_do_configure () {
+    cat > ${WORKDIR}/pyo3.config << EOF
+implementation=CPython
+version=${PYTHON_BASEVERSION}
+shared=true
+abi3=false
+lib_name=${PYTHON_DIR}
+lib_dir=${STAGING_LIBDIR}
+pointer_width=${SITEINFO_BITS}
+build_flags=WITH_THREAD
+suppress_build_script_link_lines=false
+EOF
+}
+
+EXPORT_FUNCTIONS do_configure
-- 
2.30.2



  parent reply	other threads:[~2022-01-16  5:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-16  5:28 [meta-python][PATCH 0/7] setuptools-rust and python3-cryptography Tim Orling
2022-01-16  5:28 ` [meta-python][PATCH 1/7] python3-setuptools-rust-native: add v1.1.2 recipe Tim Orling
2022-01-16  5:28 ` Tim Orling [this message]
2022-01-16  5:29 ` [meta-python][PATCH 3/7] setuptools3_rust.bbclass: setuptoools Rust plugin Tim Orling
2022-01-16  5:29 ` [meta-python][PATCH 4/7] python3-pyruvate: add recipe for v1.1.2 Tim Orling
2022-01-18 17:15   ` [oe] " Khem Raj
2022-01-18 17:22     ` Tim Orling
2022-01-16  5:29 ` [meta-python][PATCH 5/7] python3-pytest-subtests: upgrade 0.5.0 -> 0.6.0 Tim Orling
2022-01-16  5:29 ` [meta-python][PATCH 6/7] python3-cryptography-vectors: upgrade 35.0.0 => 36.0.1 Tim Orling
2022-01-16  5:29 ` [meta-python][PATCH 7/7] python3-cryptography: upgrade 3.3.2 -> 36.0.1 Tim Orling
2022-01-19 12:51   ` [oe] " Ross Burton
2022-01-19 12:13 ` [oe] [meta-python][PATCH 0/7] setuptools-rust and python3-cryptography Samuli Piippo
2022-01-19 19:38   ` Tim Orling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2847980b4d497b069460a298853cb7f59fab662e.1642309436.git.tim.orling@konsulko.com \
    --to=ticotimo@gmail.com \
    --cc=openembedded-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.