aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
AgeCommit message (Collapse)AuthorFilesLines
2022-09-19fix odd mypy issue in unreachable codeEli Schwartz1-0/+1
This used to be fine, until imports were removed from this file. Now a function annotated as T.NoReturn doesn't actually tell mypy that it cannot return, though, so we manually do it.
2022-09-19simplify type annotationEli Schwartz1-1/+1
2022-09-19compilers: avoid importing compilers upfront for detectEli Schwartz1-114/+2
We no longer need these upfront at all, since we now import the ones we need for the language we are detecting, at the time of actual detection. This avoids importing 28 files, consisting of just under 9,000 lines of code, at interpreter startup. Now, it is only imported depending on which languages are invoked by add_languages, which may not even be anything. And even if we do end up importing a fair chunk of it for C/C++ projects, spreading the import cost around the interpreter runtime helps responsiveness.
2022-09-19compilers: perform targeted imports for detectEli Schwartz1-86/+103
Only import the ones we need for the language we are detecting, once we actually detect that language. This will allow finally dropping the main imports of these files in a followup commit.
2022-09-19compilers: use more direct checks for what kind of compiler we haveEli Schwartz1-7/+7
Instead of comparing against specific compiler classes, check the logical compiler id or language etc. In a couple cases, we seem to be missing a couple things by being a bit too strict about the exact class type.
2022-09-19compilers/detect: rename potentially conflicting nameEli Schwartz1-12/+12
Preparation for future commit.
2022-09-19compilers: use consistent function signature for objcEli Schwartz1-7/+7
e.g. for detect_c_or_cpp we just take the language itself as an argument.
2022-09-19compilers: remove dead codeEli Schwartz1-1/+1
It doesn't matter whether the language is c or cpp, xc16 only has a C compiler so that's what this has to be.
2022-09-19compilers: single-source compiler class as cls, consistentlyEli Schwartz1-18/+26
It's the style for most, but not all, of this file.
2022-09-19compilers: don't export every compiler as a top-level propertyEli Schwartz1-161/+0
This is wasteful and generally unneeded, since code can just use the compiler they detected instead of manually poking at the internals of this subpackage. It also avoids importing an absolute ton of code the instant one runs `from . import compilers`
2022-09-13Use os.path.realpath for default include paths testing in -isystem.Yang Bo1-3/+4
This ensures correct removal of default include paths in -isystem options when symbolic links are involved. A test for this is also added.
2022-09-09compilers: drop some useless info from CompileResultEli Schwartz1-5/+2
text_mode was never set, nor used, and pid was set but never used.
2022-09-09compilers: fix regression in logging cached compile commandsEli Schwartz1-4/+3
In commit d326c87fe22507b8c25078a7cd7ed88499ba7dc1 we added a special holder object for cached compilation results, with some broken attributes: - "command", that was never set, but used to print the log - "args", that was set to some, but not all, of the information a fresh compilation would log, but never used Remove the useless args attribute, call it command, and use it properly.
2022-09-07compilers: correct the MSVC version comparison for turning on __cplusplusEli Schwartz1-1/+1
We compared a Visual Studio (the IDE) version, but we wanted a MSVC (the compiler) version. This caused the option to be passed for a few too many versions of MSVC, and emit a "D9002 : ignoring unknown option" on those systems. Compare the correct version using the version mapping from https://walbourn.github.io/vs-2017-15-7-update/ Fixes #10787 Co-authored-by: CorrodedCoder <38778644+CorrodedCoder@users.noreply.github.com>
2022-09-01env2mfile: reuse logical lists of interesting facts from meson itselfEli Schwartz1-0/+1
Meson internally knows about many languages and tools, and *FLAGS variables, and which languages to use them for. Instead of duplicating this logic, import it from mesonbuild.* This logic was originally standalone, but now that it is merged into the Meson tree we can have a single source of truth.
2022-08-29flake8: move typing-only imports into T.TYPE_CHECKINGEli Schwartz2-2/+6
2022-08-26Fix purely white space issues reported by flake8Alf Henrik Sauge3-12/+10
2022-08-24fix linker regression for compilers that don't accept LDFLAGS directlyEli Schwartz6-13/+31
e.g. ldc -- the compiler needs to process args before consuming them. Fixes #10693
2022-07-25linkers: Add a representation for the Apple AR LinkerDylan Baker1-1/+2
Which is old and annoying and doesn't expose global symbols by default, so we need a work around. see: https://github.com/mesonbuild/meson/pull/10587 see: https://lists.gnu.org/archive/html/libtool/2002-07/msg00025.html
2022-07-21ar linker: detect the "osx ld" case (where generating thin archives won't ↵Justin Blanchard1-3/+3
work) based on host OS, not build OS.
2022-07-21compilers: add logging to obscure compiler defines scraperEli Schwartz1-2/+8
If this command fails, for example when CXX is something not generic enough to be a valid universal compiler command (clang -std=c++11 perhaps), we end up with two problems: - it's impossible to figure out what Meson ran to get that error - the error report isn't clear on what is stdout and what is stderr, or even that that is what the message is about. ``` meson.build:1:0: ERROR: Unable to get clang pre-processor defines: error: invalid argument '-std=c++11' not allowed with 'C' ``` What's C doing there and why is Meson talking about it? Answer: that's compiler stdout. Say so.
2022-07-21compilers: include compiler detection output in the debug logsEli Schwartz1-0/+5
We do something similar when running get_compiler() method checks from the DSL. This ensures that if errors happen, the log file we tell people to check actually works.
2022-07-21compilers: better reporting of command failuresEli Schwartz1-25/+26
Use join_args to ensure that commands are rendered correctly.
2022-07-11Revert /utf-8 changes in the visualstudio mixin to the 0.62.0 stateEli Schwartz1-5/+3
Specifically, this is a combination of the following: - Revert "visualstudio.py: Apply /utf-8 only on clang or VS2015+" This reverts commit 6e7c3efa793c25259891d3b5471343f95fb061fa. - Revert "Visual Studio: Only use /utf-8 on VS2015 or later or clang-cl" This reverts commit 8ed151bbd786d2c52e6ea7b7cfe3147fc41ec041. The changes were broken and untested, although this is because of a lack of general CI testing for all languages on Windows. At least, this broke the use of ifort, and possibly more. The changes are fundamentally a bit "exciting", as they step out of the hierarchy of compiler definitions and apply arguments almost willy-nilly. And apparently it's leaky all over the place. I don't understand all of what is going on with it, but it plainly failed to achieve its desired goal and needs to be rolled back ASAP.
2022-07-06Detect Cython and Vala compilers on the build machine alwaysTristan Partin1-4/+3
Transpilers need to run on the build machine in order to generate their output, which can then be taken by a cross-compiler to create the final output.
2022-07-03move various unused typing-only imports into type-checking blocksEli Schwartz9-11/+30
2022-07-03fix totally invalid import of an importEli Schwartz1-1/+3
MachineChoice is a mesonlib object, not a compilers object, so it makes no sense to import it from the latter simply because the latter imports it too. This results in brittle module dependencies and everything breaking when a refactor removes it from the latter. ... also it is a typing-only import so while we are fixing it to import from the right place, we can also put it in a type-checking block.
2022-06-21visualstudio.py: Apply /utf-8 only on clang or VS2015+Chun-wei Fan1-7/+5
In PR 10263, we didn't account for that we may have initialize the Visual Studio-like compiler two times, once for a C compiler and once for the C++ compiler, so we end up with Meson breaking on Visual Studio 2013 or earlier, such as when building GLib. Fix this by setting up the always_args member of the VisualStudioLikeCompiler instance during __init__() as needed, so that we avoid falling into modifying shared objects.
2022-06-10ACfL version detection with regexStepan Nassyr1-28/+6
2022-06-10Allow for 3-component ACfL versionsStepan Nassyr1-8/+26
2022-06-10treewide: various cleanups to move imports for mypy into typechecking blocksEli Schwartz1-4/+3
Along the way, add __future__ annotations where lacking.
2022-06-06compilers: Add support for stand-alone leak sanitizerMarco Trevisan (Treviño)1-1/+1
Leak sanitizer can be enabled without the whole AddressSanitizer, this can be done by passing -fsanitize=leak as documented at [1]. Meson doesn't support this, so add support for it. [1] https://clang.llvm.org/docs/LeakSanitizer.html
2022-06-01compiler: Add missing needs_static_linker to base Compiler classDylan Baker1-0/+3
2022-05-25Fix optimization level 's' for the TI compilerAndreas Obergschwandtner1-1/+1
2022-05-23move various imports into TYPE_CHECKING blocks for neatnessEli Schwartz1-8/+10
2022-05-19Fix invalid Python overridesTristan Partin3-10/+6
- mismatched method type - mismatched parameter names
2022-05-19Add cc.has_function_attribute('sentinel')Tristan Partin1-0/+2
2022-05-19Add cc.has_function_attribute('section')Tristan Partin1-0/+6
2022-05-09compilers/gnu: demote visibilty inlineshidden to hidden for unsupported ↵Eli Schwartz1-0/+2
compilers This option is only valid for C++ and ObjC++, but the kwarg is useful for mixed language targets. Asking for inlines as well, when the compiler driver is trying to build the C components of a target, results in gcc emitting: ``` cc1: warning: command-line option ‘-fvisibility-inlines-hidden’ is valid for C++/ObjC++ but not for C ``` Squelch this warning by filtering it out on Meson's side of things.
2022-05-08compilers/c++: Add MSVC option to make the __cplusplus define accurateEli Schwartz1-0/+10
Otherwise it always returns the value for c++98, starting with MSVC 2017 15.7 or later. Earlier versions are not affected by this mis-feature. See: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160 This was originally applied as 0b97d585480e973d8b149618901f7a4ddfa1a906 but later reverted because it made the CI red. Try it again, now. Original-patch-by: Dylan Baker <dylan@pnwbakers.com> Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
2022-05-06compiler.has_argument: Add `-Werror=unknown-warning-option` to clang-cl cmd lineKhairul Azhar Kasmiran1-1/+1
2022-04-30implement and test a few compiler checks for DRemi Thebault1-2/+99
- run - sizeof - alignment - has_header
2022-04-30linkers: Add support for mold linkerFini Jastrow7-43/+51
[why] Support for the relatively new mold linker is missing. If someone wants to use mold as linker `LDFLAGS="-B/path/to/mold"` has to be added instead of the usual `CC_LD=mold meson ...` or `CXX_LD=mold meson ...`. [how] Allow `mold' as linker for clang and newer GCC versions (that versions that have support). The error message can be a bit off, because it is generic for all GNU like compilers, but I guess that is ok. (i.e. 'mold' is not listed as possible linker, even if it would be possible for the given compiler.) [note] GCC Version 12.0.1 is not sufficient to say `mold` is supported. The expected release with support will be 12.1.0. On the other hand people that use the un-released 12.0.1 will probably have built it from trunk. Allowing 12.0.1 is helping bleeding edge developers to use mold in Meson already now. Fixes: #9072 Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-04-25Visual Studio: Only use /utf-8 on VS2015 or later or clang-clChun-wei Fan1-0/+4
The compiler flag only exists on Visual Studio 2015 or later, or clang-cl, and using this always can interfere with compiler feature detection when this flag is not supported. So, remove '/utf-8' from always_args if we are on Visual Studio 2013 or earlier.
2022-04-13compilers: fix broken CompCert support for release flagsEli Schwartz1-1/+1
This has been broken ever since the original implementation. Due to a typo, the optimization flag used a zero instead of an uppercase "o", which the compiler then breaks on during argument parsing because it is an invalid argument. Fixes #10267
2022-03-31Merge pull request #9989 from ePirat/epirat-fix-uscore-prefix-detectionJussi Pakkanen2-7/+91
Fix underscore detection
2022-03-31clike: print stderr instead of stdout for debuggingMarvin Scholz1-1/+1
When something goes wrong with running the compiler in _symbols_have_underscore_prefix_searchbin, print stderr instead, as it actually contains helpful output while stdout is usually empty in this case.
2022-03-31visualstudio: do not query underscore define with MSVCMarvin Scholz1-0/+17
MSVC does not has the builtin define to check for the symbol prefix, so do not try to query it at all, to save some time.
2022-03-31clike: add more reliable ways to check underscore prefixMarvin Scholz1-6/+73
Fix #5482
2022-03-30compilers/gnu: use Popen_safe to prevent resource leaksMarvin Scholz1-8/+1
Fixes the following ResourceWarnings: ResourceWarning: subprocess 25556 is still running _warn("subprocess %s is still running" % self.pid, ResourceWarning: Enable tracemalloc to get the object allocation traceback mesonbuild/compilers/mixins/gnu.py:195: ResourceWarning: unclosed file <_io.BufferedReader name=4> return gnulike_default_include_dirs(tuple(self.exelist), self.language).copy() ResourceWarning: Enable tracemalloc to get the object allocation traceback