Skip to content

Commit cb3af4e

Browse files
committed
add details about Python particularities
1 parent df299ca commit cb3af4e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

sphinx/src/maintainer/knowledge_base.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,43 @@ but merely to provide a starting point with some guidelines. Please look at `oth
453453

454454
.. _other recipes for more examples: https://github.com/search?q=org%3Aconda-forge+path%3Arecipe%2Fmeta.yaml+%22%5Bbuild_platform+%21%3D+target_platform%5D%22&type=code
455455

456+
Details about cross-compiled Python packages
457+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
458+
459+
Cross-compiling Python packages is a bit more involved than other packages. This is because Python
460+
doesn't have official support for cross-compilation and a series of workarounds need to be applied
461+
to make it work. See `PEP720 <https://peps.python.org/pep-0720/>`__ for more details.
462+
463+
On conda-forge, there are two extra metadata bits that are needed in ``meta.yaml``:
464+
465+
- Adding ``cross-python_{{ target_platform }}`` in ``build`` requirements, provided by the
466+
`cross-python-feedstock <https://github.com/conda-forge/cross-python-feedstock>`__. This is a
467+
wrapper for the ``crossenv`` Python interpreters with `some activation logic that adjust some of
468+
the crossenv workarounds
469+
<https://github.com/conda-forge/cross-python-feedstock/blob/main/recipe/activate-cross-python.sh>`__
470+
so they work better with the conda-build setup.
471+
- Copying some Python-related packages from ``host`` to ``build`` with a ``[build_platform !=
472+
target_platform]`` selector:
473+
- ``python`` itself, to support ``crossenv``.
474+
- Non-pure Python packages (i.e. they ship compiled libraries) that need to be present while the
475+
package is being built, like ``cython`` and ``numpy``.
476+
477+
In the terms of the `PEP720 <https://peps.python.org/pep-0720/>`__, the conda-forge setup
478+
implements the "faking the target environment" approach. More specifically:
479+
480+
This will result in the following changes before the builds scripts run:
481+
482+
- A modified ``crossenv`` installation in ``$BUILD_PREFIX/venv``, mimicking the architecture of
483+
``$PREFIX``.
484+
- Forwarder binaries in ``$BUILD_PREFIX/bin`` that point to the ``crossenv`` installation.
485+
- Symlinks that expose the ``$BUILD_PREFIX`` site-packages in the ``crossenv`` installation, which
486+
is also included in ``$PYTHONPATH``.
487+
- A copy of all ``$PREFIX`` site-packages to ``$BUILD_PREFIX`` (except the compiled libraries).
488+
489+
All in all, this results in a setup where ``conda-build`` can run a ``$BUILD_PREFIX``-architecture
490+
``python`` interpreter that can see the packages in ``$PREFIX`` (with the compiled bits provided by
491+
their corresponding counterparts in ``$BUILD_PREFIX``) and mimic that target architecture.
492+
456493
Rust Nightly
457494
------------
458495

0 commit comments

Comments
 (0)