Commit Graph

1138 Commits

Author SHA1 Message Date
Eli Schwartz 34ac2e4af6 fix ninja backend rules containing internal enum reprs
Partially reverts commit 1624354f33 which
moved a bunch of stuff from strings to enums. The issue here is that
Compiler.mode is not just, or primarily, something we compare, but is
instead written in as e.g. `rule c_{compiler.mode}` to build.ninja, so
this identifier needs to be a string.

Ultimately, the issue is that the commit tried to rewrite a bunch of
things called "mode" that had a couple of TODOs saying to use enums...
but it rewrote everything called "mode" regardless of whether it was a
function kwarg or a compiler property, even though the TODO only applied
to one of them.
2023-10-20 18:07:05 -04:00
Eli Schwartz 1cf0ed0997 add missing imports for future annotations 2023-10-20 18:07:05 -04:00
Xavier Claessens e2a87afa52 rust: Always link dll and exe with the correct vscrt
This fixes missing flags in the link_whole case and link failure for
static libraries.
2023-10-19 08:13:57 -04:00
Xavier Claessens 361f7484d2 Remove duplicated code to canonicalize b_vscrt option value
Add a common function that infers vscrt from buildtype in Compiler base
class.
2023-10-19 08:13:57 -04:00
Dylan Baker 74771d2119 compilers/d: use DFeatures for get_features_args 2023-10-16 13:28:32 -07:00
Dylan Baker 6599c32fd3 compilers/d: remove duplicate method from subclass
The DCompiler and DmDLikeCompiler classes both implement the exact same
`get_feature_args()` method. The DmdLikeCompiler inherits the DCompiler.
As such, removing it doesn't change the behavior of anything, but
decreases the chances of bugs being introduced, as well as LoC.
2023-10-16 13:28:32 -07:00
Mattijs Korpershoek 4ae75eef16 cpp: use -nostlib++ instead of -nostlib for custom cpp_stdlib
The <lang>_stdlib can be used in cross files to use a custom standard library
for a given language.

When cpp_stdlib is used in a cross file, meson passes
* -nostdinc++ to the compiler
* -nostlib to the linker

According to [1] (gcc) and [2] (clang), we should pass -nostlib++ to the linker
when we don't want to link to the standard C++ library.
Currently, we pass -nostlib.

Fix this by implementing a C++ specific get_no_stdlib_link_args() function.

[1] https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#index-nostdlib_002b_002b
[2] https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-nostdlib
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-10-12 20:15:42 +05:30
Benjamin Redelings 84b8d257e4 Allow c++23 in gcc-11. 2023-10-09 23:53:31 +03:00
Marvin Scholz dec4f72da4 clike compilers: use MesonBugException instead of AssertionError
Follow-up to #12223
2023-10-04 08:15:42 -04:00
Eli Schwartz 5b317c5658
compilers: use correct version comparison for openbsd libraries
It should *be* a version comparison. We are guaranteed to get a
two-element version number, which also parses as a float but a float
doesn't correctly handle version sorting when the second component
differs in number of digits.

The standard way to handle this is by comparing tuples such that each
component is an integer. Do so here.

Fixes #12195

Co-authored-by: George Koehler <xkernigh@netscape.net>
(for unittests)
2023-09-26 02:36:15 -04:00
Alan Brooks c1ac252f4f fix bug where all java builds & tests fail to run SanityCheck on JDK11
Needed a classpath set in the current working directory.
This was on a Zulu build of OpenJDK 11.0.17 on a macOS ARM machine.

The errors folks might encounter:
Error: Could not find or load main class SanityCheck
Caused by: java.lang.ClassNotFoundException: SanityCheck
2023-09-25 18:27:24 +03:00
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
Steven Noonan 54950544c2 objective-c++: add support for current supported standards in Apple Clang
Pulled from this list on Xcode 15 beta:

    $ clang -E -dM -xobjective-c++ -std=arglbargle -o - /dev/null
    error: invalid value 'arglbargle' in '-std=arglbargle'
    note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
    note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
    note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
    note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
    note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
    note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
    note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
    note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
    note: use 'c++20' for 'ISO C++ 2020 DIS' standard
    note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
    note: use 'c++2b' for 'Working draft for ISO C++ 2023 DIS' standard
    note: use 'gnu++2b' for 'Working draft for ISO C++ 2023 DIS with GNU extensions' standard

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2023-09-21 12:41:39 +03:00
Xavier Claessens 7321f01678 Rust: Use Popen_safe_logged in sanity checks 2023-09-19 13:54:49 -04:00
Nomura 2b4002e60f
Metrowerks assembler should not inherit opt args from mixin
The Metrowerks assembler does not support optimization flags.
However, it received the same opt args as the Metrowerks C and C++
compilers, because it inherits from the 'MetrowerksCompiler' mixin.
This broke builds with opt level higher than 0 that used the Metrowerks
Assembler, as the latter received unsupported args. This is now fixed.
2023-09-18 02:11:06 -04:00
Nomura 319b1505e8
Metrowerks: set optlevel 3 to max optimization args
According to the Meson documentation, optimization level 3 should
set the highest possible optimization for the compiler in use.
In Metrowerks, this is 'O4,p'. However, Meson's Metrowerks
implementation mapped opt level 3 to '-O3'. This has been fixed.
2023-09-18 02:11:01 -04:00
Nomura e7ed45396d
Metrowerks: remove duplicate optimization args
The args were in both buildtype and optimization. This broke buildtypes other
than plain or custom unless manually setting the optimization level to
0, because Metrowerks chokes on duplicate arguments.
2023-09-18 02:10:59 -04:00
Moody Liu 3c47216fe9 clike compilers: fix cross_* functions' include
A standard C library may not exist for cross-compile
environments, thus the existence of <stdio.h> cannot be
guaranteed.

Use <stddef.h> instead, this header contains compiler-specific
defines thus it usually comes from the compiler.
2023-09-09 07:25:27 -04:00
Xavier Claessens d5f17bc9ff Rename OptionOverrideProxy to OptionsView and move to coredata
Coredata is where all option handling is done so it makes sense there.
It is a view on a list of options for a given subproject and with
optional overrides. This change prepare for using that view in a more
generic way in the future.
2023-09-07 06:55:07 -04:00
Marvin Scholz 3fc16f05b5 Add compiler.has_define
Adds a new method to the compiler object, has_define.
This makes it possible to check if a preprocessor macro/define
is set or not.

This is especially helpful if the define in question is empty,
for example:

  #define MESON_EMPTY_DEFINE

This would yield the same results as a missing define with
the existing get_define method, as it would return an empty
string for both cases. Therefore this additional method is
needed.
2023-09-07 00:45:38 +03:00
Filipe Laíns 025bcc0d9d compilers: fix compiler detection when the "ccache" string is in the path
Signed-off-by: Filipe Laíns <lains@riseup.net>
2023-09-01 02:09:21 -04:00
Jussi Pakkanen 08d83a4a97
Merge pull request #10332 from xclaesse/std-opt
c_std, cpp_std: Change to a list of desired versions in preference order
2023-08-30 12:04:09 -07:00
Benoit Pierre bde690b06e compilers: fix checks handling of internal dependencies
The include directories were not passed to the compiler.
2023-08-22 09:40:30 -04:00
Eli Schwartz 90ce084144
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04:00
Eli Schwartz a01418db0a
remove useless type annotations
These annotations all had a default initializer of the correct type, or
a parent class annotation.
2023-08-11 13:37:17 -04:00
Charles Brunet 711e4e3b06 Optimize CLikeCompiler._get_file_from_list()
Simplify and optimize the function. When not on Mac OS, it was iterating two times the list when there were no files in it.
2023-08-09 09:44:15 -04:00
kiwixz 3de0f6d4e9 clang: use gcc syntax to enable diagnostics color
clang has supported gcc syntax since version 3.3.0 from 10 years ago.
It's better than its own version because it takes a "when" verb which
allows us to explicitely ask for "auto".  This is useful when overriding
flags that came from elsewhere.

Before this patch, meson was just treating b_colorout="auto" as "always".
2023-08-08 16:46:03 -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
Xavier Claessens 48c17b7ae6 UserArrayOption: Remove user_input argument
The only place it can be set to False is from optinterpreter. Better
check value there and deprecate string usage.
2023-08-06 09:39:55 -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
Dylan Baker 1a182ab599 make 'gui_app' an interpreter only concept
Since it's deprecated anyway, we don't really want to plumb it all the
way down into the build and backend layers. Instead, we can just turn
it into a `win_subsystem` value in the interpreter if `win_subsystem`
isn't already set.
2023-07-25 13:29:08 -04:00
Eli Schwartz 7afc69254d
fix implicit_reexport issues and enforce them going forward
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
2023-07-19 18:31:37 -04:00
Jussi Pakkanen 0dba7340ec
Merge pull request #11976 from tristan957/cleanups
Some various type related cleanups
2023-07-17 00:29:37 +03:00
Dylan Baker 76eba99850 rust: disable overflow-checks by default
These result in very large binaries when linked, and are not generally
useful. A user can turn them back on by passing `-C overflow-checks=yes`
manually via `-Drust_args` or the `RUSTFLAGS` environment variable

fixes: #11785
2023-07-15 12:22:30 -07: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 24edddb412 Fix return type of debugfile functions
It was returning None in some cases while being marked as returning
string.
2023-07-12 18:56:06 -05:00
Tristan Partin c1863f781b Remove Compiler._build_wrapper(temp_dir:)
The function wasn't using the keyword argument and all the callers were
using env.scratch_dir anyway.
2023-07-12 18:56:06 -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 9e8a034ade Fix the typing around Compiler._get_compile_output()
This function says it returns a string, but was returning None in some
cases.
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 921c2370a7 Replace some type comments with annotations 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
Eli Schwartz e2ce53b6b4
compilers: detect cython version on stdout for newer cython versions
Cython historically, when asked to print the version and exit
successfully, would do so on stderr, which is weird and inconsistent.
Recently, it fixed this UX bug by printing on stdout instead:

https://github.com/cython/cython/issues/5504

This then broke meson detection because we assumed it was on stderr due
to historically being there:

https://github.com/scipy/scipy/issues/18865

Cython is right, and shouldn't have to revert this reasonable change for
backwards compatibility. Instead, check both.
2023-07-12 15:56:51 -04:00
Tristan Partin ab21dc0384 Remove type comments from compilers.py 2023-07-12 14:47:30 -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
Xavier Claessens d140342c14 comp.preprocess(): Do not treat every file as assembly
Fixes: #11940
2023-07-05 21:34:25 +03:00
Jussi Pakkanen d391e5281c
Merge pull request #11742 from xclaesse/link-whole-cases
Fix niche cases when linking static libs
2023-07-05 01:10:58 +03:00
Kacper Michajłow 9dd5f0ae69 compilers: strip get_define output
Fixes get_define() for MSVC. cl with /std:c11 and newer add a trailing
space character when substituting, even if macro is empty. This breaks
parsing preprocessed output to extract value. Since they cannot contain
spaces it is safe to simply strip parsed value.

Fixes: #10179
2023-07-04 16:29:15 -04:00