Skip to content

Conversation

tobiasdiez
Copy link
Contributor

@tobiasdiez tobiasdiez commented Nov 25, 2024

Replace the old setuptools-based build by the new meson-based one in sage-the-distro. Delete most of the old stuff that is no longer needed now.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@tobiasdiez tobiasdiez changed the title Distro-meson Use meson in sage-the-distro Nov 25, 2024
@tobiasdiez
Copy link
Contributor Author

@dimpase @orlitzky Here is a first version of replacing the old setuptools-based build with meson in sage-the-distro. I'm not familiar enough with sage-the-distro to effectively finish this PR. Do you have the resources to take over from here?

@dimpase
Copy link
Member

dimpase commented Nov 30, 2024

Sure, I'm ready to help as much as I can. Could you share an outline of how this is meant to work?

I imagine it is an adaptation to the Sage's venv (which is a more or less standard venv, no?) of what one can get e.g. with a standard venv on Gentoo Linux, or another environment where all the dependencies are available. Would this approach also work for a Conda-based environment?

@tobiasdiez
Copy link
Contributor Author

As a first step, I would not change how sage-the-distro works. So leave all the dependency installation (python and non-python deps) untouched for now. (We can discuss later how to transfer the configure checks to meson, and perhaps even completely replace the install scripts by mesons wrap files)

So, basically the only required change would be pip install ./src to pip install . , i.e. instead of using the pyproject.toml in src, the meson-based one in the root should be used to install sagelib. I tried to that in build/pkgs/sagelib/spkg-install.in in this branch, but not sure if the changes are correct. Then see what errors popup and resolve those.

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

running ./bootstrap gives

sed: can't read ../sagelib/package-version.txt: No such file or directory

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

that's cause

$ git grep "sagelib/package-version.txt"
pkgs/sagemath-bliss/requirements.txt.m4:sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)')
pkgs/sagemath-coxeter3/requirements.txt.m4:sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)')
pkgs/sagemath-mcqd/requirements.txt.m4:sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)')
pkgs/sagemath-meataxe/requirements.txt.m4:sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)')
pkgs/sagemath-sirocco/requirements.txt.m4:sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)')
pkgs/sagemath-tdlib/requirements.txt.m4:sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)')

@tobiasdiez
Copy link
Contributor Author

I think these requirements files can be safely deleted. At least I'm not aware of any usage of them.

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

I think these requirements files can be safely deleted. At least I'm not aware of any usage of them.

these are for building all these sagemath-* pseudo-packages.

By the way, can you resolve the git conflict?

@tobiasdiez
Copy link
Contributor Author

I think these requirements files can be safely deleted. At least I'm not aware of any usage of them.

these are for building all these sagemath-* pseudo-packages.

You are right, these are actually used.

Does ae33069 works for you? (I cannot test it atm on linux)

@tobiasdiez tobiasdiez marked this pull request as draft December 1, 2024 11:05
@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

something in your branch broke the build system, with recursive make running wild. Not much fun to debug.
after ./bootstrap && ./configure (and hitting Ctrl-C after a short while):

$ make build
make build/make/Makefile --stop
make[1]: Entering directory '/mnt/opt/Sage/sage-dev'
make build/make/Makefile --stop
make[2]: Entering directory '/mnt/opt/Sage/sage-dev'
make build/make/Makefile --stop
...
make[24]: Entering directory '/mnt/opt/Sage/sage-dev'
make build/make/Makefile --stop
^Cmake[24]: *** [Makefile:39: build/pkgs/sage_conf/package-version.txt] Interrupt
make[23]: *** [Makefile:39: build/pkgs/sage_conf/package-version.txt] Interrupt
make[22]: *** [Makefile:39: build/pkgs/sage_conf/package-version.txt] Interrupt
...
make[2]: *** [Makefile:39: build/pkgs/sage_conf/package-version.txt] Interrupt
make[1]: *** [Makefile:39: build/pkgs/sage_conf/package-version.txt] Interrupt
make: *** [Makefile:39: base-toolchain] Interrupt
$ 

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

by the way, can this be based on the grayskull branch - this would make working a bit faster, as bootstrap-conda takes a nontrivial amount of time to run.

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

the recursion (I ran make -d in broken and in the non-broken environments, to compare) starts at

  Considering target file 'build/pkgs/saclib/package-version.txt'.
   Looking for an implicit rule for 'build/pkgs/saclib/package-version.txt'.
    Trying pattern rule '%::' with stem 'package-version.txt'.
   Found implicit rule '%::' for 'build/pkgs/saclib/package-version.txt'.
  Finished prerequisites of target file 'build/pkgs/saclib/package-version.txt'.
  No need to remake target 'build/pkgs/saclib/package-version.txt'.
  Considering target file 'build/pkgs/sage_conf/package-version.txt'.
   File 'build/pkgs/sage_conf/package-version.txt' does not exist.
   Looking for an implicit rule for 'build/pkgs/sage_conf/package-version.txt'.
    Trying pattern rule '%::' with stem 'package-version.txt'.
   Found implicit rule '%::' for 'build/pkgs/sage_conf/package-version.txt'.
  Finished prerequisites of target file 'build/pkgs/sage_conf/package-version.txt'.
  Must remake target 'build/pkgs/sage_conf/package-version.txt'.
make[1]: Entering directory '/mnt/opt/Sage/sage-dev'
Makefile:38: update target 'build/pkgs/sage_conf/package-version.txt' due to: target does not exist
if [ -x relocate-once.py ]; then ./relocate-once.py; fi

So the problem is that build/pkgs/sage_conf/package-version.txt is no longer there. I'll now try with ./configure --disable-sage_conf to see if it makes a difference.

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

--disable-sage_conf has no effect. Has it ever worked? I see

configure: WARNING: unrecognized options: --disable-sage_conf

in the output of ./configure.

It needs, and always needed, the following fix:

--- a/configure.ac
+++ b/configure.ac
@@ -431,7 +431,7 @@ AS_IF([test "x$enable_download_from_upstream_url" = "xyes"], [
 ])
 AC_SUBST([SAGE_SPKG_OPTIONS])
 
-AC_ARG_ENABLE([sagelib],
+AC_ARG_ENABLE([sage_conf],
   AS_HELP_STRING([--disable-sage_conf],
                  [disable build of the sage_conf package]), [
     for pkg in sage_conf; do

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

your fix for VERSION.txt didn't work:

$ ls -l build/pkgs/sage_conf/
total 16
-rw-r--r-- 1 dima dima 167 Jan 26  2024 dependencies
lrwxrwxrwx 1 dima dima  12 Dec  1 12:17 package-version.txt -> 'VERSION.txt'$'\n'
...

@dimpase
Copy link
Member

dimpase commented Dec 1, 2024

To unblock this, one needs to fix

build/pkgs/sage_*/package-version.txt and build/pkgs/sagemath_*/package-version.txt - they should be links to VERSION.txt.
A failed attempt was make in this branch. Instead why not just

cd build/pkgs/sage_conf
ln -sf  ../../../VERSION.txt package-version.txt
... etc

?

After these changes, make starts to run OK.

@dimpase
Copy link
Member

dimpase commented Dec 2, 2024

with changes as above, ./configure && make ends with

make --no-print-directory sagelib-SAGE_VENV-no-deps
[sagelib-10.5.rc2] Setting up build directory /mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/var/tmp/sage/build/sagelib-10.5.rc2
[sagelib-10.5.rc2] Host system: Linux hilbert 6.0.8-gentoo-x86_64 #2 SMP PREEMPT_DYNAMIC Sun Dec 18 22:31:12 GMT 2022 x86_64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz GenuineIntel GNU/Linux
[sagelib-10.5.rc2] C compiler: gcc, Using built-in specs., COLLECT_GCC=gcc, COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/14/lto-wrapper, Target: x86_64-pc-linux-gnu, Configured with: /var/tmp/portage/sys-devel/gcc-14.2.1_p20240817/work/gcc-14-20240817/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/14 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/14/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/14/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14 --disable-silent-rules --disable-dependency-tracking --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/14/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 14.2.1_p20240817 p4' --with-gcc-major-version-only --enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-multilib --with-multilib-list=m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --enable-cet --disable-systemtap --disable-valgrind-annotations --disable-vtable-verify --disable-libvtv --with-zstd --without-isl --enable-default-pie --enable-host-pie --enable-host-bind-now --enable-default-ssp --disable-fixincludes --with-build-config='bootstrap-O3 bootstrap-cet', Thread model: posix, Supported LTO compression algorithms: zlib zstd, gcc version 14.2.1 20240817 (Gentoo 14.2.1_p20240817 p4)
[sagelib-10.5.rc2] No stamp file for package 'sagelib' in /mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/var/lib/sage/installed
[sagelib-10.5.rc2] No spkg-legacy-uninstall script; nothing to do
[sagelib-10.5.rc2] [spkg-install] Installing sagelib-10.5.rc2 (editable mode)
[sagelib-10.5.rc2] [spkg-install] Using pip 24.2 from /mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/pip (python 3.12)
[sagelib-10.5.rc2] [spkg-install] Obtaining file:///mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/var/tmp
[sagelib-10.5.rc2] [spkg-install] ERROR: file:///mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/var/tmp does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
[sagelib-10.5.rc2] [spkg-install] ***************************************************************************************************************************************************************************************************
[sagelib-10.5.rc2] [spkg-install] Error installing sagelib-10.5.rc2
[sagelib-10.5.rc2] [spkg-install] ***************************************************************************************************************************************************************************************************

the ERROR comes from load_pyproject_toml() in local/var/lib/sage/venv-python3.12/lib64/python3.12/site-packages/pip/_internal/pyproject.py, i.e. from pip.

Indeed, there is no pyproject.toml in local/var/lib/sage/venv-python3.12/var/tmp (and, needless to say, no setup.py)
The latter directory is set up by extract_the_package() from build/bin/sage-spkg, with $PKG_SRC_TYPE being script (sic!), and $PKG_SRC being sagelib-10.5.rc2.

One way or another, spkg-install is not invoked from build/pkgs/sagelib, but rather from local/var/lib/sage/venv-python3.12/var/tmp [etc], so cd ../../../ in there does not bring us to the correct place, which is $SAGE_ROOT.

With

--- a/build/pkgs/sagelib/spkg-install.in
+++ b/build/pkgs/sagelib/spkg-install.in
@@ -1,7 +1,7 @@
 if [ "$SAGE_EDITABLE" = yes ]; then
-    cd ../../..
+    cd $SAGE_ROOT
 else
-    cd ../../..
+    cd $SAGE_ROOT
     # Issue #34181: Do not allow scripts with shebang lines from old
     # venvs leak into new venvs. (Changes only seem to be necessary
     # for non-editable builds.)

one gets to meson being invoked for building. However, it ends with

[sagelib-10.5.rc2] [spkg-install]   The Meson build system
[sagelib-10.5.rc2] [spkg-install]   Version: 1.5.1
[sagelib-10.5.rc2] [spkg-install]   Source dir: /mnt/opt/Sage/sage-dev
[sagelib-10.5.rc2] [spkg-install]   Build dir: /mnt/opt/Sage/sage-dev/build/cp312
[sagelib-10.5.rc2] [spkg-install]   Build type: native build
[sagelib-10.5.rc2] [spkg-install]   Project name: SageMath
[sagelib-10.5.rc2] [spkg-install]   Project version: 10.5.rc2
[sagelib-10.5.rc2] [spkg-install]   C compiler for the host machine: gcc (gcc 14.2.1 "gcc (Gentoo 14.2.1_p20240817 p4) 14.2.1 20240817")
[sagelib-10.5.rc2] [spkg-install]   C linker for the host machine: gcc ld.bfd 2.43
[sagelib-10.5.rc2] [spkg-install]   C++ compiler for the host machine: g++ -std=gnu++11 (gcc 14.2.1 "g++ (Gentoo 14.2.1_p20240817 p4) 14.2.1 20240817")
[sagelib-10.5.rc2] [spkg-install]   C++ linker for the host machine: g++ -std=gnu++11 ld.bfd 2.43
[sagelib-10.5.rc2] [spkg-install]   Cython compiler for the host machine: cython (cython 3.0.11)
[sagelib-10.5.rc2] [spkg-install]   Host machine cpu family: x86_64
[sagelib-10.5.rc2] [spkg-install]   Host machine cpu: x86_64
[sagelib-10.5.rc2] [spkg-install]   Program python found: YES (/mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/bin/python3)
[sagelib-10.5.rc2] [spkg-install]   Found pkg-config: YES (/usr/bin/pkg-config) 2.3.0
[sagelib-10.5.rc2] [spkg-install]   Run-time dependency python found: YES 3.12
[sagelib-10.5.rc2] [spkg-install]   Program python (pytest) found: NO
[sagelib-10.5.rc2] [spkg-install] 
[sagelib-10.5.rc2] [spkg-install]   ../../src/meson.build:18:8: ERROR: Tried to form an absolute path to a dir in the source tree.
[sagelib-10.5.rc2] [spkg-install]   You should not do that but use relative paths instead, for
[sagelib-10.5.rc2] [spkg-install]   directories that are part of your project.
[sagelib-10.5.rc2] [spkg-install] 

where the log says

--- stderr ---


Running command: /mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/bin/python3 -c 'import numpy
print(numpy.get_include())'
--- stdout ---
/mnt/opt/Sage/sage-dev/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/numpy/core/include

--- stderr --- 

So meson isn't happy about the full path here. Not sure what an easy fix is.

@dimpase
Copy link
Member

dimpase commented Aug 25, 2025

@kiwifb - on Gentoo, ./bootstrap && ./configure --enable-system-site-packages && make is a close, modulo few Python packages, (by the way, please merge #40568 (and review it again)) approximation of a pure meson build of sagelib.

else
# Now implied: "$SAGE_WHEELS" = yes
# We should remove the egg-link that may have been installed previously.
(cd "$SITEPACKAGESDIR" && rm -f sagemath-standard.egg-link)
# Use --no-build-isolation to avoid rebuilds because of dependencies:
# Compiling sage/interfaces/sagespawn.pyx because it depends on /private/var/folders/38/wnh4gf1552g_crsjnv2vmmww0000gp/T/pip-build-env-609n5985/overlay/lib/python3.10/site-packages/Cython/Includes/posix/unistd.pxd
sdh_pip_install --no-build-isolation .
sdh_pip_install --no-build-isolation . --config-settings=setup-args="-DSAGE_LOCAL=$SAGE_LOCAL"
Copy link
Member

Choose a reason for hiding this comment

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

So, a concrete comment @dimpase in the non-editable install you do not set the build-dir. So, I am expecting that if you try to build the documentation with make doc-html after a non editable install, it will fail because it specifically looks for build/sage-distro and I am fairly sure that will not be what pip uses by default.

Copy link
Member

Choose a reason for hiding this comment

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

SAGE_EDITABLE=no make build quickly errors out:

[sagelib-10.8.beta0] [spkg-install] Installing sagelib-10.8.beta0
[sagelib-10.8.beta0] [spkg-install] usage: python -m build [-h] [--version] [--verbose] [--sdist] [--wheel]
[sagelib-10.8.beta0] [spkg-install]                        [--outdir PATH] [--skip-dependency-check]
[sagelib-10.8.beta0] [spkg-install]                        [--no-isolation | --installer {pip,uv}]
[sagelib-10.8.beta0] [spkg-install]                        [--config-setting KEY[=VALUE]]
[sagelib-10.8.beta0] [spkg-install]                        [srcdir]
[sagelib-10.8.beta0] [spkg-install] python -m build: error: unrecognized arguments: --config-settings=setup-args=-DSAGE_LOCAL=/home/dima/software/sage-src/local

@tobiasdiez - what's the correct way to do this, or it's indeed broken?
It seems to have been broken before this PR, too, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot @kiwifb! I indeed missed to change the builddir for non-editable builds. Should be fixed now.

@dimpase just a typo due to different conventions of build and pip install (config-setting vs config-settings). What I don't understand is why the non-editable install needs to create wheels using build, instead of using pip install without -e. But that's for another day.

@vbraun
Copy link
Member

vbraun commented Aug 26, 2025

I'm guessing this breaks incremental builds, ok but maybe make it more explicit then there will be fewer failure reports from people that test incremental builds

@dimpase
Copy link
Member

dimpase commented Aug 26, 2025

I'm guessing this breaks incremental builds, ok but maybe make it more explicit then there will be fewer failure reports from people that test incremental builds

before trying this PR one most probably needs make distclean, as it's a big change.

Then it should be fine (perhaps more cleaning up of things triggering senseless recursive rebuilds might be needed)

@tobiasdiez
Copy link
Contributor Author

Documentation build fails with

[sagelib-10.8.beta0] [spkg-install]   ../../src/doc/en/thematic_tutorials/explicit_methods_in_number_theory/meson.build:27:16: ERROR: File conf.py does 
not exist. 

@vbraun
That comes since your branch includes a commit that deletes it: vbraun@e01e900

Would it be possible to test this branch here on isolation on the build bots. Since it completely changes how sagelib is built, it's very likely that other PRs are indeed changing things in a way that needs slight modification afterwards.

@fchapoton
Copy link
Contributor

I confirm that the build works with the current branch on the Ubuntu machine where it failed because of NumPy.

@tobiasdiez tobiasdiez mentioned this pull request Aug 26, 2025
5 tasks
@tobiasdiez
Copy link
Contributor Author

I confirm that the build works with the current branch on the Ubuntu machine where it failed because of NumPy.

Awesome, thanks for testing!

Co-authored-by: Kwankyu Lee <[email protected]>
@tobiasdiez
Copy link
Contributor Author

Documentation build fails with

[sagelib-10.8.beta0] [spkg-install]   ../../src/doc/en/thematic_tutorials/explicit_methods_in_number_theory/meson.build:27:16: ERROR: File conf.py does 
not exist. 

Fixed that now by removing the conf.py files also here in this PR. Since the CI is passing, setting it back to positive review.

@vbraun
Copy link
Member

vbraun commented Aug 27, 2025

merge conflict

@tobiasdiez
Copy link
Contributor Author

tobiasdiez commented Aug 28, 2025

merge conflict

Resolved now. @vbraun

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 31, 2025
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Replace the old setuptools-based build by the new meson-based one in
sage-the-distro. Delete most of the old stuff that is no longer needed
now.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

- sagemath#40133
- sagemath#39973
- sagemath#40071
- sagemath#40597
<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

URL: sagemath#39030
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik, François Bissey, Tobias Diez
@dimpase dimpase mentioned this pull request Sep 1, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants