275 Commits

Author SHA1 Message Date
Aleksandr Kovalko
2b4f5dcd1b compilers/cpp: add vc++23 to ALL_STDS
ClangClCPPCompiler.get_options() registers 'vc++23' as a valid cpp_std
value (since commit 3b7c81d4, 'clang-cl: add c++23 support ...'), but
'vc++23' was never added to the ALL_STDS list that backs the cpp_std
UserStdOption. UserStdOption.set_versions() therefore trips its

    assert all(std in self.all_stds for std in versions)

as soon as a clang-cl C++ compiler is detected, aborting configuration
with an AssertionError ("Unhandled python exception") for every C++
project built with clang-cl. MSVC is unaffected because it never
registers the vc++23 standard.

Add the missing 'vc++23' entry so the compiler's advertised stds are a
subset of ALL_STDS again.
2026-07-07 11:43:46 -07:00
Koushik Nakka
915a847ba2 use VC_VERSION_MAP as base for cpp_stds list 2026-06-04 12:00:48 -07:00
Koushik Nakka
3b7c81d462 clang-cl: add c++23 support via /clang:-std= and remove CPP11AsCPP14Mixin
clang-cl supports C++11 natively, so CPP11AsCPP14Mixin is not needed.
Override get_option_std_args to use /clang:-std=c++N for all standards
except c++latest/vc++latest which still require /std:c++latest. Add
c++23 and vc++23 to the supported standards list.

Fixes #15845
2026-06-04 12:00:48 -07:00
Frankie Robertson
aceb4d82ce Pass -qopenmp to Intel LLVM based compilers 2026-04-20 09:55:51 +01:00
Princeton Ferro
797decc3e4 compilers: pass external args to sanity check; add #include <stddef.h>
Two improvements so the compiler sanity check exercises the same code
paths as cc.links():

1. Compiler._sanity_check_compile_args (the base class) now passes
   get_external_args() and get_external_link_args() to the probe, just
   as build_wrapper_args() does.  CLikeCompiler already did this via
   _get_basic_compiler_args(); the base class fix extends it to non-CLike
   compilers (Fortran, Swift, etc.).  Duplicates in the CLike path are
   harmless because arglist deduplicates them.

2. CCompiler and CPPCompiler sanity check sources now include <stddef.h>.
   This ensures that a broken or missing include path is caught at
   compiler detection time with a natural compiler error, rather than
   surfacing later as a cryptic Meson exception.
2026-04-14 15:37:01 +02:00
Joel Rosdahl
2c72dbe12b Speed up generation of Ninja rules
- Use `lru_cache` for `quote_arg`,
  `_StdCPPLibMixin.language_stdlib_provider` and
  `NinjaBackend._generate_single_compile_base_args`.
- Cache calls to `platform.system().lower()` and
  `platform.release().lower()`.

With this, I see a ≈10% speedup of Ninja rule generation for a somewhat
large project.
2026-04-14 15:34:19 +02:00
Joel Rosdahl
ba3aba7ad8 compilers: Remove _StdCPPLibMixin.language_stdlib_provider env param
It's unused.

Also remove doc string trace of an env parameter to
_StdCPPLibMixin.language_stdlib_only_link_flags.
2026-04-14 15:34:19 +02:00
Ilya Kurdyukov
3beb5d1436 update Elbrus C/C++ stds for newer compiler 2026-02-05 09:14:13 -08:00
Ilya Kurdyukov
f7e24f1695 update ALL_STDS list for C/C++ 2026-02-05 09:14:13 -08:00
Ilya Kurdyukov
d435758194 fix Elbrus support
Fix commit d37d649b08, which broke Elbrus support:

   File "/usr/lib/python3/site-packages/mesonbuild/compilers/cpp.py", line 641, in get_option_compile_args
     assert isinstance(debugstl, str)
2026-02-05 09:14:13 -08:00
Dylan Baker
379165e0c6 compilers: refactor sanity checking code, again
The goal is to reduce code duplication, and allow each language to
implement as little as possible to get good checking. The main
motivation is that half of the checks are fragile, as they add the work
directory to the paths of the generated files they want to use. This
works when run inside mesonmain because we always have an absolute build
directory, but when put into run_project_tests.py it doesn't work
because that gives a relative build directory.

Additionally, this fixes the implementation of sanity checking for
transpiled languages like Vala and Cython, which previously didn't test
the output of their compilers at all, but re-ran the C compiler test for
itself.
2026-02-03 13:34:06 -08:00
Zephyr Lykos
ac746a28c1 compilers: add get_cpp_modules_args method
This new method returns all possible flags to enable C++ Modules.
2026-01-27 14:47:24 -08:00
Zephyr Lykos
5882e83590 compilers/nvidia_hpc: compilers: move -std options to get_option_std_args
Fixes: 6c88d99921
Fixes: d3542ff690
Fixes: ff0c758b2a
2025-12-08 10:06:30 -08:00
Jussi Pakkanen
c52e6c92b0 Add import std support to MSVC. 2025-11-23 16:04:33 +02:00
Jussi Pakkanen
e1d611410f Add cpp_importstd option.
The reason it is a string array is that this allows us to add more
values than true/false should it be needed. For an example see
`b_lto`.
2025-11-23 16:04:33 +02:00
Dylan Baker
b44846c0f2 compilers: Remove Environment parameter from CLikeCompiler.get_compiler_dirs 2025-11-19 10:48:48 -08:00
Dylan Baker
e8c1d6a0b5 compilers: Remove Environment parameter from Compiler.get_option_compile_args 2025-11-19 10:48:48 -08:00
Dylan Baker
249c22df00 compilers: Remove Environment parameter from Compiler.get_option_std_args 2025-11-19 10:48:48 -08:00
Dylan Baker
81bd5d3fe4 compilers: Remove Environment parameter from Compiler.get_option_link_args 2025-11-19 10:48:48 -08:00
Dylan Baker
15e054e9c3 compilers: Remove Environment parameter from Compiler.has_header 2025-11-19 10:48:48 -08:00
Dylan Baker
40b4151f33 compilers: Remove Environment parameter from Compiler.has_header_symbol 2025-11-19 10:48:48 -08:00
Dylan Baker
86b2cf3d1d compilers: Remove Environment parameter from Compiler.has_function 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
Dylan Baker
0e6fd84db2 compilers: Remove Environment parameter from Compiler.get_language_stdlib_only_link_flags 2025-11-19 10:48:48 -08:00
Dylan Baker
5b2bdb4fcf compilers: Remove Environment parameter from Compiler.get_assert_args 2025-11-19 10:48:48 -08:00
Dylan Baker
8938f5efad compilers: Remove Environment parameter from Compiler.sanity_check 2025-11-19 10:48:48 -08:00
Dylan Baker
3832a592db compilers: Remove Environment parameter from Compiler.compiles() 2025-11-19 10:48:48 -08:00
Dylan Baker
e6a8aea750 compilers: Remove Environment parameter from get_compileropt_value 2025-11-19 10:48:48 -08:00
Dylan Baker
fc93ef0370 compilers: Stop passing is_cross
This is calculated by `Environment().is_cross_build(for_machine)`. Since
we have that in the Compiler class, just calculate it in the Compiler
initializer
2025-11-19 10:48:48 -08:00
Dylan Baker
a6c4a4d7e8 compilers: Pass Environment instead of MachineInfo
We end up needing it everywhere, so just store it. This patch is huge
already, so it's just the conversion to passing Environment, more
cleanups to come.
2025-11-19 10:48:48 -08:00
Tudor Gradinaru
a60564e605 Fix inverted RTTI logic in Intel C++ compiler
The IntelCPPCompiler was incorrectly adding -fno-rtti when RTTI was
enabled (rtti=True) instead of when it was disabled. This change
corrects the logic to match the behavior of GCC and Clang compilers,
which properly add -fno-rtti when rtti=False.

Fixes #15220
2025-11-09 14:57:42 +02:00
Sam James
8b74f795e8 compilers: cpp: unset LIBCPP_HARDENING_MODE first for debugstl
libc++ uses the same macro name, just with different values, for debugstl.

If the distro or similar predefines a hardening mode lower than the mode
debugstl wants (or in any other way not equal), we get an annoying redefinition
warning.

Closes: https://github.com/mesonbuild/meson/issues/13812
2025-10-31 01:24:46 -04:00
Sam James
6ad2c91908 compilers: cpp: explain more wrt GCC versions vs assertions
Bug: https://github.com/mesonbuild/meson/issues/13978
2025-10-31 01:24:46 -04:00
Sam James
5403a9dea7 compilers: cpp: stop trying to handle old libc++ for assertions
This has two problems:
1) it keeps breaking with Apple Clang (bug #14440, bug #14856)
2) it gets confused when using GCC with libc++ (a rare configuration)
   because compiler version != libc++ version

There's no reason to keep catering for old libc++ here. The feature
was somewhat immature in older libc++ anyway.

Just rip it out and then we can go back and restore it for the niche
case later.

Bug: https://github.com/mesonbuild/meson/issues/14440
Bug: https://github.com/mesonbuild/meson/issues/14856
Closes: https://github.com/mesonbuild/meson/issues/13978
2025-10-31 01:24:46 -04:00
Sam James
92b60413e2 compilers: cpp: add comment wrt GCC -stdlib=libc++ case
It's not obvious so add a comment, lest someone think handling the case
is a bug.
2025-10-31 01:24:46 -04:00
Liza Chevalier
ba860d72a9 compilers: add Microchip XC32 compiler
The Microchip XC32 compiler is a GCC-based compiler implemented using
existing GNU compiler classes. As the XC32 version and GCC version do
not match mixins have been implemented to override versions used in
versions checks where applicable.
2025-10-29 12:35:55 -07:00
Eisuke Kawashima
6c88d99921 compilers/nvidia_hpc: support C/C++ -std 2025-10-29 11:26:50 -07:00
Dylan Baker
a6af0ad503 Revert "compilers: refactor sanity checking code"
This reverts commit 806289a5d2.
2025-10-06 10:22:41 -07:00
Dylan Baker
806289a5d2 compilers: refactor sanity checking code
The goal is to reduce code duplication, and allow each language to
implement as little as possible to get good checking. The main
motivation is that half of the checks are fragile, as they add the work
directory to the paths of the generated files they want to use. This
works when run inside mesonmain because we always have an absolute build
directory, but when put into run_project_tests.py it doesn't work
because that gives a relative build directory.
2025-10-06 09:03:07 -07:00
Sam James
14c2300dde cpp: handle Apple Clang deprecation of hardening macro for old versions too
a16ec8b0fb changed the threshold to 17
for Apple Clang, but it needs to be 16 instead.

Bug: https://github.com/mesonbuild/meson/issues/14440
Closes: https://github.com/mesonbuild/meson/issues/14856
2025-08-07 19:41:38 -04:00
Peter Harris
043ff22fc7 cpp: Fix cpp_std=vc++14
Fixes a regression introduced in commit d37d649b08 "Make all Meson level
options overridable per subproject." This change results in every file
printing the warning "cl : Command line warning D9002 : ignoring unknown
option '/std:vc++14'"

Now that "get_option_..." is called before overwriting the option (instead
of after), we have to operate on compiler options, not meson options.

There is no such compiler option as /std:vc++14 (the meson option vc++xx is
split into /std:c++xx for the C++ standard version, and a separate flag
that enables Microsoft extensions). Remove the mapping from c++14 to
vc++14.
2025-05-13 09:44:22 -07:00
Martin Dørum
a16ec8b0fb cpp: fix _LIBCPP_ENABLE_ASSERTIONS warning
libc++ deprecated _LIBCPP_ENABLE_ASSERTIONS from version 18.
However, the libc++ shipped with Apple Clang backported that
deprecation in version 17 already,
which is the version which Apple currently ships for macOS.
This PR changes the _LIBCPP_ENABLE_ASSERTIONS deprecation check
to use version ">=17" on Apple Clang.
2025-05-02 15:27:58 +03:00
Dylan Baker
390ea4624c coredata: move MutableKeyedOptionDict to options 2025-04-08 10:00:16 -07:00
Paolo Bonzini
ff0c758b2a compilers: move -std options to get_option_std_args, special-casing CUDA
Move building the -std option to the new get_option_std_args method,
special casing CUDA to never include the option from the host compiler.
This fixes again #8523, which was broken by the option refactoring
(unsurprisingly, since the fix was ripped out unceremoniously without
a replacement).

Fixes: #14365
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-04 12:46:55 +03:00
Paolo Bonzini
4ecf608936 compilers: remove useless get_option_compile_args
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-04 12:46:55 +03:00
Dylan Baker
251f74dcf3 coredata: remove get_option_for_subproject
This is just a wrapper around `OptionStore.get_option_for`, but without
taking an `OptionKey`. This complicates the subproject passing, since
`OptionKey` is designed to encapsulate the option name and subproject.
2025-03-10 14:14:25 -04:00
Jussi Pakkanen
d37d649b08 Make all Meson level options overridable per subproject. 2025-02-13 23:57:48 +02:00
Dylan Baker
ba3460eb11 options: Add an EnumeratedUserOption class
This will allow us to take choices out of the UserOption class, which
doesn't actually use this attribute.
2025-02-05 17:45:38 +02:00
Dylan Baker
0e11b90d6f options: use dataclasses for UserOption
This reduces code, makes this clearer, and will be a nice step toward
the goal of getting everything typesafe.

For `UserIntegerOption` this makes a fairly nice, but substantial change
in that the old method used a tuple of `(min, value, max)` to pass to the
initializer, while all other types just passed `value`. The new
`UserIntegerOption` does the same, with keyword arguments for the min
and max values.
2025-02-05 17:45:38 +02:00
Dylan Baker
fe9f8de1ab compilers: remove Compiler.create_option
This saves a *tiny* bit of typing, but at the cost of requiring either
the current solution of throwing up our hands and saying "typing is too
hard, better to have bugs!" or an extensive amount of `TypedDict`s,
`overloads`, and a very new version of mypy. Let's get our type safety
back, even if it means writing a little bit more code.
2025-02-05 17:45:38 +02:00