Skip to content

Commit 01be49c

Browse files
author
Release Manager
committed
gh-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: #40485 Reported by: Michael Orlitzky Reviewer(s): Antonio Rojas, Dima Pasechnik, Michael Orlitzky, Tobias Diez
2 parents 38f4c2e + 3811277 commit 01be49c

File tree

10 files changed

+143
-25
lines changed

10 files changed

+143
-25
lines changed

meson.options

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,78 @@ option(
77
value: '',
88
description: 'Path to SAGE_LOCAL directory (only used for compatibility with the old Sage-the-Distro',
99
)
10+
11+
#
12+
# Boolean options
13+
#
14+
option(
15+
'build-docs',
16+
type: 'boolean',
17+
description: 'Build the HTML / PDF documentation'
18+
)
19+
20+
#
21+
# Features
22+
#
23+
option(
24+
'bliss',
25+
type: 'feature',
26+
value: 'auto',
27+
description: 'Bliss interface to graph isomorphisms'
28+
)
29+
30+
option(
31+
'brial',
32+
type: 'feature',
33+
value: 'auto',
34+
description: 'BRiAl interface to polynomials over boolean rings'
35+
)
36+
37+
option(
38+
'coxeter3',
39+
type: 'feature',
40+
value: 'auto',
41+
description: 'Coxeter 3.x interface to Coxeter groups'
42+
)
43+
44+
option(
45+
'eclib',
46+
type: 'feature',
47+
value: 'auto',
48+
description: 'eclib interface to mwrank and elliptic curves over Q'
49+
)
50+
51+
option(
52+
'mcqd',
53+
type: 'feature',
54+
value: 'auto',
55+
description: 'MCQD interface to the MaxCliqueDyn algorithm'
56+
)
57+
58+
option(
59+
'meataxe',
60+
type: 'feature',
61+
value: 'auto',
62+
description: 'MeatAxe interface to matrix representations over finite fields'
63+
)
64+
65+
option(
66+
'rankwidth',
67+
type: 'feature',
68+
value: 'auto',
69+
description: 'Interface to librw for rank-width decompositions'
70+
)
71+
72+
option(
73+
'sirocco',
74+
type: 'feature',
75+
value: 'auto',
76+
description: 'Sirocco interface to certified root continuation'
77+
)
78+
79+
option(
80+
'tdlib',
81+
type: 'feature',
82+
value: 'auto',
83+
description: 'Interface to tdlib for tree decompositions'
84+
)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@ host-requires = [
129129
"virtual:interface/blas",
130130
"virtual:compiler/fortran",
131131
"pkg:generic/boost",
132-
"pkg:generic/brial",
133132
"pkg:generic/cddlib",
134133
"pkg:generic/cliquer",
135134
"pkg:generic/ecl",
136-
"pkg:generic/eclib",
137135
"pkg:generic/ecm",
138136
"pkg:generic/fflas-ffpack",
139137
"pkg:generic/flint",
@@ -183,7 +181,9 @@ dependencies = [
183181
[external.optional-host-requires]
184182
extra = [
185183
"pkg:generic/bliss",
184+
"pkg:generic/brial",
186185
"pkg:generic/coxeter3",
186+
"pkg:generic/eclib",
187187
"pkg:generic/mcqd",
188188
"pkg:generic/meataxe",
189189
"pkg:generic/sirocco",

src/doc/en/installation/meson.rst

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,24 @@ To configure the project, we need to run the following command:
232232
233233
$ meson setup builddir
234234
235-
This will create a build directory ``builddir`` that will hold the build
236-
artifacts.
235+
This will create a build directory ``builddir`` that will hold the
236+
build artifacts. Certain options are configurable at build time. The
237+
easiest way to obtain an overview of these options is by using ``meson
238+
configure``:
239+
240+
.. code-block:: shell-session
241+
242+
$ meson configure builddir
243+
244+
This command should display the available options and their associated
245+
values. The section titled "Project options" contains the options that
246+
are unique to SageMath. To change the value of an option, the flag
247+
``-Doption=value`` can be passed to ``meson setup``. For example, if
248+
you don't want to build the HTML documentation, you might use
249+
250+
.. code-block:: shell-session
251+
252+
$ meson setup -Dbuild-docs=false builddir
237253
238254
If pip is used as above with ``--editable``, ``builddir`` is set to be
239255
``build/cp[Python major version][Python minor version]``, such as
@@ -298,6 +314,21 @@ Alternatively, we can still use pip to install:
298314
$ meson compile -C builddir
299315
$ DESTDIR=/path/to/staging/root meson install -C builddir
300316
317+
SageMath's automatic feature detection (based on the packages that
318+
happen to be installed at build time) can be disabled in favor of
319+
explicit configuration by passing ``-Dauto_features=disabled`` to
320+
``meson setup``. Afterwards, individual features must be enabled
321+
explicitly. You can obtain a list of valid feature names through
322+
``meson configure``.
323+
324+
By default, meson may fall back to bundled versions of certain
325+
subprojects known as `wrap dependencies
326+
<https://mesonbuild.com/Wrap-dependency-system-manual.html>`_.
327+
Maintainers will typically want to disable this behavior as well
328+
to ensure that the system dependencies are used. This can be
329+
achieved with the `--wrap-mode flag
330+
<https://mesonbuild.com/Subprojects.html#commandline-options>`_
331+
301332
With the `default <https://mesonbuild.com/Running-Meson.html#installing>`_ prefix
302333
being ``/usr/local``, it may then install to
303334
``$DESTDIR/usr/local/lib/python3.12/site-packages/sage``.

src/doc/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if not get_option('build-docs')
2+
subdir_done()
3+
endif
4+
15
sphinx_check = py_module.find_installation(required: false, modules: ['sphinx'])
26
if not sphinx_check.found()
37
warning(
@@ -6,6 +10,7 @@ if not sphinx_check.found()
610
subdir_done()
711
endif
812

13+
914
doc_src = []
1015
subdir('en/reference/repl')
1116
# TODO: Migrate this completely to meson

src/meson.build

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,18 @@ endif
151151
# Cannot be found via pkg-config
152152
mtx = cc.find_library(
153153
'mtx',
154-
required: false,
154+
required: get_option('meataxe'),
155155
disabler: true,
156156
has_headers: ['meataxe.h'],
157157
)
158158
png = dependency(['libpng', 'png', 'png16'], version: '>=1.2')
159159
zlib = dependency('zlib', version: '>=1.2.11')
160-
# We actually want >= 20231212, but the version number is not updated in the pkgconfig
161-
# https://github.com/conda-forge/eclib-feedstock/issues/48
162-
ec = dependency('eclib', version: '>=20231211', required: false, disabler: true)
163-
if not ec.found()
164-
ec = cc.find_library('ec', required: false, disabler: true)
165-
endif
160+
ec = dependency(
161+
'eclib',
162+
version: '>=20250122',
163+
required: get_option('eclib'),
164+
disabler: true,
165+
)
166166
ecm = cc.find_library('ecm', required: not is_windows, disabler: true)
167167
gmpxx = dependency('gmpxx', required: not is_windows, disabler: true)
168168
fflas = dependency(

src/sage/graphs/graph_decompositions/meson.build

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# tdlib is a header-only library
2-
if cc.has_header('treedec/combinations.hpp')
1+
tdlib = disabler()
2+
if cc.has_header('treedec/combinations.hpp', required: get_option('tdlib'))
3+
# tdlib is a header-only library
34
tdlib = declare_dependency()
4-
else
5-
tdlib = disabler()
65
endif
76
# Cannot be found via pkg-config
8-
rw = cc.find_library('rw', required: false, disabler: true)
7+
rw = cc.find_library('rw', required: get_option('rankwidth'), disabler: true)
98

109
py.install_sources(
1110
'__init__.py',

src/sage/graphs/meson.build

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
bliss = cc.find_library('bliss', required: false, disabler: true)
2-
# mcqd is a header-only library
3-
if cc.has_header('mcqd.h')
1+
bliss = cc.find_library('bliss', required: get_option('bliss'), disabler: true)
2+
3+
mcqd = disabler()
4+
if cc.has_header('mcqd.h', required: get_option('mcqd'))
5+
# mcqd is a header-only library
46
mcqd = declare_dependency()
5-
else
6-
mcqd = disabler()
77
endif
88
cliquer = cc.find_library('cliquer', required: not is_windows, disabler: true)
99

src/sage/libs/coxeter3/meson.build

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
coxeter3 = cc.find_library('coxeter3', required: false, disabler: true)
1+
coxeter3 = cc.find_library(
2+
'coxeter3',
3+
required: get_option('coxeter3'),
4+
disabler: true,
5+
)
26
py.install_sources(
37
'__init__.py',
48
'all__sagemath_coxeter3.py',

src/sage/libs/meson.build

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
sirocco = cc.find_library('sirocco', required: false, disabler: true)
1+
sirocco = cc.find_library(
2+
'sirocco',
3+
required: get_option('sirocco'),
4+
disabler: true,
5+
)
26
# cannot be found via pkg-config
37
ecl = cc.find_library('ecl', required: false, disabler: true)
48
if not ecl.found() and not is_windows

src/sage/rings/polynomial/pbori/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
brial = cc.find_library('brial', required: false, disabler: true)
1+
brial = cc.find_library('brial', required: get_option('brial'), disabler: true)
22
# Cannot be found via pkg-config
33
brial_groebner = cc.find_library(
44
'brial_groebner',
5-
required: false,
5+
required: get_option('brial'),
66
disabler: true,
77
)
88

0 commit comments

Comments
 (0)