You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A package needs to make a few changes in their recipe to be compatible with cross-compilation. Here are a few examples.
390
+
- If it needs to run during the build, it goes in ``build``.
391
+
- If it needs to be available on the target host, it goes in ``host``.
392
+
- If both conditions are true, it belongs in both.
393
+
394
+
However, there are some exceptions to this rule; most notably Python cross-compilation
395
+
(:ref:`see below <python_cross_compilation>`).
396
+
397
+
Cross-compilation examples
398
+
^^^^^^^^^^^^^^^^^^^^^^^^^^
399
+
400
+
A package needs to make a few changes in their recipe to be compatible with cross-compilation. Here
401
+
are a few examples.
314
402
315
403
A simple C library using autotools for cross-compilation might look like this:
316
404
@@ -323,18 +411,59 @@ A simple C library using autotools for cross-compilation might look like this:
323
411
- pkg-config
324
412
- gnuconfig
325
413
326
-
In the build script, it would need to update the config files and guard any tests when cross-compiling:
414
+
In the build script, it would need to update the config files and guard any tests when
415
+
cross-compiling:
327
416
328
417
.. code-block:: sh
329
418
330
419
# Get an updated config.sub and config.guess
331
420
cp $BUILD_PREFIX/share/gnuconfig/config.*.
332
421
333
422
# Skip ``make check`` when cross-compiling
334
-
if [[ "${CONDA_BUILD_CROSS_COMPILATION}"!="1" ]];then
423
+
if [[ "${CONDA_BUILD_CROSS_COMPILATION:-}"!="1"||"${CROSSCOMPILING_EMULATOR:-}"!="" ]];then
335
424
make check
336
425
fi
337
426
427
+
A simple C++ library using CMake for cross-compilation might look like this:
428
+
429
+
.. code-block:: yaml
430
+
431
+
requirements:
432
+
build:
433
+
- {{ compiler("cxx") }}
434
+
- cmake
435
+
- make
436
+
437
+
In the build script, it would need to update ``cmake`` call and guard any tests when cross-compiling:
438
+
439
+
.. code-block:: sh
440
+
441
+
# Pass ``CMAKE_ARGS`` to ``cmake``
442
+
cmake ${CMAKE_ARGS} ..
443
+
444
+
# Skip ``ctest`` when cross-compiling
445
+
if [[ "${CONDA_BUILD_CROSS_COMPILATION:-}"!="1"||"${CROSSCOMPILING_EMULATOR:-}"!="" ]];then
446
+
ctest
447
+
fi
448
+
449
+
Similarly, with Meson, the ``meta.yaml`` needs:
450
+
451
+
.. code-block:: yaml
452
+
453
+
requirements:
454
+
build:
455
+
- {{ compiler("c") }}
456
+
- {{ compiler("cxx") }}
457
+
- meson
458
+
- make
459
+
460
+
And this in ``build.sh``:
461
+
462
+
.. code-block:: sh
463
+
464
+
# Pass ``MESON_ARGS`` to ``meson``
465
+
meson ${MESON_ARGS} builddir/
466
+
338
467
A simple Python extension using Cython and NumPy's C API would look like so:
339
468
340
469
.. code-block:: yaml
@@ -360,6 +489,90 @@ but merely to provide a starting point with some guidelines. Please look at `oth
360
489
361
490
.. _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
362
491
492
+
.. _python_cross_compilation:
493
+
494
+
Details about cross-compiled Python packages
495
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
496
+
497
+
Cross-compiling Python packages is a bit more involved than other packages. The main pain point is
498
+
that we need an executable Python interpreter (i.e. ``python`` in ``build``) that knows how to
499
+
provide accurate information about the target platform. Since this is not officially supported, a
500
+
series of workarounds are required to make it work. Refer to `PEP720
501
+
<https://peps.python.org/pep-0720/>`__ or `the discussion in this issue
502
+
<https://github.com/conda-forge/conda-forge.github.io/issues/1841>`__ for more information.
503
+
504
+
In practical terms, for conda-forge, this results into two extra metadata bits that are needed in
505
+
``meta.yaml``:
506
+
507
+
- Adding ``cross-python_{{ target_platform }}`` in ``build`` requirements, provided by the
508
+
`cross-python-feedstock <https://github.com/conda-forge/cross-python-feedstock>`__. This is a
509
+
wrapper for the ``crossenv`` Python interpreters with `some activation logic that adjust some of
0 commit comments