aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
AgeCommit message (Collapse)AuthorFilesLines
2025-03-12mesonbuild/compilers/detect.py: Support Open D ldc and dmdAndrei Horodniceanu1-1/+5
Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
2025-03-10coredata: remove get_option_for_subprojectDylan Baker6-17/+19
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-09compilers: convert `b_sanitize` to a free-form array optionPatrick Steinhardt5-22/+25
In the preceding commit we have started to perform compiler checks for the value of `b_sanitize`, which allows us to detect sanitizers that aren't supported by the compiler toolchain. But we haven't yet loosened the option itself to accept arbitrary values, so until now it's still only possible to pass sanitizer combinations known by Meson, which is quite restrictive. Lift that restriction by adapting the `b_sanitize` option to become a free-form array. Like this, users can pass whatever combination of comma-separated sanitizers to Meson, which will then figure out whether that combination is supported via the compiler checks. This lifts a couple of restrictions and makes the supporting infrastructure way more future proof. A couple of notes regarding backwards compatibility: - All previous values of `b_sanitize` will remain valid as the syntax for free-form array values and valid combo choices is the same. We also treat 'none' specially so that we know to convert it into an empty array. - Even though the option has been converted into a free-form array, callers of `get_option('b_sanitize')` continue to get a string as value. We may eventually want to introduce a kwarg to alter this behaviour, but for now it is expected to be good enough for most use cases. Fixes #8283 Fixes #7761 Fixes #5154 Fixes #1582 Co-authored-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-03-09compilers: check for sanitizer arguments via a compiler checkDylan Baker1-2/+14
The `b_sanitize` option is used to specify which sanitizers to use. This option is implemented as a combo option, where it only allows a specific set of hardcoded choices. This implementation isn't quite scalable: - The number of available sanitizers is steadily growing, so we have to always catch up with what sanitizers exist out there. - Sanitizers can be combined more freely nowadays, but we only allow to combine the "address" and "undefined" sanitizers. - A hardcoded list is not a good match given that a choice existing as an option does not mean that it is supported by the compiler in the first place. Instead of hardcoding available options, it is way more future proof to instead allow arbitrary values and perform a compiler check. This makes us support new sanitizers readily while also providing good feedback to our users why a specific option might not be allowed. Implement the compiler checks for sanitizers as a first step. Note that this does not yet loosen the set of allowed sanitizers as we only accept hardcoded values as specified by the combo option. This restriction will be lifted in the next commit.
2025-03-09compilers/cuda: fix checking for multiple linker argsPatrick Steinhardt1-1/+2
When checking for multiple linker args we convert the supplied args to flags that the compiler understands. But besides these supplied args, we also try to convert linker flags that convert warnings into errors. This mechanism causes an error though because we don't know to convert these flags to linker flags: gcc: error: unrecognized command-line option '--warning-as-error'; did you mean '--warn-no-error'? ----------- ERROR: Linker nvcc does not support sanitizer arguments ['-Xcompiler=-fsanitize=address\\,undefined'] As you can see, the flag is passed to the underlying compiler, not to the underlying linker. The obvious fix would be to convert them to linker flags, which we can do by using `-Xlinker=` instead of `-Xcompiler=`. But that is incorrect, too: /nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: unrecognized option '--warning-as-error' /nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: use the --help option for usage information collect2: error: ld returned 1 exit status ----------- ERROR: Linker nvcc does not support sanitizer arguments ['-Xcompiler=-fsanitize=address\\,undefined'] Now we ended up passing the flag to the underlying linker, but the `--warning-as-error` flag isn't known by it. What we really ought to do is to pass on the flag to nvlink, which is the linker driver that controls the underlying linker. Do so by using `-Xnvlink=`, which fixes the bug. Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-03-09compilers/cuda: implement has_argument checksDylan Baker1-2/+10
Same as the preceding commit, the CUDA toolchain does not yet know to perform compile checks for multiple arguments. Backfill required functions.
2025-03-09compilers/rust: implement has_argument checksDylan Baker1-1/+8
We're about to convert the `b_sanitize` option into a free-form array whose value gets verified via a compiler check. This conversion will also impact the Rust toolchain, which does not yet know to check for multiple arguments at once. Implement both `has_multi_arguments()` and `has_multi_link_arguments()` to prepare the code accordingly.
2025-03-09Optimize CLikeCompiler._get_file_from_list()Charles Brunet1-7/+7
2025-03-03compilers: Remove the BaseOption typeDylan Baker2-42/+29
This class only served one purpose, to avoid typing the name of the option twice. Unfortunately the way it was implemented made getting the type checking right difficult, and required storing the same data twice. This patch replaces this approach with a dictionary comprehension that creates the OptionKey from the UserOption. This allows us to initialize a single dictionary once, avoid typing the name twice, delete lines of code, and get better type safety. As an added bonus, it means that the exported data from the module can be marked module constant, ie, ALL_CAPS.
2025-03-01environment: make fully type safeDylan Baker1-0/+2
This as much as anything is to stop lying to envconfig about the potential types it will be given.
2025-03-01swift: Add swift_std compiler optionMarco Rebhan1-1/+28
2025-02-27compilers: delete dead code after option refactorDylan Baker1-26/+0
2025-02-27coredata: delete the OptionsViewDylan Baker2-4/+4
This also makes KeyedOptionDictType obsolete and it's removed
2025-02-27use ElementaryOptionValues instead of open coding... againDylan Baker1-1/+1
2025-02-27modules/rust: use 'nightly' as the bindgen version if the compiler is nightlyDylan Baker1-0/+2
This adds tracking for both nightly and beta to the rust compiler.
2025-02-27compilers/detect: Split -beta and -nightly suffixes from rustcDylan Baker1-3/+8
Store both a full version with the nightly and beta suffixes, and the version as just X.Y.Z. This sort of distinction is why full_version exists. This fixes an issue with the bindgen module where we pass invalid version of X.Y.Z-beta and X.Y.Z-nightly.
2025-02-27Fixes issue 14089 (detection of Intel compiler)Tom Evers1-4/+1
2025-02-16c: add -Wno-vla-larger-than to the exceptions for -Wno*Paolo Bonzini1-4/+10
When supplying -Wno-vla-larger-than to compiler.get_supported_arguments, meson will inject -Wvla-larger-than as an argument which considered invalid by GCC, as the converse argument is -Wvla-larger-than=<value>. Just like CLikeCompiler._has_multi_arguments special-cases -Wno-attributes=, do the same for -Wno-vla-larger-than. Resolves: https://github.com/mesonbuild/meson/issues/14208 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-13Make all Meson level options overridable per subproject.Jussi Pakkanen14-274/+395
2025-02-11ninja backend: Use swiftc flag -working-directory if availableMarco Rebhan1-1/+7
This makes SourceKit-LSP work using a meson-generated compile_commands.json.
2025-02-05options: Replace uses of `UserOption[T.Any]` with a Union of UserOption typesDylan Baker1-2/+1
The fact that UserOption is generic is really an implementation detail, not something to be used publicly. So by having an `AnyOptionType` alias, we can get better type checking, as can be seen by the patch as a whole. One of the big fixes it replace open-coded equivlalents of `MutableKeydOptionDictType` with that type alias.
2025-02-05options: Add an EnumeratedUserOption classDylan Baker7-42/+37
This will allow us to take choices out of the UserOption class, which doesn't actually use this attribute.
2025-02-05options: use dataclasses for UserOptionDylan Baker7-26/+28
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-05compilers: remove Compiler.create_optionDylan Baker10-181/+217
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-05compilers: use super().get_options() instead of CompilerClass.get_options()Dylan Baker3-23/+23
Because the latter doesn't always interact with the MRO correctly.
2025-02-05compilers: fix the UserStdOption name of the C and C++ compilersDylan Baker2-2/+2
2025-02-05options: Get rid of the invalid _U type, and use UserOption[_T]Dylan Baker1-7/+8
2025-02-03rust: use f-string to build rpath argumentsPaolo Bonzini1-1/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03ninjabackend: start adjusting for differences between rustc and rustdocPaolo Bonzini1-4/+22
Add functions to RustCompiler() to account for differences between rustc and "rustdoc --test": rustdoc always generates a binary, does not support -g, and does not need --emit. Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03ninjabackend: unify building rpath argsPaolo Bonzini1-0/+14
Implement RustCompiler.build_rpath_args, so that more code can be shared between non-Rust and Rust targets. Then, RustCompiler can override it to convert the arguments to "-C link-arg=" and add the rustup sysroot. Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-01-29swift: Fix duplicate SDK include paths causing a compile errorPiotr Brzeziński1-2/+32
Some dependencies can bring include paths pointing to older macOS SDK's. In this case, it was libffi pointing to SDK from 12.0. When the Foundation framework is imported in Swift, swiftc attempts to import the FFI module from the most recent version of the SDK, which causes a compilation error because of conflicting definitions between the two SDK versions. SwiftPM also had this problem: https://github.com/swiftlang/swift-package-manager/pull/6772 The solution on our side is a simplified version of what SwiftPM did. Let's naively look for .sdk paths in the compile args of our dependencies and replace them with the most recent one. I included a test which is confirmed to fail without the workaround added in this patch. This was not tested on anything else than macOS, but I don't expect it to make the situation worse in any case.
2025-01-28Merge pull request #13642 from dcbaker/submit/fix-objc-standardsJussi Pakkanen8-151/+234
Support lists for ObjC and ObjC++ standards
2025-01-28compilers/clang++: Add `-fpch-instantiate-templates` to speed up clang++ buildsinsunaa1-0/+6
- see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5168
2025-01-27compilers: Check if GCC has support for ObjC and/or ObjC++Dylan Baker1-1/+5
Since this is optional, we should not accept that GCC is a valid ObjC or G++ is a valid ObjC++ Compiler unless we've tested that they can actually do a basic compile. This requires fixing a number of tests that have broken assumptions. In some cases I've split tests where issues with one language would hide the other. It would be great if we had a competent test framework that allowed subtests to skip, unfortunately we have python's unittest instead. Because of that we can't avoid extra tests by use of subtests.
2025-01-27compilers: split Apple C++ version handling to a mixinDylan Baker3-6/+13
2025-01-27compilers: move Apple C Std version handling to a mixinDylan Baker3-12/+14
To avoid duplication between C and ObjC
2025-01-27compilers/objcpp: Use the GnuCPPStdMixin for ObjC++Dylan Baker1-2/+9
2025-01-27compilers/gnu: Split Gnu C++ standard handling into a mixin classDylan Baker2-14/+28
So we can re-use it in the ObjC++ standards
2025-01-27compilers/objc: Use Shared GNU C standard handlingDylan Baker1-2/+9
2025-01-27compilers/gnu: Pull C Standard handling out of GnuCCompilerDylan Baker2-22/+33
So we can re-use it for the ObjC code
2025-01-27compilers/objcpp: Use shared C++ standards with ClangCPPStandardDylan Baker2-22/+24
2025-01-27compilers/clang: split the Std handling for C++ out of the ClangCPPCompilerDylan Baker2-16/+30
We'll want to use this for the ObjC++ compiler too.
2025-01-27compilers/objc: Use shared C standards with clang C compilerDylan Baker2-19/+27
This means that the two compilers will update together, and that ObjC has the list behavior that C does.
2025-01-27compilers/clang: Move the Mixin for C standards out of the c moduleDylan Baker2-39/+46
We'll want to use this for ObjC as well, so we'll make it public and put it in a public place.
2025-01-27adding c_std=c2y option for gcc-15ajs1-0/+3
Signed-off-by: ajs <sam4lordjesus@outlook.com>
2025-01-27adding c_std=c2y option for clangajs1-1/+4
Signed-off-by: ajs <sam4lordjesus@outlook.com>
2025-01-20Remove GCC's -Wunsuffixed-float-constants from warningsDavid Robillard1-3/+1
This inclusion was a misunderstanding on my part: this warning isn't generally applicable to standard C (it prevents using double literals whatsoever since C doesn't have a suffix for them), but exists to support a GNU C extension. It also has no counterpart in clang. So, remove it, since warning_level=everything doesn't include such things.
2025-01-20compilers/clike: Speedup cross_compute_intFlorian "sp1rit"​1-0/+15
Expand the expression passed into cross_compute_int using the preprocessor first and then try to evaluate the expanded expression using the host machine compiler and test if the result is valid. Co-authored-by: Charles Brunet <charles.brunet@optelgroup.com>
2025-01-15Fix minimum required Apple clang version for C++26Nikolai Vavilov1-3/+1
2025-01-09Add Linear ASM compilerWu, Zhenyu3-0/+51
Fix #13670