Commit Graph

358 Commits

Author SHA1 Message Date
Eli Schwartz d57ca7d2a2
compilers: improve a comment describing why we add a silly clang workaround
Clang is such a great compiler! Not.

Compilers have enhanced diagnostics for some kinds of "well known"
undeclared identifiers, telling you exactly which header you might have
forgotten to include. The reason why clang needs an option GCC doesn't
need is because clang's fixit suggestions, unlike GCC's actually
*changes the type of the error*, as a result of a fixit of all things.

After the fixit suggestion grants this error the right to be ignored,
we start having to add clang-specific options.

Follow-up to https://github.com/mesonbuild/meson/issues/9140

Upstream clang bug, which appears to be going nowhere:
https://github.com/llvm/llvm-project/issues/33905
2024-05-24 17:10:32 -04:00
Jussi Pakkanen 5365d9a842 Refactor option classes to their own file. 2024-05-23 21:26:45 +03:00
Tristan Partin cb1068a288 Catch Python exception in the event alignment can't be converted to int
The user almost certainly has to be using a compiler wrapper script that
doesn't actually work if we land here.

Fixes: #12982
2024-04-25 18:49:57 -04:00
Jussi Pakkanen f233b7b98d
Merge pull request #12808 from U2FsdGVkX1/master
Fix ninja cannot find the library when libraries contain symlinks.
2024-04-22 16:04:46 +03:00
L. E. Segovia 8239912379 compilers: Ensure -L flags do not get reordered when used with MSVC
If -L flags get into CLikeCompiler::build_wrapper_args, they will be
correctly detected and the /LINK flag added to the list. However,
CompilerArgs::__iadd__ will reorder them to the front, thinking they're
GNU-style flags, and this will cause MSVC to ignore them after
conversion.

The fix is twofold:

1. Convert all the linker args into their compiler form, making sure the
   /LINK argument is dropped (see 2)
2. Insert /LINK into extra_args if not already present
3. Execute in situ the unix_to_native replacement, ensuring no further
   reordering occurs.

Fixes #11113
2024-04-05 15:11:52 -07:00
Jussi Pakkanen 30c38e2bd6
Merge pull request #12144 from amyspark/fix-msvc-clangcl-linker-flag-detection
linkers: Fix detection of link arguments to Clang(-cl) + MSVC
2024-04-05 00:08:09 +03:00
Sam James 5bd28febf7
Pass Environment down from Backend
We'll need it in a moment for get_base_compile_args -> get_assert_args.

Bug: https://github.com/mesonbuild/meson/issues/12962
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-28 00:52:25 -04:00
Charles Brunet dacb25db10 Improve error messages for invalid option values
By adding the option name to UserOption object, it is now possible to
display the name of the affected option when the given option value is
not valid.

Fixes #12635
2024-03-15 09:23:46 -07:00
Xavier Claessens c1076241af compilers: No need to pass exe_wrapper everywhere
Places where compiler needs it already have access to Environment object
and can use it directly.

This fixes mypy complaining that not all compilers have self.exe_wrapper
in run() method that got moved to base class.
2024-03-15 11:38:54 -04:00
Xavier Claessens f41a95ddf2 compilers: Every compiler can run code
Compiling and linking code is part of the Compiler base class, there is
no reason it cannot also run executables.
2024-03-15 11:38:54 -04:00
Petr Machacek eb74bb8dbf Added support for Texas Instruments C6000 compiler. 2024-03-12 20:38:30 +02:00
Elliot e4622ff1ee
Only link to generated pch object when using msvc. (#12957)
backend: Only link to generated pch object when using msvc
2024-03-11 11:23:33 -07:00
Eli Schwartz 4d1bfd0939
compilers: only wrap multiple input libraries with start/end group
When only a single input file shows up in an arglist, it makes no sense
to inject `-W,--start-group -lone -Wl,--end-group`, since there is
nothing being grouped together. It's just longer command lines for
nothing.
2024-03-03 13:42:58 -05:00
Eli Schwartz 46f3cff5b2
compilers: avoid catching -Wl,-soname and wrapping with start/end group
This is just a bad regex match, because it matches *.so as a prospective
filename input even though it is actually not an input but a linker
flag. --start-group is only relevant to input files...
2024-03-03 13:42:58 -05:00
L. E. Segovia c5254429e4 clang: Fix tests that use /DEF for MSVC LINK.exe 2024-02-25 10:48:45 -03:00
L. E. Segovia 3366756c0f compilers: Forward Meson's preference of lld-link to clang-cl
The latter prefers LINK.exe by default, which rejects GNU-like linker
flags.
2024-02-25 10:48:45 -03:00
L. E. Segovia a33c599f78 linkers: Fix detection of link arguments to Clang(-cl) + MSVC
Currently, not only Meson lacks a way to induce a "--fatal-warnings" on
LINK.exe, it is also unable to pass flags appropriately when using
clang-cl or Microsoft's stock clang.

This commit fixes it by implementing `fatal_warnings()` in the
MSVCDynamicLinker and ClangCLDynamicLinker classes, and by implementing
the requisite conversion steps in linker_to_compiler_args for
ClangCompiler.
2024-02-25 10:48:44 -03:00
U2FsdGVkX1 7a60218dca
Turn on strict mode, as it is no longer the default since Python 3.6 2024-02-05 17:24:21 +08:00
U2FsdGVkX1 91caf7aa56
Fix ninja cannot find the library when libraries contain symlinks. 2024-02-04 14:07:54 +08:00
Eli Schwartz 2fbc7b5ce3
Revert "clike: Deduplicate rpath linker flags"
This reverts commit 53ea59ad84.

This breaks at least:
- frameworks/17 mpi
- frameworks/30 scalapack

The problem is that openmpi's pkg-config emitted link arguments
includes:

```
-Wl,-rpath -Wl,/path/to/libdir
```

The deduplication logic in meson doesn't contain sufficient information
to tell when the compiler is passing an argument that requires values,
and definitely cannot tell when that argument is split across argv. But
for arguments that *can* do this, it is not possible to deduplicate a
single argument as standalone, because it is not standalone.

The argument for deduplicating rpath here was that if you have multiple
dependencies that all add the same rpath, the Apple ld64 emits a
non-fatal warning "duplicate -rpath ignored". Since this is non-fatal,
it's not a major issue. A major issue is when builds fatally error out
with:

```
FAILED: scalapack_c
cc  -o scalapack_c scalapack_c.p/main.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group /usr/lib64/libscalapack.so /usr/lib64/liblapack.so /usr/lib64/libblas.so -Wl,-rpath -Wl,/usr/lib64 -Wl,/usr/lib64 -Wl,--enable-new-dtags /usr/lib64/libmpi.so -Wl,--end-group
/usr/libexec/gcc/x86_64-pc-linux-gnu/ld: error: /usr/lib64: read: Is a directory
```
2023-12-26 18:09:34 -05:00
Charles Brunet 4761e4cad9 Remove `get_buildtype_args` function
This is a first step to make `buildtype` a true alias of `debug` and
`optimization` options.

See #10808.

Relates to:
- #11645
- #12096
- #5920
- #5814
- #8220
- #8493
- #9540
- #10487
- #12265
- #8308
- #8214
- #7194
- #11732
2023-12-23 13:32:49 +02:00
Denis Drakhnia 360d81e4aa compilers/elbrus: wrap get_default_include_dirs with lru_cache 2023-12-23 00:31:53 -08:00
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Eli Schwartz 39ecfc2d54
compilers: drop dead code
no_warn_args is unused. Its only purpose was to implement automatic
hiding of UB in transpiled code, and it was not used at all in languages
other than C/C++ -- specifically when the C/C++ source files were
created by transpiling from vala or cython.
2023-12-05 19:52:23 -05:00
Eli Schwartz caa38dad45 fix broken type annotation imports being ignored
If an annotation could not be resolved, it's classified as a "missing
import" and our configuration ignored it:

```
Skipping analyzing "mesonbuild.backends": module is installed, but missing library stubs or py.typed marker
```

As far as mypy is concerned, this library may or may not exist, but it
doesn't have any typing information at all (may need to be installed
first).

We ignored this because of our docs/ and tools/ thirdparty dependencies,
but we really should not. It is trivial to install them, and then
enforce that this "just works".

By enforcing it, we also make sure typos get caught.
2023-11-26 17:12:52 -05:00
Fini Jastrow 30ab9747ae clike: Deduplicate rpath linker flags
[why]
On Apple clang 15.0.0 linker (i.e. ld64 1015.7) giving the same rpath
multiple times raises a warning:

ld: warning: duplicate -rpath '/local/lib' ignored

This can frequently happen when linking several dependencies that all
have that rpath in e.g. pkgconfig.

[how]
Deduplicate all rpath arguments.

[note]
I'm not sure how the code handles --start/end-group, but for rpath that
should not make any difference as that is not bound to a group.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-11-22 22:11:50 +02:00
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
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
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
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
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
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
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
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 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
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