Commit Graph

291 Commits

Author SHA1 Message Date
Eli Schwartz 0a6e485d92
pylint 2.16: join iterables without repeated append
We do += style joining in a loop, but we could just join with
`''.join()` which is faster, neater, and simpler.
2023-02-01 17:01:31 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Charles Brunet 3729b6bcd4 remove /utf-8 option when /validate-charset- is present 2023-02-01 11:33:17 -05:00
Kleis Auke Wolthuizen 4e1d0e4784 emscripten: remove redundant `thread_flags` implementation
Since it's the same as the one in `CLikeCompiler`.
2022-12-27 06:59:55 -05:00
Kleis Auke Wolthuizen 51ac9ed317 emscripten: use single arguments when specifying options
i.e. without a space between the "-s" and option name. See:
https://github.com/emscripten-core/emscripten/issues/11463

This is supported since Emscripten 1.39.19, see:
f45bea21f3
2022-12-27 06:59:55 -05:00
Kleis Auke Wolthuizen 898e85d847 emscripten: prefer `-pthread` over `-s USE_PTHREADS=1`
See: https://github.com/emscripten-core/emscripten/issues/12346

This is supported since Emscripten 1.38.33, see:
24350798a8
2022-12-27 06:59:55 -05:00
Nirbheek Chauhan 5dd3413b71 meson: Cache os.path.realpath in CLikeCompilerArgs
Profiling showed that we were spending 25s inside os.path.realpath()
on Windows while generating compile lines for build.ninja, inside
NinjaBackend.generate()

The real path for these will not (should not) change during a single
meson invocation, so cache all these.

Brings build.ninja generation from 73s to 47s on my machine.
2022-12-22 23:14:25 +05:30
Dylan Baker 2d349eae8c
pylint: enable the set_membership plugin
Which adds the `use-set-for-membership` check. It's generally faster in
python to use a set with the `in` keyword, because it's a hash check
instead of a linear walk, this is especially true with strings, where
it's actually O(n^2), one loop over the container, and an inner loop of
the strings (as string comparison works by checking that `a[n] == b[n]`,
in a loop).

Also, I'm tired of complaining about this in reviews, let the tools do
it for me :)
2022-11-30 16:23:29 -05:00
David Robillard 81d7c24a59 Add warning_level=everything
Adds a new maximum warning level that is roughly equivalent to "all warnings".
This adds a way to use `/Wall` with MSVC (without the previous broken warning),
`-Weverything` with clang, and almost all general warnings in GCC with
strictness roughly equivalent to clang's `-Weverything`.

The GCC case must be implemented by meson since GCC doesn't provide a similar
option.  To avoid maintenance headaches for meson, this warning level is
defined objectively: all warnings are included except those that require
specific values or are specific to particular language revisions.  This warning
level is mainly intended for new code, and it is expected (nearly guaranteed)
that projects will need to add some suppressions to build cleanly with it.

More commonly, it's just a handy way to occasionally take a look at what
warnings are present with some compiler, in case anything interesting shows up
you might want to enable in general.

Since the warnings enabled at this level are inherently unstable with respect
to compiler versions, it is intended for use by developers and not to be set as
the default.
2022-11-27 16:50:48 -05:00
Xavier Claessens e68fcac919 compilers: Make sure to not use ccache in compiler checks
ccache was used in all command lines but disabled using CCACHE_DISABLE
in Compiler.compile() method. Wrapping invokations still has a cost,
especially on Windows.

With sccache things are even worse because CCACHE_DISABLE was not
respected at all, making configure *extremely* slow on Windows when
sccache is installed.
2022-10-25 17:24:56 -04:00
Tristan Partin 5a7427cebb Fix mismatched param names between Compiler and BasicLinkerIsCompilerMixin 2022-10-24 21:43:25 +03:00
Xavier Claessens ebbaeec51b gnulike: Fix preprocessing files with any extension 2022-10-23 12:21:46 +02:00
Xavier Claessens 5e0f22896f Compilers: Add a preprocessor mode for clike compilers
A compiler object can now return a list of "modes", they are new
compiler object specialized for a specific task.
2022-10-23 12:21:46 +02:00
Tatsuyuki Ishi 673dca5c07 Add b_thinlto_cache for automatically configuring incremental ThinLTO 2022-10-13 04:18:13 -04:00
Tatsuyuki Ishi a0032480d6 clang: Support ThinLTO with mold 2022-10-13 04:18:13 -04:00
Jan Tojnar a590cfde0c compilers: Add optimization=plain option
https://github.com/mesonbuild/meson/pull/9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
2022-10-09 14:43:18 +03:00
Dylan Baker 676e66f853
pylint: enable consider-using-(min|max)-builtin
There's only one case of each, in the same function, so I've handled
both in the same commit.
2022-10-03 00:02:20 -04:00
Eli Schwartz 56a6ee1e5d find_library with argument beginning in "lib" is a bad idea, warn about it
We need to support cases where the library might be called "foo.so" and
therefore we check for exact matches too. But this also allows
`cc.find_library('libfoo')` to find libfoo.so, which is strange and
won't work in many cases. Emit a warning when this happens.

Fixes #10838
2022-09-28 12:53:46 +03:00
Eli Schwartz 30b1774628 compilers: unify fortran sanity check with its parent Clike handling
We *mostly* just need to do the same thing. Plug in one utility method
to make sanity_check_impl find the right compile args, and plug in
DEVNULL to the test run. It's that simple.

This solves a few inconsistencies. The main one is that fortran never
logged the sanity checks to the Meson debug log, making it hard to
debug.

There's also some interesting quirks we built up in the dedicated
fortran handling. For example:

- in commit 5b109c9ad2 we added cwd to
  building the fortran executable, with a wordy comment about how the
  compiler has defects. But the clike base has always done that on
  general principle anyway, so we would never have had that bug in the
  first place.

- in commit d6be7822a0 we added special
  deletion of an old "bad existing exe file" just for fortran. Looking
  at the PR discussion for this odd requirement, it turns out that the
  real problem is mixing WSL and native Windows without deleting the
  build directory. This is apparently fortran specific simply because
  "contemporary Windows 10 Fortran users" switch between the two?

  The actual problem is that this never used .exe as the output name, so
  Windows thinks you want to run something other than the thing you
  asked to run, because it's not even a Window executable. But... the
  common clike handling could have fixed that without needing special
  cases.
2022-09-22 18:15:25 -04:00
Eli Schwartz 332968da1b use simpler subprocess.run interface instead of manual Popen
This code dates back to 2012 and probably has no specific reason...
2022-09-22 18:15:25 -04:00
Eli Schwartz 0d354588ca compilers: make sanity checks log commands using join_args
It is more correct to join commands with a command joiner than a
whitespace joiner.
2022-09-22 18:15:25 -04:00
Yang Bo 83d18d137d Use os.path.realpath for default include paths testing in -isystem.
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-13 02:24:38 -04:00
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -04:00
Eli Schwartz 27748f9cd1
fix linker regression for compilers that don't accept LDFLAGS directly
e.g. ldc -- the compiler needs to process args before consuming them.

Fixes #10693
2022-08-24 23:49:14 -04:00
Eli Schwartz 46793145ba
Revert /utf-8 changes in the visualstudio mixin to the 0.62.0 state
Specifically, this is a combination of the following:

- Revert "visualstudio.py: Apply /utf-8 only on clang or VS2015+"

  This reverts commit 6e7c3efa79.

- Revert "Visual Studio: Only use /utf-8 on VS2015 or later or clang-cl"

  This reverts commit 8ed151bbd7.

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-11 17:58:02 -04:00
Chun-wei Fan 6e7c3efa79 visualstudio.py: Apply /utf-8 only on clang or VS2015+
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-21 21:08:06 +03:00
Andreas Obergschwandtner bfc4e958b4 Fix optimization level 's' for the TI compiler 2022-05-25 07:12:02 -07:00
Tristan Partin 5d0538d235 Fix invalid Python overrides
- mismatched method type
- mismatched parameter names
2022-05-19 15:05:53 -04:00
Eli Schwartz 7c4087ace5 compilers/gnu: demote visibilty inlineshidden to hidden for unsupported 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-09 10:49:04 -04:00
Khairul Azhar Kasmiran 6b7bc608b7 compiler.has_argument: Add `-Werror=unknown-warning-option` to clang-cl cmd line 2022-05-06 23:09:52 +03:00
Fini Jastrow c16fdaeeca linkers: Add support for mold linker
[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-30 10:06:22 -04:00
Chun-wei Fan 8ed151bbd7 Visual Studio: Only use /utf-8 on VS2015 or later or clang-cl
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-25 20:29:16 +03:00
Eli Schwartz a0e7f93414 compilers: fix broken CompCert support for release flags
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-04-13 21:11:09 +03:00
Jussi Pakkanen efc7604ca2
Merge pull request #9989 from ePirat/epirat-fix-uscore-prefix-detection
Fix underscore detection
2022-03-31 16:26:22 +03:00
Marvin Scholz 89620dc8e7 clike: print stderr instead of stdout for debugging
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-31 10:55:55 +02:00
Marvin Scholz 1b03441bc4 visualstudio: do not query underscore define with MSVC
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-31 10:55:55 +02:00
Marvin Scholz f02ffc007c clike: add more reliable ways to check underscore prefix
Fix #5482
2022-03-31 10:55:55 +02:00
Marvin Scholz 4b97c60650 compilers/gnu: use Popen_safe to prevent resource leaks
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
2022-03-30 16:04:23 -04:00
Xavier Claessens 06d12064d0 OptionOverrideProxy: Make it immutable to avoid copies
It is always used as an immutable view so there is no point in doing
copies. However, mypy insist it must implement the same APIs as
Dict[OptionKey, UserOption[Any]] so keep faking it.
2022-03-22 17:20:48 -04:00
Dylan Baker f9bfeb2add compilers/gnu: set level 0 optimization to '-O0'
GCC with optimization set to 0 does not actually result in no
optimizations, which can be annoying when trying to use a debugger like
gdb, and finding that your variable has been optimized out. We already
do this with clang, so gcc is a bit of an outlier here.
2022-03-02 19:59:45 +02:00
Eli Schwartz 9daaece785
flake8: fix various whitespace errors with badly aligned code 2022-02-16 23:00:31 -05:00
William Toohey b4d9b2551c Genericise TI compiler and add MSP430 support 2022-02-02 16:45:05 +02:00
Gatgat f3a8e5d3b2 Fix system include arguments for clang-cl 2022-01-15 22:00:05 +05:30
Dylan Baker 1209b8820b compilers: push the compiler id to a class variable
It really is a per class value, and shouldn't be set per instance. It
also allows us to get rid of useless constructors, including those
breaking mypy
2022-01-10 15:53:26 -05:00
Jussi Pakkanen 251d6f0f5d
Merge pull request #9739 from mathstuf/armclang-support
Armclang support
2022-01-10 19:01:11 +02:00
Eli Schwartz 9f384e9207
fix type annotations for compiler toolchain rpaths
We pass around a tuple of rpaths, because rpaths *can* be more than one.
But all the annotations said it would be a str instead.
2021-12-30 15:15:25 -05:00
Tristan Partin 269337ceb2 Fix mypy 0.930 issues
Removed errant "type: ignore".

Fixed issue with "fetch" call. This issue was the following:

Dict::get() and Dict::pop() have the following signature:

T.Callable[[_T, _U], _U | None] OR T.Callable[[_T], _U | None]

Note how the return type is _U here. When the fetch() function was
actually being called, it had the following signature:

T.Callable[[_T, T.List[_U]], T.Union[T.List[_U], _U]]

This is incompatible with the previous definitions. The solution is
simply to move where the default value is introduced if fetch() produces
None.
2021-12-30 00:53:58 -05:00
Ben Boeckel 28de74c994 armclang: clarify that this is support for the Keil cross-compiler 2021-12-16 17:08:10 -05:00
Sahnvour d9c73a6a7b clang-cl: add a translation pass for `-isystem` args to work 2021-12-08 00:53:29 +02:00
Luke Elliott d014ccf8d7 Fix _calculate_toolset_version for VS2022. 2021-11-27 21:46:16 +02:00