60 Commits
Author SHA1 Message Date
Paolo Bonzini 3f54b93a76 environment: add get_sys_root_path
Extract a function to apply the sysroot path, which python.py uses
in multiple places.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-10-05 13:06:48 +02:00
Barbossa 0a58d1664e dependencies: python: Use python{vernum}_d.lib in MSVC debug builds
Fixes incorrect linking to Python release libraries (python313.lib) when building
debug targets with MSVC on Windows. This ensures compatibility with debug Python
interpreters (e.g. python_d.exe) and resolves runtime crashes.

Details:
- Modified `get_windows_link_args` in `dependencies/python.py` to select debug
  libraries based on Python interpreter build type and Python library suffix (_d.dll).
- Added debug logging to validate library selection.

Fixes: #14429
2026-10-01 16:58:33 +02:00
Paolo Bonzini bdbab2c364 python: do checks for Windows via Python platform, not build machine
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2026-08-19 08:34:53 +02:00
Michał Górny d191bd704d Use destdir_join()
Signed-off-by: Michał Górny <mgorny@quansight.com>
2026-03-27 12:35:38 +01:00
Michał Górny c35a26cddf Fix prepending duplicate sys_root to python build configs
Fix the logic responsible for handling python build configs to check
if paths from `build-details.json` start with sys_root, and do not
prepend it if they do. This matches the pkg-config behavior (of
`PKG_CONFIG_SYSROOT_DIR`). It permits using it both with sysroots that
are a regular system mounted in a subdirectory, and that are dedicated
prefixes (e.g. created via conda).

Signed-off-by: Michał Górny <mgorny@quansight.com>
2026-03-27 12:35:38 +01:00
Dylan Baker 4abca7cad3 dependencies: Remove log_tried method
It's now only used to populate the DependencyCandidate, so we can remove
it and just calculate the same information from the `type_name`
parameter. This reduces code and the number of method calls.
2025-12-17 14:47:18 -08:00
Dylan Baker 63f47811ea Dependencies: Make use of the DependencyCandidate class
This makes the type checking more reasonable (including fixing an issue
that newer mypy is pointing out to us), consolidating special cases, and
improving code readability.
2025-12-17 14:47:18 -08:00
Dylan Baker e1164f616d dependencies: Require 'native' be passed in kwargs
This simplifies a bunch of cases, and likely fixes some annoying bugs
in cross compile situations where should have been passing this and
weren't.
2025-12-17 14:47:18 -08:00
Dylan Baker 7ddd0732c2 dependencies: stop passing "language" as a keyword argument
It's allowed in the `DependencyKeywordArguments` TypeDict already, so we
now have two sources of truth. Additionally, it's often populated by
reading from that dict, so we're just doing useless work.
2025-12-17 14:47:18 -08:00
Dylan Baker 6f3d0ddd82 dependencies: Pass the name to ExternalDependency constructor
So we don't create a default name that is overwritten except in the case
of appleframeworks. This allows for some cleanup, including
deleting some initializers that were only setting the name.
2025-12-17 14:47:18 -08:00
Dylan Baker 15e054e9c3 compilers: Remove Environment parameter from Compiler.has_header 2025-11-19 10:48:48 -08:00
Dylan Baker 252faf5be8 compilers: Remove Environment parameter from Compiler.find_library 2025-11-19 10:48:48 -08:00
Paolo Bonzini 1614401329 environment: move detection functions to envconfig.py
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29 18:59:30 +02:00
Dylan Baker 87dac856b6 dependencies: Add remaining internal arguments to Dependency classes
These may be better replaced by setting instance attributes, honestly.
2025-10-20 15:15:53 -07:00
Dylan Baker 793ba9a543 modules/python: port dependency embed to typed_kwargs 2025-10-20 15:15:53 -07:00
Dylan Baker 035b8e4c01 dependency: Use a TypedDict to describe the keyword arguments to Dependency
This allows us to check that all of the keyword arguments are of the
correct type.
2025-10-20 15:15:53 -07:00
Paolo Bonzini c6814b7cd5 options: replace get_value with get_value_for
The two methods are identical.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-06 14:44:31 -07:00
Russell Keith-Magee 12bebed5a1 Use base_prefix, not prefix for iOS framework linking.
Outside of a venv, sys.prefix and sys.base_prefix are the same. However, if you're using
a virtual environment, sys.prefix points at the location of the virtual environment, not
the location of the iOS binaries. sys.base_prefix should be used to ensure that you're
always referencing the underlying install location, not the venv location.
2025-10-01 13:37:41 -07:00
Filipe Laíns 59c3dd1fdf python: add a python.build_config option (PEP 739)
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Michał Górny <mgorny@quansight.com>
2025-08-28 22:09:20 +03:00
Daniele Nicolodi 96e0c4bf4a dependencies/python: Fix Framework Python when pkg-config is installed
In this case, self.raw_link_args is None.

Fixes #14534.
2025-05-06 21:22:40 +03:00
Daniele Nicolodi a343b01d1b dependencies/python: Replace non-breakable space with space 2025-05-06 21:22:40 +03:00
Russell Keith-Magee c98cd76956 Add framework linking for iOS builds. 2025-05-04 17:34:42 -04:00
L. E. Segovia 237513dffd modules/gnome, modules/Python: Allow injecting RPATH flags through LDFLAGS if needed
Fixes communicating the RPATH to g-i-scanner in macOS.

See #14169
2025-04-09 18:09:57 +05:30
Dylan Baker 4fa5292545 coredata: replace get_option with optstore.get_value_for
This is an old method, that is now just a wrapper around the OptionStore
method, that doesn't add any value. It's also an option related method
attached to the CoreData instead of the OptionStore, so useless and a
layering violation.
2025-03-10 14:14:25 -04:00
L. E. Segovia f75e45887c Python: fix typo in the inserted workaround for missing RPATH
See #14169
2025-02-04 08:16:23 +05:30
L. E. Segovia c616f1ed50 Python: Work around missing rpath in Xcode python3-embed
This enables generating Python bindings and linking against
`python3-embed` without resorting to later `install_name_tool` changes,
as the pkg-config module provided by Xcode doesn't say that
Python3.framework requires a rpath entry:

    $ otool -L /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Python3
    /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Python3:
                @rpath/Python3.framework/Versions/3.9/Python3 (compatibility version 3.9.0, current version 3.9.0)
                /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1933.0.0)
                /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
2025-01-30 15:19:33 +05:30
Dylan Baker cdbd33a4f5 modules/python: Make sure that all dependency candidates meet interface
Because in at least one case it will lack the `log_tried` method.
2025-01-28 10:23:32 -08:00
Edgar Andrés Margffoy Tuay 4ac3e7d356 Enable GCC to find free-threaded python DLL library 2024-11-01 07:44:54 -04:00
Jussi Pakkanen 0d7bb776e2 Move OptionKey in the option source file. 2024-07-11 11:53:39 +03:00
Andrew McNulty 8b757b1f2d Python: fix limited API logic under GCC on Windows
When building a limited API module on Windows the library
to link with should be python3.dll, not python3X.dll. This was
already the case for non-GCC, but should have been the case
unconditionally.
2024-07-02 19:52:52 -04:00
Dudemanguy 9be6e653d4 find_program: add a kwarg to specify custom version argument
When trying to get the version of a program, meson was previously
hardcoded to run the binary with `--version`. This does work with the
vast majority of programs, but there are a few outliers (e.g. ffmpeg)
which have an unusual argument for printing out the version. Support
these programs by introducing a version_argument kwarg in find_program
which allows users to override `--version` with whatever the custom
argument for printing the version may be for the program.
2024-06-23 15:10:42 +03:00
Ralf Gommers a111c28ece Add support for detecting free-threaded Python on Windows
This does a couple of things:
1. Scrape the `Py_GIL_DISABLED` sysconfig var, which is the best way as of today
   to determine whether the target interpreter was built with `--disable-gil`
2. link against the correct libpython
3. On Windows, work around a known issue in the python.org installer with a
   missing define in `pyconfig.h`, which the CPython devs have said is unlikely
   to be fixed since headers are shared between the regular and free-threaded
   builds in a single NSIS installer.
2024-06-23 13:23:31 +03:00
Jussi Pakkanen ce889d6870 Merge pull request #13307 from mesonbuild/optstorerefactor
Convert OptionStore from a dict to a full class with named methods
2024-06-14 19:25:18 +03:00
Jussi Pakkanen 9a6fcd4d9a Replace direct indexing with named methods. 2024-06-14 17:19:53 +03:00
Jussi Pakkanen c0d86024f5 Rename option variable to optstore to make it unique. 2024-06-14 17:19:53 +03:00
Andrew McNulty 328011f77a Python: link correct limited API lib on mingw
This commit fixes GH issue #13167 by linking to the correct
library under MINGW when the 'limited_api' kwarg is specified.
2024-06-11 19:47:31 +02:00
Andrew McNulty f66a527a7c Python: move Windows functions to dependency base
This is in preparation for a future commit which makes it
possible for a PythonPkgConfigDependency to be used in a
context where previously only a PythonSystemDependency would
be used.
2024-06-11 19:47:31 +02:00
Jonathon Anderson 46b3c1c30d python: Fix header check for system method
Fixes https://github.com/mesonbuild/meson/issues/12862
2024-04-16 13:25:40 -07:00
Eli Schwartz 6e1556028c python dependency: use exceptions to pass failure state around
Instead of returning Optional, a state that is only possible during
`__init__` and which prevents mypy from knowing what it is safe to
assume it will get.
2024-02-12 18:52:43 -05:00
Ralf Gommers 80ed1dfa7f Add a numpy dependency with pkg-config and configtool methods
These are being added for NumPy 2.0 The implementation closely follows
the one for the pybind11 dependency.
2024-02-06 12:54:35 -08:00
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Christoph Reiter 6eee9e7c0c python: fix mingw python detection code in case pkg-config isn't available
The code assumed that sysconfig.get_platform() returns "mingw" for mingw Python,
but that's no longer the case for 2.5 years now, as it now only starts with
"mingw" and contains further information like the arch and other ABI relevant things
to avoid conflicts.

This updates the detection code to the current status quo. mingw Python only documents
right now that it starts with "mingw", and none of that arch stuff, but it's
unlikely that this will change, and this looks less error prone than looking at CC.

Fixes #12547
2023-12-03 13:42:45 -05:00
Eli Schwartz 9f610ad5b7 python dependency: ensure that setuptools doesn't inject itself into distutils
We do not use setuptools for anything, and only lightly use distutils.
Unpredictable issues can occur due to setuptools monkey-patching, which
interferes with our intended use. Tell setuptools to simply never get
involved.

Note: while it's otherwise possible to check if the probe is run using
sys.executable and avoid forking, setuptools unconditionally injects
itself at startup in a way that requires subprocess isolation to
disable.
2023-10-02 18:15:16 -04:00
Andrew McNulty c730807696 Python: Add 'limited_api' kwarg to extension_module
This commit adds a new keyword arg to extension_module() that enables
a user to target the Python Limited API, declaring the version of the
limited API that they wish to target.

Two new unittests have been added to test this functionality.
2023-08-14 20:02:09 -04:00
Eli Schwartz b8b2d87567 dependencies: switch the delayed-import mechanism for custom dependencies
Simply store the module it is expected to be found in. That module then
appends to the packages dict, which guarantees mypy can verify that
it's got the right type -- there is no casting needed.
2023-06-26 13:10:33 -04:00
Radek Bartoň 0bea4b632e Fix building python extensions on win-arm64 2023-05-05 15:13:00 -04:00
Ralf Gommers e4f6eeb7d7 Python module: emit warning for debug buildtypes with MSVC and no debug Python
CPython adds a hard to avoid hardcoded link flag to look for a debug
libpython. This results in a very puzzling error, so emit a warning
with a clear message. Note that pybind11 has a workaround for this,
which undefines `_DEBUG`. So users who use only pybind11 can use
non-release buildtypes, but they won't get debug symbols on Windows
unless they have a debug build.
2023-05-05 12:23:52 -04:00
Eli Schwartz a95ebf1077 dependencies: allow config-tool to fallback to default program names
If the dependency permits it, we can just do a PATH search instead of
mandating that it be listed in the cross file. This is useful for the
limited case where a specific dependency is known to be compatible with
any machine choice.

Mark the pybind11 dependency as supporting this. It's a valid choice
because pybind11 is a header-only C++ library.
2023-05-03 20:26:32 -04:00
Charles Brunet bda799dff2 fix python.version() not working in some cases
import('python').find_installation('python').version() causes exception
because of a missing initialization, when `find_installation()` receives
a name or a path.
2023-04-23 23:03:25 -04:00
Eli Schwartz 81c3c3808e python dependency: avoid redefinition warnings for MS_WIN64
pyconfig.h defines it in limited cases, but as empty, rather than as "1"
which is what command-line defines generally do. Explicitly define it as
a compatible definition so the compiler does not log a warning that the
value has changed.

Fixes #11592
2023-03-28 23:24:13 -04:00