Dear developers,
I am excited to announce that SageMath now supports the Meson build system! This modern alternative to Autotools brings several key advantages:
To build SageMath with Meson, install the required dependencies (either using your system package manager or conda), then use:
`pip install --no-build-isolation --editable .`Start Sage with `./sage` and run tests using `./sage -t`, as usually.
For more details, check out the SageMath Meson Guide.
Thanks for your interest, William!
The Meson project for Sage began in October 2023 (PR #36524), and most of the work was wrapped up a couple of months ago. I just wanted to iron out a few remaining annoyances before officially announcing it on the mailing list.
My original motivation was to enable native builds of Sage on Windows. Moreover, I had grown increasingly frustrated with constant build issues in sage-the-distribution. Around the same time, many other projects in the ecosystem, like NumPy/SciPy and flint-python, had started migrating to Meson as well, which reinforced the idea.
The majority of the work and PRs came from my side, but I’m very grateful for the interest and support from the community — especially those who reviewed, tested, or otherwise contributed. A big thank you to Dima, Michael, Gonzalo, Antonio, and “user202729” in particular!
As Dima mentioned, currently only sagelib has been migrated. It can now be built completely independently of any autotools/configure/bootstrap scripts.
Regarding dependencies, there are a few strategies:
a) Require dependencies to be installed externally (e.g., via a system package manager or Conda).
b) Make non-essential dependencies optional — if not present, Meson simply skips building the corresponding Cython modules, in a fine-grained way.
c) Use Meson’s subproject feature to automatically build missing dependencies. Ideally, this involves writing a Meson build system for the subproject, but sometimes an upstream CMake or Autotools build system can be reused.
Currently, we’ve mostly implemented strategy (a). For this reason, I recommend installing dependencies via Conda or using a Linux distro that ships recent-enough versions, like Arch or Gentoo.
For Windows support, I used a combination of (b) and (c) as well, since some dependencies can’t be built on Windows at all or aren’t yet available via Conda. For example, I wrote a Meson build script for Singular, and reused the upstream CMake build for Flint.
I’m curious to hear what others think would be a good approach when a required dependency isn’t available on the system — especially in the context of portability and developer experience.