Skip to content

Conversation

@orlitzky
Copy link
Contributor

@orlitzky orlitzky commented Jul 27, 2025

As discussed in various places over the past two years, it is useful to be able to override the automagic detection of libraries to explicitly enable or disable a feature. This commit adds meson.options at the top level to do that, and to make the documentation optional as well.

Example:

$ meson setup -Dsirocco=disabled

will disable the cython module sage.libs.sirocco, even if I have sirocco installed. This is nice for a few reasons:

  • If you are building from source (or using a source-based distro), this is the only way to achieve accurate dependency information.
  • Now that we are adding meson subprojects, there is again a risk of vendoring libraries that you already have installed if (say) its pkg-config check is flaky. Specifying -Dfoo=enabled makes that an error rather than quietly doing the wrong thing.
  • It makes it possible to easily test the # needs whatever tags on non-Windows systems (i.e. to test that the things we say are optional are really optional).
  • On a system where the corresponding libraries happen to be installed, you can speed up the build by disabling the features you aren't currently working on or using.

And of course, the defaults are all "auto," and should not change anything for anyone else.

I was finally motivated to do this because the doc build fails on my machine, and otherwise I have to edit out the line in src/meson.build and be careful not to commit it to all of my PRs. This implementation is the first thing I came up with after a few minutes of reading the docs, but it works surprisingly well.

@dimpase
Copy link
Member

dimpase commented Jul 27, 2025

@tobiasdiez - looks good to me.

Copy link
Contributor

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly see that these options can be helpful in certain situations, and the maintenance overhead is quite small. So I'm fine with going forward with this PR.

If you feel like it, you can also add a bit of documentation on how to toggle those features. Should be enough to point to meson introspect --buildoptions for the full list of options (https://mesonbuild.com/Commands.html#introspect).

The CI is failing due to some small formatting issues.

Two small remarks:

If you are building from source (or using a source-based distro), this is the only way to achieve accurate dependency information.

Not sure if I understand this comment correctly, but the dependency info can be found in builddir\meson-info\intro-dependencies.json and in meson-logs.

Now that we are adding meson subprojects, there is again a risk of vendoring libraries that you already have installed if (say) its pkg-config check is flaky. Specifying -Dfoo=enabled makes that an error rather than quietly doing the wrong thing.

In this case, it's better to use --wrap-mode (https://mesonbuild.com/Subprojects.html#commandline-options) to skip all submodules.

@kiwifb
Copy link
Member

kiwifb commented Jul 27, 2025

We had those discussion before in other threads/foras. It would be best if stuff like sirocco was just split like giac is. That part is a slight regression in the meson build compared to the previous state. A growing pain no doubt.
But as a general rule for package maintainers, automagic detection is evil and prevents you from figuring why stuff succeeds on one machine and fails on another. Controlling it has my vote.
In other news I will start to be more active again. Hopefully it will last.

@orlitzky
Copy link
Contributor Author

If you feel like it, you can also add a bit of documentation on how to toggle those features. Should be enough to point to meson introspect --buildoptions for the full list of options (https://mesonbuild.com/Commands.html#introspect).

Done, but with with meson configure instead since it looks a lot nicer.

If you are building from source (or using a source-based distro), this is the only way to achieve accurate dependency information.

Not sure if I understand this comment correctly, but the dependency info can be found in builddir\meson-info\intro-dependencies.json and in meson-logs.

That will give you the dependency info after the fact, but it may not be what you wanted to achieve. Essentially we want users to be able to say e.g. "build me a sage that doesn't need sirocco," and then we want our distro package to know that sirocco is not a dependency of sage from that point on. With explicit config this is pretty easy to do, we just take the user's enabled/disabled flag for the sirocco feature, and then pass it to the sage build system. This guarantees that sagelib is built with/without sirocco according to the user's wishes, and that we know ahead of time whether or not the result will depend on sirocco, so that we can pull it in as a dependency and record it in the package manager's database iff we need to do that.

Now that we are adding meson subprojects, there is again a risk of vendoring libraries that you already have installed if (say) its pkg-config check is flaky. Specifying -Dfoo=enabled makes that an error rather than quietly doing the wrong thing.

In this case, it's better to use --wrap-mode (https://mesonbuild.com/Subprojects.html#commandline-options) to skip all submodules.

Fair enough, I added that locally.

@orlitzky
Copy link
Contributor Author

We had those discussion before in other threads/foras. It would be best if stuff like sirocco was just split like giac is. That part is a slight regression in the meson build compared to the previous state.

I personally agree but each of those will require a few days of work to split off cleanly. Until then this PR will prevent things from regressing too badly when the setuptools packages are removed.

Copy link
Contributor

@antonio-rojas antonio-rojas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine here, tested no configuration (everything is built) and disabling a couple of modules while still keeping the dependencies installed.

Copy link
Member

@dimpase dimpase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about mentioning --wrap-mode=... in the docs?

@orlitzky
Copy link
Contributor Author

how about mentioning --wrap-mode=... in the docs?

done

@tobiasdiez
Copy link
Contributor

CI is still falling. Could you please run the update meson script locally and commit it?

@orlitzky
Copy link
Contributor Author

Sure, it's only complaining about whitespace but that should fix it.

Copy link
Contributor

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then let's get this in!

@vincentmacri
Copy link
Member

Out of curiosity, does this provide a way to change the compilation flags passed to cythonize/gcc/etc. when building Sage? If not, would it be possible to expand upon this in a future PR to add that?

@orlitzky
Copy link
Contributor Author

orlitzky commented Aug 2, 2025

Out of curiosity, does this provide a way to change the compilation flags passed to cythonize/gcc/etc. when building Sage? If not, would it be possible to expand upon this in a future PR to add that?

This should already be possible. Meson supports the standard environment variables like CFLAGS, and has invented(?) others like CYTHONFLAGS:

I don't use CYTHONFLAGS, but can confirm that my CFLAGS and LDFLAGS are used during the build.

Make it possible to disable the documentation build by passing,

  $ meson setup -Dbuild-docs=false

Otherwise, the documentation will be built by default, as usual.
Several libraries are detected at setup time, and the corresponding
feature is enabled or disabled based on the library's presence. This
commit retains this behavior by default while making it possible to
explicitly enable or disable the feature via,

  $ meson setup -Dfoo=disabled

or

  $ meson setup -Dfoo=enabled

The former disables the feature even if the library is installed, and the
latter makes it an error if the library is not installed.

The list of features (valid values for foo) is,

  * bliss
  * brial
  * coxeter3
  * mcqd
  * meataxe
  * rankwidth
  * sirocco
  * tdlib
Add examples of explicit configuration using the "-Doption=value"
syntax, and mention the auto_features option for package maintainers.
Mention how to disabled wrapped subprojects in the tips for package
maintainers section.
@github-actions
Copy link

github-actions bot commented Aug 4, 2025

Documentation preview for this PR (built with commit 3811277; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@orlitzky
Copy link
Contributor Author

orlitzky commented Aug 4, 2025

It looks like eclib is optional now, so I'll add a flag for that too.

@tobiasdiez
Copy link
Contributor

That was actually not a very conscious change on my side, but it's probably a good idea to have it optional indeed. Could you please move eclib also to the optional dependencies in 'pyproject.toml' and perhaps check that there are disable flags for exactly all optional deps listed there. (I can also do this after my conference...)

It is now possible to build sagelib without these libraries; the
corresponding extensions are automatically disabled by meson.
I believe this is required anyway after commit eaef4ae, and
regardless is nice to have because it guarantees that we'll have a
pkg-config file and can skip the no-pkgconfig fallback.
Add an entry to meson.options (and tweak src/meson.build) so that
the user can explicitly state whether or not he would like eclib
support to be enabled, e.g.

  $ meson setup -Declib=disabled

The default of "auto" is backwards-compatible.
@orlitzky
Copy link
Contributor Author

orlitzky commented Aug 4, 2025

  • Moved eclib and brial to optional-host-requires in pyproject.toml
  • Bumped the version bound on eclib (I'm almost certain this is required anyway) so that we can rely on pkg-config
  • Added the explicit option for eclib

@orlitzky
Copy link
Contributor Author

orlitzky commented Aug 4, 2025

(The list of feature flags does now match the list of optional deps.)

@antonio-rojas
Copy link
Contributor

The meataxe description doesn't seem accurate, Sage doesn't use any of the meataxe programs, but rather its multiplication tables (via the libmtx library) to optimize matrix operations over finite fields

@orlitzky
Copy link
Contributor Author

orlitzky commented Aug 4, 2025

The meataxe description doesn't seem accurate, Sage doesn't use any of the meataxe programs, but rather its multiplication tables (via the libmtx library) to optimize matrix operations over finite fields

Better now?

I tried to word them all in a way that avoids "description rot" if the implementation details change, but I don't know meataxe very well and wound up on a webpage that wasn't much help the first time around.

@dimpase
Copy link
Member

dimpase commented Aug 5, 2025

is meataxe really used anywhere apart from defunct p-group cohomology package?

@antonio-rojas
Copy link
Contributor

is meataxe really used anywhere apart from defunct p-group cohomology package?

yes, https://github.com/sagemath/sage/blob/develop/src/sage/matrix/matrix_gfpn_dense.pyx

@dimpase
Copy link
Member

dimpase commented Aug 5, 2025

Yes, that's a Cython module split out from the now defunct package by Simon King, when he worked on refactoring his package, something that hasn't been completed.

@antonio-rojas
Copy link
Contributor

Yes, that's a Cython module split out from the now defunct package by Simon King, when he worked on refactoring his package, something that hasn't been completed.

which is used by default if present as parent for matrices over fields of small order

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 10, 2025
sagemathgh-40485: meson: explicitly configurable options
    
As discussed in various places over the past two years, it is useful to
be able to override the automagic detection of libraries to explicitly
enable or disable a feature. This commit adds `meson.options` at the top
level to do that, and to make the documentation optional as well.

Example:

```
$ meson setup -Dsirocco=disabled
```

will disable the cython module `sage.libs.sirocco`, even if I have
sirocco installed. This is nice for a few reasons:

* If you are building from source (or using a source-based distro), this
is the only way to achieve accurate dependency information.
* Now that we are adding meson subprojects, there is again a risk of
vendoring libraries that you already have installed if (say) its pkg-
config check is flaky. Specifying `-Dfoo=enabled` makes that an error
rather than quietly doing the wrong thing.
* It makes it possible to easily test the `# needs whatever` tags on
non-Windows systems (i.e. to test that the things we say are optional
are really optional).
* On a system where the corresponding libraries happen to be installed,
you can speed up the build by disabling the features you aren't
currently working on or using.

And of course, the defaults are all "auto," and should not change
anything for anyone else.

I was finally motivated to do this because the doc build fails on my
machine, and otherwise I have to edit out the line in `src/meson.build`
and be careful not to commit it to all of my PRs. This implementation is
the first thing I came up with after a few minutes of reading the docs,
but it works surprisingly well.
    
URL: sagemath#40485
Reported by: Michael Orlitzky
Reviewer(s): Antonio Rojas, Dima Pasechnik, Michael Orlitzky, Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 12, 2025
sagemathgh-40485: meson: explicitly configurable options
    
As discussed in various places over the past two years, it is useful to
be able to override the automagic detection of libraries to explicitly
enable or disable a feature. This commit adds `meson.options` at the top
level to do that, and to make the documentation optional as well.

Example:

```
$ meson setup -Dsirocco=disabled
```

will disable the cython module `sage.libs.sirocco`, even if I have
sirocco installed. This is nice for a few reasons:

* If you are building from source (or using a source-based distro), this
is the only way to achieve accurate dependency information.
* Now that we are adding meson subprojects, there is again a risk of
vendoring libraries that you already have installed if (say) its pkg-
config check is flaky. Specifying `-Dfoo=enabled` makes that an error
rather than quietly doing the wrong thing.
* It makes it possible to easily test the `# needs whatever` tags on
non-Windows systems (i.e. to test that the things we say are optional
are really optional).
* On a system where the corresponding libraries happen to be installed,
you can speed up the build by disabling the features you aren't
currently working on or using.

And of course, the defaults are all "auto," and should not change
anything for anyone else.

I was finally motivated to do this because the doc build fails on my
machine, and otherwise I have to edit out the line in `src/meson.build`
and be careful not to commit it to all of my PRs. This implementation is
the first thing I came up with after a few minutes of reading the docs,
but it works surprisingly well.
    
URL: sagemath#40485
Reported by: Michael Orlitzky
Reviewer(s): Antonio Rojas, Dima Pasechnik, Michael Orlitzky, Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 13, 2025
sagemathgh-40485: meson: explicitly configurable options
    
As discussed in various places over the past two years, it is useful to
be able to override the automagic detection of libraries to explicitly
enable or disable a feature. This commit adds `meson.options` at the top
level to do that, and to make the documentation optional as well.

Example:

```
$ meson setup -Dsirocco=disabled
```

will disable the cython module `sage.libs.sirocco`, even if I have
sirocco installed. This is nice for a few reasons:

* If you are building from source (or using a source-based distro), this
is the only way to achieve accurate dependency information.
* Now that we are adding meson subprojects, there is again a risk of
vendoring libraries that you already have installed if (say) its pkg-
config check is flaky. Specifying `-Dfoo=enabled` makes that an error
rather than quietly doing the wrong thing.
* It makes it possible to easily test the `# needs whatever` tags on
non-Windows systems (i.e. to test that the things we say are optional
are really optional).
* On a system where the corresponding libraries happen to be installed,
you can speed up the build by disabling the features you aren't
currently working on or using.

And of course, the defaults are all "auto," and should not change
anything for anyone else.

I was finally motivated to do this because the doc build fails on my
machine, and otherwise I have to edit out the line in `src/meson.build`
and be careful not to commit it to all of my PRs. This implementation is
the first thing I came up with after a few minutes of reading the docs,
but it works surprisingly well.
    
URL: sagemath#40485
Reported by: Michael Orlitzky
Reviewer(s): Antonio Rojas, Dima Pasechnik, Michael Orlitzky, Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 14, 2025
sagemathgh-40485: meson: explicitly configurable options
    
As discussed in various places over the past two years, it is useful to
be able to override the automagic detection of libraries to explicitly
enable or disable a feature. This commit adds `meson.options` at the top
level to do that, and to make the documentation optional as well.

Example:

```
$ meson setup -Dsirocco=disabled
```

will disable the cython module `sage.libs.sirocco`, even if I have
sirocco installed. This is nice for a few reasons:

* If you are building from source (or using a source-based distro), this
is the only way to achieve accurate dependency information.
* Now that we are adding meson subprojects, there is again a risk of
vendoring libraries that you already have installed if (say) its pkg-
config check is flaky. Specifying `-Dfoo=enabled` makes that an error
rather than quietly doing the wrong thing.
* It makes it possible to easily test the `# needs whatever` tags on
non-Windows systems (i.e. to test that the things we say are optional
are really optional).
* On a system where the corresponding libraries happen to be installed,
you can speed up the build by disabling the features you aren't
currently working on or using.

And of course, the defaults are all "auto," and should not change
anything for anyone else.

I was finally motivated to do this because the doc build fails on my
machine, and otherwise I have to edit out the line in `src/meson.build`
and be careful not to commit it to all of my PRs. This implementation is
the first thing I came up with after a few minutes of reading the docs,
but it works surprisingly well.
    
URL: sagemath#40485
Reported by: Michael Orlitzky
Reviewer(s): Antonio Rojas, Dima Pasechnik, Michael Orlitzky, Tobias Diez
@vbraun vbraun merged commit 01be49c into sagemath:develop Aug 16, 2025
25 of 27 checks passed
@dimpase
Copy link
Member

dimpase commented Aug 18, 2025

are there meson options allowing to control tools discovery things, e.g. getting pybind11 and cython from a prescribed location, rather than getting whatever found in /usr/bin etc?

@orlitzky
Copy link
Contributor Author

are there meson options allowing to control tools discovery things, e.g. getting pybind11 and cython from a prescribed location, rather than getting whatever found in /usr/bin etc?

For cython, PATH should work. When building extension modules, meson will use whatever python knows about, so you could probably prepend to PYTHONPATH for something like pybind11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants