@@ -9,106 +9,177 @@ This is a short guide on how to build the Sage from source using Meson.
9
9
Walkthrough
10
10
===========
11
11
12
- Assume we're starting from a clean repo and a fully set up conda environment
13
- (modify ``-linux `` according to your operating system):
14
-
15
- .. tab :: Linux
12
+ .. note ::
16
13
17
- .. code-block :: shell
14
+ If you have previously build Sage in-place, you first have to delete the
15
+ already compiled files, e.g. with ``shopt -s globstar `` followed by
16
+ ``rm src/**/*.so `` or ``for f in src/**/*.so ; do mv "$f" "$f.old"; done ``.
17
+ Moreover, remove the old generated files with
18
+ ``find src/sage/ext/interpreters -type f ! -name 'meson.build' -delete ``.
19
+ Also uninstall the 'old' sage packages with ``pip uninstall sage-conf sage-setup sagemath-standard ``.
20
+
21
+ Sage relies on a number of external libraries, which have to be installed
22
+ before building. The easiest way to install them is to use Conda.
23
+ Alternatively, you can install them via your system package manager.
24
+ Both methods are described below.
25
+
26
+ Using Conda
27
+ ~~~~~~~~~~~
28
+
29
+ - If you haven't already, download and install Miniforge for your platform
30
+ following the `Miniforge instructions <https://github.com/conda-forge/miniforge?tab=readme-ov-file#install >`_.
31
+ Other Conda distributions like Miniconda should work as well, but
32
+ may require additional configuration (see :ref: `sec-installation-conda `).
33
+
34
+ - Create and activate a new conda environment with the dependencies of Sage
35
+ and a few additional developer tools:
36
+
37
+ .. tab :: Linux
38
+
39
+ .. code-block :: shell
40
+
41
+ $ mamba env create --file environment-3.12-linux.yml --name sage-dev
42
+ $ mamba activate sage-dev
43
+
44
+ .. tab :: macOS
45
+
46
+ .. code-block :: shell
47
+
48
+ $ mamba env create --file environment-3.12-macos.yml --name sage-dev
49
+ $ mamba activate sage-dev
50
+
51
+ .. tab :: Windows
52
+
53
+ .. note ::
54
+
55
+ Windows support is very experimental and many features are not working
56
+ yet.
57
+
58
+ First you need to install the Microsoft Visual C++ compiler.
59
+ You can download the
60
+ `Visual Studio Build Tools <https://aka.ms/vs/17/release/vs_BuildTools.exe >`_.
61
+ Make sure to select "VC++ 2022 version xx.x build tools" and "Windows SDK".
62
+ If you prefer, you can also run the following command to install the necessary
63
+ components:
64
+
65
+ .. code-block :: shell
66
+
67
+ $ winget install Microsoft.VisualStudio.2022.BuildTools --force --override " --wait --passive --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621"
68
+
69
+ Alternatively, you can use the compiler that comes bundled with Visual Studio.
70
+
71
+ If you haven't already, install the latest version of Conda from
72
+ `Miniforge <https://github.com/conda-forge/miniforge?tab=readme-ov-file#windows >`_.
73
+ It is strongly recommended to choose the option to add Conda to the `PATH `
74
+ during installation (because we will not use the Miniforge prompt).
75
+
76
+ Open the "VS x64 Native Tools Command Prompt" (for 64bit) or
77
+ "Developer Command Prompt for VS2022 (or 2019)" (for 32bit).
78
+
79
+ .. code-block :: shell
18
80
19
- $ mamba env create --file environment-3.11-linux.yml --name sage-dev
20
- $ mamba activate sage-dev
81
+ $ mamba env create --file environment-3.12-win.yml --name sage-dev
82
+ $ conda activate sage-dev
83
+ $ set LIB=%CONDA_PREFIX%\L ibrary\l ib; %LIB%
84
+ $ set INCLUDE=%CONDA_PREFIX%\L ibrary\i nclude; %INCLUDE%
21
85
22
- .. tab :: macOS
23
-
24
- .. code-block :: shell
86
+ Windows support is experimental and not fully working yet.
87
+ In fact, the Sage prompt is not working at all, but you can use the Python
88
+ prompt to run certain commands. For example, the following should work
89
+ after building Sage:
25
90
26
- $ mamba env create --file environment-3.11-macos.yml --name sage-dev
27
- $ mamba activate sage-dev
91
+ .. code-block :: python
28
92
29
- .. tab :: Windows
30
-
31
- .. note ::
93
+ >> > from sage.rings.integer import Integer
94
+ >> > Integer(5 )
95
+ 5
96
+ >> > Integer(5 ) + 2.0
97
+ 7.0
32
98
33
- Windows support is very experimental and many features are not working
34
- yet .
99
+ A different Python version can be selected by replacing `` 3.12 `` with the
100
+ desired version .
35
101
36
- First you need to install the Microsoft Visual C++ compiler.
37
- You can download the
38
- `Visual Studio Build Tools <https://aka.ms/vs/17/release/vs_BuildTools.exe >`_.
39
- Make sure to select "VC++ 2022 version xx.x build tools" and "Windows SDK".
40
- If you prefer, you can also run the following command to install the necessary
41
- components:
42
-
43
- .. code-block :: shell
102
+ - To compile and install Sage in editable install, just use:
103
+ .. code-block :: shell-session
44
104
45
- $ winget install Microsoft.VisualStudio.2022.BuildTools --force --override " --wait --passive --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621"
46
-
47
- Alternatively, you can use the compiler that comes bundled with Visual Studio.
105
+ $ pip install --no-build-isolation --editable .
48
106
49
- If you haven't already, install the latest version of Conda from
50
- `Miniforge <https://github.com/conda-forge/miniforge?tab=readme-ov-file#windows >`_.
51
- It is strongly recommended to choose the option to add Conda to the `PATH `
52
- during installation (because we will not use the Miniforge prompt).
107
+ This will install Sage in the current Conda environment.
108
+ The ``--no-build-isolation `` flag is necessary to allow the build system
109
+ to reuse the already installed build dependencies.
53
110
54
- Open the "VS x64 Native Tools Command Prompt" (for 64bit) or
55
- "Developer Command Prompt for VS2022 (or 2019)" (for 32bit) .
111
+ - You can then start Sage from the command line with `` ./sage ``
112
+ or run the tests with `` ./sage -t `` .
56
113
57
- .. code-block :: shell
114
+ Using system package manager
115
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
116
59
- $ mamba env create --file environment-3.11-win.yml --name sage-dev
60
- $ conda activate sage-dev
61
- $ set LIB=%CONDA_PREFIX%\L ibrary\l ib; %LIB%
62
- $ set INCLUDE=%CONDA_PREFIX%\L ibrary\i nclude; %INCLUDE%
117
+ You can also install the dependencies via your system package manager.
118
+ Note, however, that not all dependencies may be available for your system,
119
+ and that the versions may be outdated.
120
+ In this case, Meson will try to build certain dependencies from source,
121
+ or it will fail with an error message.
122
+ In this case, you can either install the missing dependencies manually,
123
+ or use Conda to install them.
63
124
64
- Windows support is experimental and not fully working yet.
65
- In fact, the Sage prompt is not working at all, but you can use the Python
66
- prompt to run certain commands. For example, the following should work:
125
+ Depending on your distribution, install the following packages:
67
126
68
- .. code-block :: python
127
+ .. tab :: Debian/Ubuntu
69
128
70
- >> > from sage.rings.integer import Integer
71
- >> > Integer(5 )
72
- 5
73
- >> > Integer(5 ) + 2.0
74
- 7.0
129
+ Not yet supported.
75
130
131
+ .. .. literalinclude:: debian.txt
76
132
77
- Alternatively, install all build requirements as described in section
78
- :ref: `section-prereqs `. In the likely case that you have to install some
79
- dependencies manually, set the correct environment variables to point
80
- to the installed libraries:
133
+ .. tab :: Fedora
81
134
82
- .. CODE-BLOCK :: shell-session
135
+ At least Fedora 41 is required.
136
+
137
+ .. literalinclude :: fedora.txt
138
+
139
+
140
+ .. tab :: Arch Linux
141
+
142
+ .. literalinclude :: arch.txt
143
+
144
+ .. tab :: Void Linux
145
+
146
+ .. literalinclude :: void.txt
147
+
148
+
149
+ In the case that you want to install some dependencies manually, set the
150
+ correct environment variables to point to the installed libraries:
151
+
152
+ .. code-block :: shell-session
83
153
84
154
$ export C_INCLUDE_PATH=$C_INCLUDE_PATH:/your/path/to/include
85
155
$ export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/your/path/to/include
86
156
$ export LIBRARY_PATH=$LIBRARY_PATH:/your/path/to/lib
87
157
88
- .. NOTE ::
158
+ We also recommend to install the Python package manager
159
+ `uv <https://docs.astral.sh/uv/getting-started/installation/ >`_.
89
160
90
- If you have previously build Sage in-place, you first have to delete the
91
- already compiled files, e.g. with ``shopt -s globstar `` followed by
92
- ``rm src/**/*.so `` or ``for f in src/**/*.so ; do mv "$f" "$f.old"; done ``.
93
- Moreover, remove the old generated files with
94
- ``find src/sage/ext/interpreters -type f ! -name 'meson.build' -delete ``.
95
- Also uninstall the 'old' sage packages with ``pip uninstall sage-conf sage-setup sagemath-standard ``.
96
-
97
- To compile and install the project in editable install, just use:
161
+ To compile and install Sage in editable install, then just use:
98
162
99
- .. CODE-BLOCK :: shell-session
163
+ .. code-block :: shell-session
100
164
101
- $ pip install --no-build-isolation --editable .
102
-
103
- This will install Sage in the current Python environment.
104
- In a Conda environment, the ``--no-build-isolation `` flag is necessary to
105
- allow the build system to reuse the already installed build dependencies.
106
- If you don't use Conda, you can omit this flag.
165
+ $ uv pip install \
166
+ meson-python \
167
+ "cypari2 >=2.2.1" \
168
+ "cysignals >=1.11.2, != 1.12.0" \
169
+ "cython >=3.0, != 3.0.3" \
170
+ "gmpy2 ~=2.1.b999" \
171
+ memory_allocator \
172
+ "numpy >=1.25" \
173
+ jinja2
174
+ $ uv sync --frozen --inexact
107
175
108
176
You can then start Sage from the command line with ``./sage ``
109
177
or run the tests with ``./sage -t ``.
110
178
111
- .. NOTE ::
179
+ Remarks
180
+ ~~~~~~~
181
+
182
+ .. note ::
112
183
113
184
By using ``pip install --editable `` in the above steps, the Sage library
114
185
is installed in editable mode. This means that when you only edit source
@@ -117,13 +188,13 @@ or run the tests with ``./sage -t``.
117
188
automatically), so you no longer need to manually compile after editing Cython
118
189
files.
119
190
120
- .. NOTE ::
191
+ .. note ::
121
192
122
193
Note that ``make `` is not used at all, nor is ``configure ``.
123
194
This means that any Sage-the-distribution commands such as ``sage -i ``
124
195
will not work.
125
196
126
- .. NOTE ::
197
+ .. note ::
127
198
128
199
By default, Meson will automatically determine the number of jobs to
129
200
run in parallel based on the number of CPU available. This can be adjusted
@@ -132,6 +203,21 @@ or run the tests with ``./sage -t``.
132
203
``--verbose `` can be passed to ``pip install ``, then the meson commands
133
204
internally used by pip will be printed out.
134
205
206
+ .. note ::
207
+
208
+ To build the documentation, use::
209
+
210
+ $ pip install --no-build-isolation -v -v --editable ./pkgs/sage-docbuild
211
+ $ sage --docbuild all html
212
+
213
+ .. note ::
214
+
215
+ You can update the conda lock files by running ``tools/update-conda.py ``.
216
+ In order to update the conda environment afterwards use::
217
+
218
+ $ mamba env update --file environment-3.12-linux.yml --name sage-dev
219
+
220
+
135
221
Background information
136
222
======================
137
223
@@ -140,52 +226,55 @@ We can also use meson directly as follows.
140
226
141
227
To configure the project, we need to run the following command:
142
228
143
- .. CODE-BLOCK :: shell-session
229
+ .. code-block :: shell-session
144
230
145
231
$ meson setup builddir
146
232
147
- This will create a build directory ``builddir `` that will hold the build artifacts.
233
+ This will create a build directory ``builddir `` that will hold the build
234
+ artifacts.
148
235
149
236
If pip is used as above with ``--editable ``, ``builddir `` is set to be
150
- ``build/cp[Python major version][Python minor version] ``, such as ``build/cp311 ``.
237
+ ``build/cp[Python major version][Python minor version] ``, such as
238
+ ``build/cp311 ``.
151
239
152
240
To compile the project, run the following command:
153
241
154
- .. CODE-BLOCK :: shell-session
242
+ .. code-block :: shell-session
155
243
156
244
$ meson compile -C builddir
157
245
158
246
Installing is done with the following command:
159
247
160
- .. CODE-BLOCK :: shell-session
248
+ .. code-block :: shell-session
161
249
162
250
$ meson install -C builddir
163
251
164
- This will install the project to currently active Python environment,
252
+ This will install the project to currently active Python environment,
165
253
or to the system Python environment if no environment is active.
166
- When editable install is used, it is not necessary to reinstall after each compilation.
254
+ When editable install is used, it is not necessary to reinstall after each
255
+ compilation.
167
256
168
- .. NOTE ::
257
+ .. note ::
169
258
170
259
If you want to install the project to a different directory, you can specify
171
260
the ``--prefix `` option when running the ``meson setup `` command:
172
261
173
- .. CODE-BLOCK :: shell-session
262
+ .. code-block :: shell-session
174
263
175
264
$ meson setup builddir --prefix=/desired/install/path -Dpython.install_env=prefix
176
265
177
266
This will then install in the directory specified by ``--prefix ``,
178
267
in particular the root folder will be be installed to
179
- ``/desired/install/path/lib/python3.11 /site-packages/sage ``.
268
+ ``/desired/install/path/lib/python3.12 /site-packages/sage ``.
180
269
Usually, this directory is not on your Python path, so you have to use:
181
270
182
- .. CODE-BLOCK :: shell-session
271
+ .. code-block :: shell-session
183
272
184
273
$ PYTHONPATH=/desired/install/path ./sage
185
274
186
275
Alternatively, we can still use pip to install:
187
276
188
- .. CODE-BLOCK :: shell-session
277
+ .. code-block :: shell-session
189
278
190
279
$ pip install --no-build-isolation --config-settings=builddir=builddir --editable .
191
280
@@ -195,7 +284,7 @@ Alternatively, we can still use pip to install:
195
284
to install to a different directory than the install prefix.
196
285
Both are supported naturally by Meson:
197
286
198
- .. CODE-BLOCK :: shell-session
287
+ .. code-block :: shell-session
199
288
200
289
$ meson setup builddir --prefix=/usr --libdir=... -Dcpp_args=...
201
290
$ meson compile -C builddir
@@ -216,10 +305,11 @@ The environment variable ``MESONPY_EDITABLE_VERBOSE=1`` can be set while running
216
305
so that when Cython files are recompiled a message is printed out.
217
306
See `<https://mesonbuild.com/meson-python/how-to-guides/editable-installs.html#verbose-mode >`_.
218
307
219
- If a new ``.pyx `` file is added, it need to be added to ``meson.build `` file in the
220
- containing directory.
308
+ If a new ``.pyx `` file is added, it need to be added to ``meson.build `` file in
309
+ the containing directory.
221
310
222
- Unlike the ``make ``-based build system which relies on header comments ``# distutils: language = c++ ``
223
- to determine whether C++ should be used, Meson-based build system requires specifying
311
+ Unlike the ``make ``-based build system which relies on header comments
312
+ ``# distutils: language = c++ `` to determine whether C++ should be used,
313
+ Meson-based build system requires specifying
224
314
``override_options: ['cython_language=cpp'] `` in the ``meson.build `` file.
225
315
Similarly, dependencies need to be specified by ``dependencies: [...] ``.
0 commit comments