summaryrefslogtreecommitdiff
path: root/building_with_meson.md
blob: 25949899869a719958696650fa379eb1d3c442a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Building with Meson

_Note: this is for early adopters. It has been tested on Linux and macOS, and
with Python 3.9-3.12. Windows will be tested soon. There is one CI job to keep
the build stable. This may have rough edges, please open an issue if you run
into a problem._

### Developer build

**Install build tools:** Use one of:

- `mamba env create -f environment.yml && mamba activate numpy-dev

- `python -m pip install -r build_requirements.txt
  # also make sure you have pkg-config and the usual system dependencies for
  # NumPy`

Then install spin:
- `python -m pip install spin`

**Compile and install:** `spin build`

This builds in the `build/` directory, and installs into the `build-install` directory.

Then run the test suite or a shell via `spin`:
```
spin test
spin ipython
```

Alternatively, to use the package, add it to your `PYTHONPATH`:
```
export PYTHONPATH=${PWD}/build/lib64/python3.10/site-packages  # may vary
pytest --pyargs numpy
```


### pip install

Note that `pip` will use the default build system, which is (as of now) still
`numpy.distutils`. In order to switch that default to Meson, uncomment the
`build-backend = "mesonpy"` line at the top of `pyproject.toml`.

After that is done, `pip install .` or `pip install --no-build-isolation .`
will work as expected. As does building an sdist or wheel with `python -m build`.
Note, however, that `pip install -e .` (in-place developer install) does not!
Use `spin` instead (see above).



### Workaround for a hiccup on Fedora

- Fedora does not distribute `openblas.pc`. Install the following file in `~/lib/pkgconfig/openblas.pc`:

```
prefix=/usr
includedir=${prefix}/include
libdir=${prefix}/lib64

Name: openblas
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
Version: 0.3.19
Cflags: -I${includedir}/openblas
Libs: -L${libdir} -lopenblas
```

Then build with:

```
spin build -- -Dpkg_config_path=${HOME}/lib/pkgconfig
```