Commit Graph

189 Commits

Author SHA1 Message Date
Christoph Reiter f20f331494 cpp: restore c++26 support
c++26 support was added in #11986, but regressed in #10332 because
the versions now get checked against the global _ALL_STDS list, and
c++26 was missing there.

Fix by adding c++26 to _ALL_STDS
2023-09-24 10:52:26 -04:00
Xavier Claessens 82a8c72187 c_std, cpp_std: Change to a list of desired versions in preference order
Projects that prefer GNU C but can fallback to ISO C can now set for
example `default_options: 'c_std=gnu11,c11'` and it will use gnu11 when
available, fallback to c11 otherwise. It is an error only if none of the
values are supported by the current compiler.

This allows to deprecate gnuXX values from MSVC compiler, that means
that `default_options: 'c_std=gnu11'` will now print warning with MSVC
but still fallback to 'c11' value. No warning is printed if at least one
of the values is valid, i.e. `default_options: 'c_std=gnu11,c11'`.

In the future that deprecation warning will become an hard error because
`c_std=gnu11` should mean GNU is required, for projects that cannot be
built with MSVC for example.
2023-08-07 08:28:00 -04:00
Jussi Pakkanen 1cd16a7cc5
Merge pull request #11986 from williamspatrick/clang-enable-cpp23
add support for newer C++ -std= flags on Clang/GCC
2023-07-31 16:59:16 +03:00
Jussi Pakkanen 0dba7340ec
Merge pull request #11976 from tristan957/cleanups
Some various type related cleanups
2023-07-17 00:29:37 +03:00
Steven Noonan e3c007aefe c++: add support for c++23/c++26 standard and aliases
GCC 12.3 and Clang 16 support -std flags for c++23/c++2b. The unreleased
GCC 14 and Clang 17 will support -std flags for c++26/c++2c.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-07-14 13:29:16 -05:00
Steven Noonan 658b0d1000 c++: add fallback mappings for C++23 and C++26
The c++23 mappings apply to current production compilers (GCC, Clang).

None of the production c++ compilers support c++26 flags yet, but this
mapping will be ready once they do.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-07-14 13:29:16 -05:00
Tristan Partin 33c8362a1c Match the method signatures of parent classes
Names and types of some methods did not match their parent methods.
2023-07-12 18:56:06 -05:00
Tristan Partin dc692d98fc Make CPPCompiler.get_display_language() a classmethod
This matches the parent declaration.
2023-07-12 18:56:06 -05:00
Tristan Partin d4bcf05c39 Annotate naked fundamental Python types
Although mypy wasn't complaining, pyright was.
2023-07-12 18:56:06 -05:00
Tristan Partin 1624354f33 Use CompileCheckMode enum
There were a ton of naked strings with TODOs telling us to use the enum.
2023-07-12 18:56:06 -05:00
Dylan Baker 9cc67b7fd1
compilers/cpp: check libc++ vs libstdc++ harder
Instead of hardcoding any values, hardcode what we think the most likely
implementation is, and check that first. It was pointed out that while
for example, Apple only provides libc++ and supports that for xcode, a
user could install a custom environment (such as homebrew) which uses
it's own copy of libstdc++, and we need to account for that. This means
that a library search will be done, but only once and the result will be
cached, on all systems.
2023-07-11 15:47:45 -04:00
Dylan Baker 9067139acb compilers/cpp: remove special libc++ handling from the AppleClangCPPCompiler
The base implementation handles this already, with the added bonuses of
caching, and having one less code path to test.
2023-06-29 13:36:47 -07:00
Dylan Baker a227768b37 compilers/cpp: try to do a better job of detecting libc++ vs libstdc++
Currently, we hardcode libc++ for MacOS (and derivatives), and libstdc++
for all other cases. Clang had some hackery to make this work in many
cases. However, this doesn't always work, namely if you try to to use
Rust as the linker when libc++ is required.

This implementation does, as an optimization, provide a hardcoded list
of OSes we know always use libc++, and otherwise will attempt to detect
it. As a second optimization, the detected values are cached, so the
lookup is only done once

fixes: #11921
2023-06-29 13:36:47 -07:00
Dylan Baker f58bd2ae11 compilers/cpp: use a Mixin to share the stdlib flags between clang++ and g++
Which will make subsequent work easier
2023-06-29 11:57:10 -07:00
Dylan Baker a4b597a7b7 compilers/cpp: use a list comprehension instead of a for loop
It's slightly faster, and less code
2023-06-29 11:56:10 -07:00
Dylan Baker 59cfbf68e0 compilers/cpp: Actually add the search dirs to for gcc
We calculate them, but then don't use them. Clang does use them, so this
looks like a simple oversight
2023-06-29 11:56:08 -07:00
Eli Schwartz a1ef957e34
linkers: delay implementations import until detect is run
This saves on a 1500-line import at startup and may be skipped entirely
if no compiled languages are used. In exchange, we move the
implementation to a new file that is imported instead.

Followup to commit ab20eb5bbc.
2023-06-26 13:10:33 -04:00
Nomura 18cfa545f0 Initial support for Metrowerks C/C++ compiler 2023-04-24 09:07:37 -04:00
Jussi Pakkanen 5a34505b18 Add c++23 to the list of C++ standards. 2023-04-17 13:56:31 +03:00
Dylan Baker f06c0e9409 compilers: Optimize the /Zc:__cplusplus code
This could also be handled once, in the initializer
2023-02-08 15:31:58 +05:30
Luke Elliott d573db77bc clang-cl: supports /std:c++20 now.
See https://github.com/llvm/llvm-project/commit/a8f75d49
2023-01-04 09:47:13 -08:00
Dylan Baker f7cde8d3f6 Add fatal=False to many mlog.warnings()
There are lots of warnings that become fatal, that are simply unfixable
by the end user. Things like using old versions of software (because
they're using some kind of LTS release), warnings about compilers not
supporting certain kinds of checks, or standards being upgraded due to
skipped implementations (MSVC has c++98 and c++14, but not c++11). None
of these should be fatal, they're informative, and too important to
reduce to notices, but not important enough to stop meson if they're
printed.
2023-01-03 14:49:02 -05:00
Dylan Baker b9ef662926 reformat some warnings for better code readability 2023-01-03 14:49:02 -05:00
Kleis Auke Wolthuizen cd6b67dea8 emscripten: enforce version 1.39.19 or higher 2022-12-27 06:59:55 -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
Eli Schwartz 0404ad5601
compilers: remove opinionated c++ warning flag
-Wnon-virtual-dtor is not what people think of as a standard warning
flag. It was previously removed from -Wall in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16190 on the grounds that
people didn't like it and were refusing to use -Wall at all because it
forced this warning. Instead, it is enabled by -Weffc++ which is
typically not enabled and even comes with GCC documentation warnings
stating that the standard library doesn't obey it, and you might need to
`grep -v` and filter out warnings. (!!!)

It doesn't fit into the typical semantics of Meson's warning_level
option, which usually aligns with compiler standard warning levels
rather than a niche ideological warning level.

It was originally added in commit 22af56e05a,
but without any specific rationale included, and has gone unquestioned
since then -- except by the Meson users who see it, assume there is a
finely crafted design behind it, and quietly opt out by rolling their own
warning options with `add_project_arguments('-Wall', ...)`.

Furthermore a GCC component maintainer for the C++ standard library
opened a Meson bug report specially to tell us that this warning flag is
a "dumb option" and "broken by design" and "doesn't warn about the right
thing anyway", thus it should not be used. This is a reasonably
authoritative source that maybe, just maybe, this flag... is too
opinionated to force upon Meson users without recourse. It's gone beyond
opinionated and into the realm of compiler vendors seem to think that
the state of the language would be better if the flag did not exist at
all, whether default or not.

Fixes #11096
2022-11-22 23:27:33 -05:00
Xavier Claessens 2961adb8c8 Compilers: Keep ccache and exelist separated
Only combine them in the Compiler base class, this will make easier to
run compiler without ccache.
2022-10-25 17:24:56 -04:00
Robert Cohn 1939e567d6 basic support for oneapi compilers 2022-10-24 18:55:22 +03:00
Dylan Baker 4da14918cd pylint: enable consider-using-in 2022-09-19 20:57:52 -04:00
Eli Schwartz 167356aeab
compilers: correct the MSVC version comparison for turning on __cplusplus
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-07 17:27:55 -04:00
Eli Schwartz 0703ee0aef
move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -04:00
Tristan Partin 5d0538d235 Fix invalid Python overrides
- mismatched method type
- mismatched parameter names
2022-05-19 15:05:53 -04:00
Eli Schwartz 04c728a126 compilers/c++: Add MSVC option to make the __cplusplus define accurate
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 0b97d58548
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-08 14:40:54 -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
Paolo Bonzini ff844f3a1f fix detection of language standard library paths
The code in the C++ and Fortran compilers' language_stdlib_only_link_flags
method is broken and cannot possibly have ever worked.  Instead of
splitting by line, it splits by whitespace and therefore, instead of
the last line of the compiler output:

 programs: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
libraries: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0

it is only the last field that has its first 11 characters removed.
Instead of reinventing the wheel with a new and brittle pattern,
reuse get_compiler_dirs.

Fixes: 64c267c49 ("compilers: Add default search path stdlib_only_link_flags", 2021-09-25)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-03-16 09:24:57 -07:00
Eli Schwartz a009eacc65
treewide: string-quote the first argument to T.cast
Using future annotations, type annotations become strings at runtime and
don't impact performance. This is not possible to do with T.cast though,
because it is a function argument instead of an annotation.

Quote the type argument everywhere in order to have the same effect as
future annotations. This also allows linters to better detect in some
cases that a given import is typing-only.
2022-03-07 19:01:04 -05:00
William Toohey b4d9b2551c Genericise TI compiler and add MSP430 support 2022-02-02 16:45:05 +02:00
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
Ben Boeckel f30e83efd6 armltdclang: add support for ARM Ltd.'s `armclang` toolchain
This is another toolchain also called `armclang`, but it is not a cross
compiler like Keil's `armclang`. It is essentially the same as `clang`
based on its interface and CMake's support of the toolchain.

Use an `armltd` prefix for the compiler ID.

Fixes: #7255
2022-01-03 12:49:04 -05:00
Ben Boeckel 28de74c994 armclang: clarify that this is support for the Keil cross-compiler 2021-12-16 17:08:10 -05:00
Nathanael Gray ae3d495c37 Remove incorrect arguments for C2000 C++ compiler. Add correct form for output and include args. 2021-11-14 21:59:59 +02:00
Eli Schwartz 038b31e72b
various manual conversion of percent-formatted strings to f-strings 2021-11-01 20:26:18 -04:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Moroz Oleg 012ec7d5b3 Add stdc++20 support for Visual Studio 2019 v16.11
fix #9242
2021-10-24 17:08:13 +03:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Eli Schwartz 4ab70c5512
fix extra whitespace
discovered via flake8 --select E303
2021-10-04 16:29:31 -04:00
makise-homura 0021a21930 compilers/elbrus: Deal with C/C++/Fortran stds more correctly 2021-09-29 20:16:02 -07:00
makise-homura d9b379df87 compilers/elbrus: Fix incorrect inheritance model of Elbrus*Compiler 2021-09-29 20:16:02 -07:00
Dylan Baker 64c267c49c compilers: Add default search path stdlib_only_link_flags
This should be done in all cases of language_stdlib_only_link_flags, but
I don't have access to all of the compilers to test it.

This is required in cases where object files created by gfortran are
linked using another compiler with a differen default search path, such
as gfortran and clang together.
2021-09-25 00:18:22 +03:00
Dylan Baker 9795323b86 pylint: check for duplicate imports
I ran into one of these from LGTM, and it would be nice if pylint could
warn me as part of my local development process instead of waiting for
the CI to tell me.
2021-09-24 10:36:05 -07:00