summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
AgeCommit message (Collapse)Author
2025-07-18Fix use of a .pxi Cython include file as source from `configure_file`Ralf Gommers
Without adding .pxi` as a known header suffix, the added test will fail with: ``` No specified compiler can handle file stuff.pxi ``` Technically only .pxd are header files, and .pxi are "include files" which are literally included in .pyx files. Adding them as headers seems to be fine though, since they're kinda similar and the point is to avoid treating them as source files.
2025-07-18rust: add rust_dynamic_std optionPaolo Bonzini
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as https://github.com/mesonbuild/meson/issues/8828 and https://github.com/mesonbuild/meson/issues/14215. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-18compilers: add Rustup libdir even if there is no other rpath argumentPaolo Bonzini
RustCompiler.build_rpath_args works by appending the directory to the arguments computed by self.linker.build_rpath_args. This does not work if there is no argument to begin with, which happens for example in program crates. Use the new extra_paths argument to force inclusion of the libdir into the rpath of the binary, even in that case. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-12cuda: enable support for `CCCL_ENABLE_ASSERTIONS`David Seifert
CUDA 12.9.0 ships a cccl that supports the new debug macros.
2025-07-10compilers: move CFLAGS/CXXFLAGS handling to EnvironmentPaolo Bonzini
That is where env_opts are stored, so make the compiler call back directly into the environment. Suggested-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10options: apply CFLAGS even if c_link_args existsPaolo Bonzini
This restores the behavior before 1.8's option store refactoring. The bug arises because c_link_args has been stored in pending_options, and therefore the extended value (which get_global_options correctly computes) is overwritten by the value passed on the command line. In fact, this bug is the reason why I added the "link_args_from_envvar" check: the CFLAGS would be ignored anyway, so I put that logic in code instead of relying on the option store's behavior. The fix is to extend the value *after* the option has been added and the pending_options resolved. This requires a tiny refactoring of the split between CoreData.add_lang_args and compilers.get_global_options. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-10options: ignore c(pp)_link_args when deciding whether to apply C(XX)FLAGSPaolo Bonzini
Commit 2d1c67f09 ("options: restore special behavior of CFLAGS vs. c_args", 2025-05-15) incorrectly checked the presence of c_link_args, and did not apply CFLAGS if c_link_args was set. This was not the behavior of 1.7, so remove the check. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-07Correct get_option_std_args for IntelClCCompilerMichael J Steel
In get_option_std_args for the Intel C compiler, the requested command line flag is 'winlibs' which returns a list of strings of libs. It should be 'std' as in other adjacent classes, to return the particular value of the C standard desired.
2025-06-27compilers-fortran: Fix preprocessing when fortran uses concat operatorAndrew Lister
2025-06-23compilers: Implement get_cxx_interoperability_argsAlbert Tang
As is the case with most other methods, it must be overriden in another compiler for it to have any use. Only the Swift compiler uses this method at this time.
2025-06-23swift: Add support for C++/Objective-C++ interoperabilityAlbert Tang
As of Swift 5.9, C++/Objective-C++ code can be mixed with Swift, and C++ APIs can be imported to Swift. However, this must be explicitly enabled, as it is disabled by default. Xcode 15 introduces a new setting for this, so only set it on Xcode 15 and above.
2025-06-18compilers: pgi: fix preprocessing argumentsPaolo Bonzini
Based on reports from the users, PGI compilers need an explicit "-o -" on the command line to emit preprocessed output on stdout. Override the methods in the PGICompiler mixin to add it when output goes to stdout but not when output goes elsewhere. Fixes: #13216 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-06-06Fix Flang stdlib linking for LLVM toolchain versions >= 19Mugundanmcw
2025-06-05swift: Pass C base compile options to swiftcKatalin Rebhan
2025-06-05Add eld as default linker for Qualcomm Hexagon compilerKushal Pal
Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>
2025-05-31cargo: Add support for target specific dependenciesXavier Claessens
2025-05-21compilers: add option for ignoring system dirsDavid Seifert
2025-05-15coredata: remove unused argumentsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-15options: restore special behavior of CFLAGS vs. c_argsPaolo Bonzini
For compatibility with Autotools, CFLAGS is added to the linker command line if the compiler acts as a linker driver. However, this behavior was lost in commit d37d649b0 ("Make all Meson level options overridable per subproject.", 2025-02-13). The issue is that (for example) c_link_args is stored in env.options, and from that point on it is treated as a machine-file option. This includes not being able to override it in compilers.get_global_options: - initialize_from_top_level_project_call places it in pending_options - add_lang_args passes the right value to add_compiler_option - add_compiler_option calls add_system_option_internal - add_system_option_internal fishes the value out of pending_options and ignores what get_global_options provided. Instead, store the putative values of the compiler options coming from the environment in a separate dictionary, that is only accessed by get_global_options. This way it never appears in pending_options, and also there is no internal *_env_args variable anymore. Fixes: #14533 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-13cpp: Fix cpp_std=vc++14Peter Harris
Fixes a regression introduced in commit d37d649b08b8 "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-11compilers/rust: fix syntax of has_argument checksDaniel Foster
2025-05-02cpp: fix _LIBCPP_ENABLE_ASSERTIONS warningMartin Dørum
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-04-30compilers: introduce common helper for sanity checksPaolo Bonzini
Avoid reinventing the wheel and instead use a single helper, taking care of logging and cross compilation. Fixes: #14373 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-30compilers: clike: log output of sanity checkPaolo Bonzini
Particularly if using an exe_wrapper, it can be useful to have output logged for debugging. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-16compilers/rust: remove CRT selection from native_static_libs argsKacper Michajłow
This will be handled by target binary link. And if it's not compatible with what Rust uses, it wouldn't work anyway.
2025-04-16linkers: pass system to DynamicLinker.__init__ for Darwin linkersPaolo Bonzini
Apple linkers need to use different arguments on macOS and iOS-like platforms. Pass the system to the constructor so that it can be examined. Co-authored-by: Russell Keith-Magee <russell@keith-magee.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-09interpreter: Error if java sources used with non-jar target (#14424)Andrew McNulty
If the user specifies java sources as input to a non-jar build target, raise an error with a message directing them to use the jar target instead. Fixes: https://github.com/mesonbuild/meson/issues/13870
2025-04-08coredata: move MutableKeyedOptionDict to optionsDylan Baker
2025-04-04compilers: move -std options to get_option_std_args, special-casing CUDAPaolo Bonzini
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-04compilers: introduce get_option_std_argsPaolo Bonzini
Allow CUDA to completely override the -std arguments but not the rest. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-04compilers: remove useless get_option_compile_argsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-03compilers/rust: fix sanity_check for Windows targetsKacper Michajłow
Windows toolchains append `.exe` to executables. When cross-compiling on Linux, attempting to run `./rusttest` will not execute the generated `rusttest.exe`. Fix this by always appending `.exe`, which is a valid filename on all supported platforms. This is what the `CLikeCompiler` class does too. While reviewing `rust.py`, there are opportunities for improvements and better unification with the rest of the Meson code. However, this commit focuses on fixing cross-compilation with minimal changes. Fixes: #14374
2025-04-02options: move BASE_OPTIONS to the options moduleDylan Baker
This makes more sense from a "group all options together" It also allows us to remove a bunch of imports in functions, a clear code smell.
2025-04-02compilers: rust: fix derivation of RustdocTestCompilerPaolo Bonzini
Pass down the full_version, otherwise assigning "self.is_beta" fails. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02ninjabackend: generate command line for rust doctestsPaolo Bonzini
Adjust get_rust_compiler_args() to accept the crate-type externally, because rustdoc tests are an executable but are compiled with the parent target's --crate-type. Apart from that, the rustdoc arguments are very similar to the parent target, and are handled by the same functions that were split out of generate_rust_target. This concludes the backend implementation of doctests, only leaving the implementation of a doctest() function in the rust module. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02compilers: introduce get_exe() and get_exe_args()Paolo Bonzini
This will be used by rustdoc tests because the Test objects takes a single string for the command and everything else goes in the args. But apart from this, the need to split the executable from the arguments is common so create new methods to do it. While at it, fix brokenness in the handling of the zig compiler, which is checking against "zig" but failing to detect e.g. "/usr/bin/zig". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02ninjabackend: split out generation of rustc argumentsPaolo Bonzini
Allow reusing the code for doctests. In particular, the sources are shared between the two cases. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-12mesonbuild/compilers/detect.py: Support Open D ldc and dmdAndrei Horodniceanu
Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
2025-03-10coredata: remove get_option_for_subprojectDylan Baker
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 Steinhardt
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 Baker
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 Steinhardt
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 Baker
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 Baker
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 Brunet
2025-03-03compilers: Remove the BaseOption typeDylan Baker
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 Baker
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 Rebhan
2025-02-27compilers: delete dead code after option refactorDylan Baker
2025-02-27coredata: delete the OptionsViewDylan Baker
This also makes KeyedOptionDictType obsolete and it's removed