Skip to content

dependencies/python: better error when C compiler is missing - #16029

Open
mmustafasenoglu wants to merge 1 commit into
mesonbuild:masterfrom
mmustafasenoglu:fix/python-dep-missing-c-compiler-error
Open

dependencies/python: better error when C compiler is missing#16029
mmustafasenoglu wants to merge 1 commit into
mesonbuild:masterfrom
mmustafasenoglu:fix/python-dep-missing-c-compiler-error

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

When python.dependency() is used in a project without a C compiler (e.g. project('foo', 'rust')), the PythonSystemDependency falls back to MissingCompiler which raises a generic 'no toolchain found' DependencyException. This is confusing for users who don't realize that detecting the Python library requires a C compiler.

This adds an early check in PythonSystemDependency.__init__ that detects when clib_compiler is missing and raises a clear error message:

Python dependency requires a C compiler but none was found. Add "c" to the project languages, e.g. project('foo', 'c', 'rust')

Also guards the has_header() call against MissingCompiler.

Fixes #16024

When python.dependency() is used in a project that does not have a C
compiler (e.g. project('foo', 'rust')), the PythonSystemDependency
falls back to MissingCompiler which raises a generic 'no toolchain
found' DependencyException. This is confusing for users who don't
realize that detecting the Python library requires a C compiler.

Add an early check in PythonSystemDependency.__init__ that detects
when clib_compiler is missing and raises a clear error message
explaining that a C compiler is needed and how to add one.

Also guard the has_header() call against MissingCompiler to avoid
AttributeError in cases where link_libpython is False but no C
compiler is available.

Fixes mesonbuild#16024

Signed-off-by: Mustafa Senoglu <mmustafasenoglu0@gmail.com>
@mmustafasenoglu

Copy link
Copy Markdown
Author

The Windows (vc2022) and macOS failures appear to be pre-existing CI issues — the master branch also has failures on the same platforms (different tests: #216, #299, native:8 on Windows; SDKROOT export on macOS). My change only touches mesonbuild/dependencies/python.py and all Linux CI jobs pass.

@bonzini bonzini added this to the 1.13 milestone Jul 31, 2026
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.

Python dependency not found in project without c language on Windows

2 participants