Compiler selection and customizing a build#
Selecting a specific compiler#
Meson supports the standard environment variables
select specific C, C++ and/or Fortran compilers. These environment variables are
documented in the reference tables in the Meson docs.
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
clean -xdf and do a full rebuild, or run
meson setup --reconfigure.
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.
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
python dev.py -s linalg
This will work because after initial configuration, Meson will remember the config options.
Controlling build parallelism#
ninja will launch
2*n_cpu + 2, with
n_cpu the number of
physical CPU cores, parallel build jobs. This is fine in the vast majority of
cases, and results in close to optimal build times. In some cases, on machines
with a small amount of RAM relative to the number of CPU cores, this leads to a
job running out of memory. In case that happens, lower the number of jobs
such that you have at least 2 GB RAM per job. For example, to launch 6 jobs:
python -m pip install . -Ccompile-args="-j6"
python dev.py build -j6
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.
Build with GCC:
python dev.py build
Using the above command, meson will build with the (default) GCC compilers in
build directory, and install to the
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
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
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