forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: write all "customizing build" and "background info" build docs
- Loading branch information
Showing
10 changed files
with
342 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,101 @@ | ||
Compiler selection and custom build flags | ||
========================================= | ||
|
||
TODO | ||
Selecting a specific compiler | ||
----------------------------- | ||
|
||
Meson supports the standard environment variables ``CC``, ``CXX`` and ``FC`` to | ||
select specific C, C++ and/or Fortran compilers. These environment variables are | ||
documented in `the reference tables in the Meson docs | ||
<https://mesonbuild.com/Reference-tables.html#compiler-and-linker-flag-environment-variables>`__. | ||
|
||
Note that environment variables only get applied from a clean build, because | ||
they affect the configure stage (i.e., ``meson setup``). An incremental rebuild | ||
does not react to changes in environment variables - you have to run ``git | ||
clean -xdf`` and do a full rebuild, or run ``meson setup --reconfigure``. | ||
|
||
|
||
Adding a custom compiler or linker flag | ||
--------------------------------------- | ||
|
||
Meson by design prefers builds being configured through command-line options | ||
passed to ``meson setup``. It provides many built-in options: | ||
|
||
- For enabling a debug build and the optimization level, see the next section | ||
on "build types", | ||
- Enabling ``-Werror`` in a portable manner is done via ``-Dwerror=true``, | ||
- Enabling warning levels is done via ``-Dwarning_level=<int>``, | ||
- There are many other builtin options, from activating Visual Studio (``-D--vsenv``) | ||
and building with link time optimization (``-Db_lto``) to changing the default | ||
C++ language level (``-Dcpp_std='c++17'``) or linker flags | ||
(``-Dcpp_link_args='-Wl,-z,defs'``). | ||
|
||
For a comprehensive overview of options, see `Meson's builtin options docs page | ||
<https://mesonbuild.com/Builtin-options.html>`__. | ||
|
||
Meson also supports the standard environment variables ``CFLAGS``, | ||
``CXXFLAGS``, ``FFLAGS`` and ``LDFLAGS`` to inject extra flags - with the same | ||
caveat as in the previous section about those environment variables being | ||
picked up only for a clean build and not an incremental build. | ||
|
||
|
||
Using different build types with Meson | ||
-------------------------------------- | ||
|
||
Meson provides different build types while configuring the project. You can see | ||
the available options for build types in | ||
`the "core options" section of the Meson documentation <https://mesonbuild.com/Builtin-options.html#core-options>`__. | ||
|
||
Assuming that you are building from scratch (do ``git clean -xdf`` if needed), | ||
you can configure the build as following to use the ``debug`` build type:: | ||
|
||
meson setup build --buildtype debug --prefix=$PWD/build-install | ||
|
||
Now, you can use the ``dev.py`` interface for further building, installing and | ||
testing SciPy:: | ||
|
||
python dev.py -s linalg | ||
|
||
This will work because after initial configuration, Meson will remember the | ||
config options. | ||
|
||
|
||
Use GCC and Clang builds in parallel | ||
------------------------------------ | ||
|
||
It may be useful to have several builds of SciPy in the same repo, for example | ||
to compare the differences between two compilers for diagnosing an issue. As | ||
discussed, Meson is fully out-of-place, so different builds will not interfere | ||
with each other. We assume in the rest of this section that GCC is the default. | ||
For example, let us build using GCC and Clang. | ||
|
||
1. Build with GCC:: | ||
|
||
python dev.py build | ||
|
||
Using the above command, meson will build with the (default) GCC compilers in | ||
the ``build`` directory, and install to the ``build-install`` directory. | ||
|
||
2. Build with Clang:: | ||
|
||
CC=clang CXX=clang++ FC=gfortran python dev.py --build-dir=build-clang build | ||
|
||
Using the above commands, Meson will build with the Clang, Clang++ and Gfortran | ||
compilers in the ``build-clang`` directory, and then install SciPy into | ||
``build-clang-install``. | ||
|
||
Meson will remember the compiler selection for the ``build-clang`` directory and | ||
it cannot be changed, so each future invocation of | ||
``python dev.py --build-dir=build-clang <command>`` it will automatically use Clang. | ||
|
||
Tip: use an alias to make this easier to use, e.g., | ||
``alias dev-clang="python dev.py --build-dir=build-clang"`` and then | ||
``dev-clang build``. | ||
|
||
A common reason to have two builds is to compare between them. For example, | ||
to run the ``scipy.linalg`` tests for builds with both compilers, do:: | ||
|
||
python dev.py -s linalg # run tests for the GCC build | ||
python dev.py --build-dir build-clang -s linalg # run tests for the Clang build | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
Cross compilation | ||
================= | ||
|
||
TODO | ||
Cross compilation is a complex topic, we only add some hopefully helpful hints | ||
here (for now). As of May 2023, cross-compilation based on ``crossenv`` is | ||
known to work, as used (for example) in conda-forge. Cross-compilation without | ||
``crossenv`` requires some manual overrides, as done in (for example) Void Linux. | ||
|
||
Please see `Meson's documentation on cross compilation | ||
<https://mesonbuild.com/Cross-compilation.html>`__ | ||
for details on Meson's support for cross-compilation. | ||
|
||
One common hiccup is that ``numpy`` and ``pythran`` require | ||
running Python code in order to obtain their include directories. This tends to | ||
not work well, either accidentally picking up the packages from the build | ||
(native) Python rather than the host (cross) Python or requiring ``crossenv`` | ||
or QEMU to run the host Python. To avoid this problem, specify the paths to the | ||
relevant directories in your *cross file*: | ||
|
||
.. code:: ini | ||
[constants] | ||
sitepkg = '/abspath/to/host-pythons/site-packages/' | ||
[properties] | ||
numpy-include-dir = sitepkg + 'numpy/core/include' | ||
pythran-include-dir = sitepkg + 'pythran' | ||
For more details and the current status around cross compilation, see: | ||
|
||
- Tracking issue for SciPy cross-compilation needs and issues: | ||
`scipy#14812 <https://github.com/scipy/scipy/issues/14812>`__ | ||
- The state of cross compilation in Python: | ||
`pypackaging-native key issue page <https://pypackaging-native.github.io/key-issues/cross_compilation/>`__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Meson and ``distutils`` ways of doing things | ||
-------------------------------------------- | ||
|
||
*Old workflows (numpy.distutils based):* | ||
|
||
1. ``python runtests.py`` | ||
2. ``python setup.py build_ext -i`` + ``export | ||
PYTHONPATH=/home/username/path/to/scipy/reporoot`` (and then edit pure | ||
Python code in SciPy and run it with ``python some_script.py``). | ||
3. ``python setup.py develop`` - this is similar to (2), except in-place build | ||
is made permanently visible in env. | ||
4. ``python setup.py bdist_wheel`` + ``pip install dist/scipy*.whl`` - build | ||
wheel in current env (i.e. uses installed numpy, etc.) and install it. | ||
5. ``pip install .`` - build wheel in an isolated build env against deps in | ||
``pyproject.toml`` and install it. *Note: be careful, this is usually not | ||
the correct command for development installs - typically you want to use (4) | ||
or* ``pip install . -v --no-build-isolation``. | ||
|
||
*New workflows (Meson and meson-python based):* | ||
|
||
1. ``python dev.py`` | ||
2. ``pip install -e . --no-build-isolation`` (see the ``meson-python`` docs) | ||
3. the same as (2) | ||
4. ``python -m build --no-isolation`` + ``pip install dist/scipy*.whl`` - see | ||
`pypa/build <https://pypa-build.readthedocs.io/en/latest/>`_. | ||
5. ``pip install .`` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.