-
Notifications
You must be signed in to change notification settings - Fork 5
BLD: Scipy meson build with Nix #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: meson
Are you sure you want to change the base?
Changes from all commits
935cac9
6b64b1a
d66b4d1
ff22204
774678c
233dd6d
c7764cc
9327151
e3f0c8a
c85eeeb
a9a0a7d
5ac8068
8196247
4f79bc2
45f8bb9
ac81b32
2229cf8
239e715
290d276
42ee4ea
88761c8
45a4711
2357405
858883d
fefa2f7
e81ce3b
a570b05
c671e29
83555af
07c1ae2
c53b21a
c6bd240
2a7d7d2
2ccc314
a3468e1
4c24656
1af5aee
9c4c4c5
9ea21cd
1ecef03
41fc827
82d87a9
634ed3d
a613031
170be29
aec9315
a87aa65
025f623
5df21d7
e4853df
3f81869
8dc66c4
9f80400
166dab9
2f6c98e
a81a78f
2d283c4
3e919c3
e26a6f6
938201e
5a7fda0
0eeb7be
b800a47
f9068dc
c333ecd
d12339b
5f75eca
1113490
a2612f5
ee1c7f4
1a86fbd
1c0a60d
4d995f0
e11fdfe
023c094
cafb205
b9b1c03
d58cd27
8f0f64f
91f5130
5c2b460
cc4ad2a
f678f9f
f49b751
e9bd92f
5d113b6
850237e
3b1bac2
7ce2735
acaacc4
7023681
f258c2f
398e5ea
0339a29
4ca8361
8d36d59
93fac07
461f198
c01a250
81fa9f9
9c468b6
4f67ed1
dc67517
88e2cf2
c832499
aea08e3
8ccb825
6f1a00b
91dfca2
163a9ca
ba50657
fb085dc
3cd0e11
8dbfb68
65c3d92
f55693a
824d182
4ddf44e
81b1a04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # How to build SciPy with Meson | ||
|
|
||
| _note: these instructions are for Linux, if you are on another OS things likely | ||
| don't work yet! macOS support should be easy, please comment if we need to | ||
| prioritize adding that._ | ||
|
|
||
| ## quickstart from scratch | ||
|
|
||
| Clone the repo and check out the right branch: | ||
|
|
||
| ```bash | ||
| git clone [email protected]:rgommers/scipy.git | ||
| git submodule update --init | ||
| git checkout meson | ||
| ``` | ||
|
|
||
| Create a conda development environment, build SciPy with Meson and run the test | ||
| suite: | ||
|
|
||
| ``` | ||
| conda env create -f environment.yml | ||
| conda activate scipy-dev | ||
| python -m pip install git+https://github.com/rgommers/meson.git@scipy | ||
| ./mesondev.sh build --prefix=$PWD/install | ||
| ``` | ||
|
|
||
| ## Full details and explanation | ||
|
|
||
| Now to build SciPy, we need the `meson` branch from `@rgommers`'s fork (this is | ||
| the integration branch until Meson support is merged into SciPy master): | ||
| ```bash | ||
| git clone [email protected]:rgommers/scipy.git | ||
| git submodule update --init | ||
| git checkout meson | ||
| ``` | ||
|
|
||
| We will use conda here, because it's the easiest way to get a fully | ||
| reproducible environment. If you do not have a conda environment yet, the | ||
| recommended installer is | ||
| [Mambaforge](https://github.com/conda-forge/miniforge#mambaforge) (`mamba` is | ||
| basically a much faster `conda`). | ||
|
|
||
| To create a development environment: | ||
| ```bash | ||
| conda env create -f environment.yml # `mamba` works too for this command | ||
| conda activate scipy-dev | ||
| ``` | ||
|
|
||
| The one dependency that we now miss is `meson`. Support for Cython in Meson is | ||
| very new, and we expect to also need some bug fixes and new features in the | ||
| Meson master branch as well as fixes we may not even have submitted yet or are | ||
| pending review. So install Meson from the `scipy` branch of `@rgommers`'s fork: | ||
| ```bash | ||
| python -m pip install git+https://github.com/rgommers/meson.git@scipy | ||
| ``` | ||
|
|
||
| Meson uses a configure and a build stage. To configure it for putting the build | ||
| artifacts in `build/` and a local install under `installdir/` and then build: | ||
| ```bash | ||
| meson setup build --prefix=$PWD/installdir | ||
| ninja -C build | ||
| ``` | ||
| In the command above, `-C` is followed by the name of the build directory. You | ||
| can have multiple builds at the same time. Meson is fully out-of-place, so | ||
| those builds will not interfere with each other. You can for example have a GCC | ||
| build, a Clang build and a debug build in different directories. | ||
|
|
||
| To then install SciPy into the prefix (`installdir/` here): | ||
| ```bash | ||
| meson install -C build | ||
| ``` | ||
| It will then install to `installdir/lib/python3.9/site-packages/scipy`, which | ||
| is not on your Python path, so to add it do: | ||
| ```bash | ||
| export PYTHONPATH=$PWD/installdir/lib/python3.9/site-packages/ | ||
| ``` | ||
|
|
||
| Now we should be able to import `scipy` and run the tests. Remembering that we | ||
| need to move out of the root of the repo to ensure we pick up the package and | ||
| not the local `scipy/` source directory: | ||
| ```bash | ||
| cd doc | ||
| python -c "from scipy import constants as s; s.test()" | ||
| ``` | ||
| The above runs the tests for a single module, `constants`. Other ways of | ||
| running the tests should also work, for example: | ||
| ```bash | ||
| pytest scipy | ||
| ``` | ||
|
|
||
| Current status (24 July) is that the full test suite passes on Linux with | ||
| OpenBLAS. And there is CI on this fork to keep it that way. Other platforms are | ||
| not tested yet. The current status is already good enough to | ||
| work on both build related issues (e.g. build warnings, debugging some C/C++ | ||
| extension) and on general SciPy development. It is already a much smoother than | ||
| working with the default `distutils`-based build one gets with | ||
| `python setup.py develop`. | ||
|
|
||
| The above configure-build-install-test docs are useful to understand and for | ||
| working on build improvements (you don't need to install for that to, for | ||
| example, see the build succeeds and a build warning has disappeared); if you | ||
| want the "all-in-one" command for the above, run: | ||
| ```bash | ||
| ./mesondev.sh build --prefix=$PWD/installdir | ||
| ``` | ||
|
|
||
| It's worth pointing out that Meson has [very good documentation](https://mesonbuild.com/); | ||
| it's worth reading and is often the best source of answers for "how to do X". | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # File is taken from nixos/nixpkgs and adapted. | ||
|
|
||
| { lib | ||
| , fetchFromGitHub | ||
| , python | ||
| , buildPythonPackage | ||
| , gfortran | ||
| , nose | ||
| # Use a hook that implements the checkPhase calling pytest | ||
| # instead of us calling pytest directly. | ||
| , pytestCheckHook | ||
| , pytest-xdist | ||
| , numpy | ||
| , pybind11 | ||
| , cython | ||
| , meson | ||
| , ninja | ||
| , pythran | ||
| , pkg-config | ||
| , boost175 | ||
| }: | ||
|
|
||
| let | ||
|
|
||
| excludeIndices = list: indices: let | ||
| nitems = lib.length list; | ||
| includeIndices = lib.subtractLists indices (lib.range 0 (nitems - 1)); | ||
| in map (idx: lib.elemAt list idx) includeIndices; | ||
|
|
||
| meson_ = meson.overrideAttrs (oldAttrs: rec { | ||
| version = "0.59.0.rc2"; | ||
| src = fetchFromGitHub { | ||
| owner = "rgommers"; | ||
| repo = "meson"; | ||
| rev = "087870a2f15b31c56c4dc830ae856c3729f60776"; | ||
| sha256 = "sha256-7HJjxVnryaBkRDiwMHVkOo6mahfjrGAf1JijBIZ7Ay4="; | ||
| }; | ||
| patches = excludeIndices oldAttrs.patches [ 2 ]; # remove gir fallback path patch | ||
| }); | ||
|
|
||
| in buildPythonPackage rec { | ||
| pname = "scipy"; | ||
| version = "dev"; | ||
| format = "other"; | ||
|
|
||
| src = ./.; | ||
|
|
||
| checkInputs = [ pytestCheckHook pytest-xdist ]; | ||
| nativeBuildInputs = [ cython gfortran meson_ ninja pythran pkg-config ]; | ||
| buildInputs = [ numpy.blas pybind11 boost175 ]; | ||
| propagatedBuildInputs = [ numpy ]; | ||
|
|
||
| # Remove tests because of broken wrapper | ||
| prePatch = '' | ||
| rm scipy/linalg/tests/test_lapack.py | ||
| ''; | ||
|
|
||
| doCheck = true; | ||
|
|
||
| preBuild = '' | ||
| ln -s ${numpy.cfg} site.cfg | ||
| ''; | ||
|
|
||
| passthru = { | ||
| blas = numpy.blas; | ||
| meson = meson_; | ||
| }; | ||
|
|
||
| preCheck = '' | ||
| pushd $out/${python.sitePackages} | ||
| export PYTHONPATH=$out/${python.sitePackages}:$PYTHONPATH | ||
| ''; | ||
|
|
||
| postCheck = '' | ||
| popd | ||
| ''; | ||
|
|
||
| SCIPY_USE_G77_ABI_WRAPPER = 1; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still being picked up?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet, but it will be later, or I'll replace it with a properly documented Meson option. So far I've been focusing on getting everything to build with just Linux + OpenBLAS, so haven't needed the configurability yet. |
||
|
|
||
| meta = with lib; { | ||
| description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering"; | ||
| homepage = "https://www.scipy.org/"; | ||
| license = licenses.bsd3; | ||
| maintainers = [ maintainers.fridh ]; | ||
| }; | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the site.cfg still being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just using
dependency('openblas')which makes Meson usepkg-config. Again, may have to add back a user-configurable option later.