Mesa is not compatible with Python 3.12 due to use of distutils
Mesa uses the following in meson.build:
prog_python = import('python').find_installation('python3')
has_mako = run_command(
prog_python, '-c',
'''
from distutils.version import StrictVersion
import mako
assert StrictVersion(mako.__version__) >= StrictVersion("0.8.0")
''', check: false)
to detect python + the mako python package.
Unfortunately this is not compatible with Python 3.12, because distutils
was removed.
See https://peps.python.org/pep-0632/#migration-advice for details.
Notice that setuptools also provides distutils, and has some ugly hack to make it importable even, but this doesn't work on all platforms: it only works when setuptools is installed as a system site-package, which cannot be assumed in general.