Commit Graph

390 Commits

Author SHA1 Message Date
Paolo Bonzini 8b9846d9a9 mtest: move determine_worker_count to utils, generalize
It is useful to apply a limit to the number of processes even outside "meson test",
and specifically for clang tools.  In preparation for this, generalize
determine_worker_count() to accept a variable MESON_NUM_PROCESSES instead of
MESON_TESTTHREADS, and use it throughout instead of multiprocessing.cpu_count().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19 09:25:20 -08:00
LIU Hao e542901af6 compilers: Pass `vs_module_defs` with `/DEF:` to LLD-LINK
Recently, it is possible to install Clang with Visual Studio Installer. By
default this Clang has a MSVC target, and invokes the Microsoft Linker; if
`-fuse-ld=lld` is specified, it will invoke LLD-LINK. Both linkers take
MSVC-style arguments, and take DEF files with `/DEF:<path>`.

Previously DEF files were passed in the GNU way, directly on the linker
command line like an object file, which caused errors like

   lld-link: error: ..\my.def: unknown file type

While Clang-CL takes Unix-style options, it actually passes MSVC-style
options to LINK or LLD-LINK with `-Wl,`. There is already a check for both
linkers in `linker_to_compiler_args()`, so it's necessary to do the same
in `gen_vs_module_defs_args()`.

This commit closes https://github.com/mesonbuild/meson/issues/13988.

Signed-off-by: LIU Hao <lh_mouse@126.com>
2024-12-10 19:42:06 -08:00
Jussi Pakkanen 467da051c8 Add VS preview version. 2024-11-27 12:44:29 +02:00
Paolo Bonzini 1b15bd0343
compilers: avoid one or more version_compare per target
version_compare can take a few milliseconds.  If you have a thousand object files
or a multiple thereof, it adds up.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-11-19 23:47:34 -05:00
Eli Schwartz 6091ef0f5a
Revert "meson: De-dup rpath arguments"
This reverts commit 8242187eb0.

This same change was previously introduced in #12495 / commit
30ab9747ae and subsequently reverted
in #12672 / commit 2fbc7b5ce3

Reintroduced in #13819 but it's still the same old problem. To repeat
the problem:

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
```

Today we have CI for this so the change actually caused our own unittest
CI to go red.
2024-10-31 17:31:26 -04:00
Nirbheek Chauhan 8242187eb0 meson: De-dup rpath arguments
This fixes spammy warnings on apple clang:

ld: warning: duplicate -rpath 'build/dist/darwin_universal/arm64/lib/pkgconfig/../../lib' ignored
2024-10-31 22:03:59 +05:30
Jussi Pakkanen 1feb771f06
Merge pull request #13681 from EngJay/13678-fix-ti-cgt-support
Fix TI C2000 support
2024-10-30 12:05:41 +02:00
Jason Scott 6e9e344bcf add c2000 to ti library naming conditional so static libs are found 2024-10-16 10:51:13 -04:00
Dylan Baker 3728b228a6 compilers: remove hasattr from `can_compile_suffixes`
This is never set outside the `Compiler.__init__`, only added to. As
such there's no reason to have this `hasattr` check. It's wasting time
*and* confusing our static checkers.
2024-10-01 10:39:23 -07:00
mid-kid ddc03e5ab3 metrowerks: Pass warning flags to all subtools
The "on" option is documented as passing the warning flags to all
subtools, and implies "most".
The default in the majority of projects is -warnings on,nocmdline, which
I'd take to be the equivalent of -Wall -Wextra, there isn't really an
inbetween.
2024-09-29 21:32:50 +03:00
mid-kid 3f135284c7 metrowerks: Fix compute_parameters_with_absolute_paths 2024-09-29 21:32:50 +03:00
Andrew McNulty 9cb9ad88da compilers: Pass mode to determine_args, not its string value
We always pass the string value of the mode to determine_args, which
causes the check on the mode argument inside determine_args to always
evaluate to false.

Fix this by passing the mode itself, not its value.
2024-09-17 00:47:17 -07:00
Thomas Haller fa8bd9306c compilers: avoid -Wunused-value compiler warning in CLikeCompiler.has_type()
Otherwise, `CFLAGS='-Wall -Werror' meson build` can fail detection:

  Running compile:
  Working directory:  ./project/build/meson-private/tmpk86bgc04
  Code:
   #include <sys/types.h>
          void bar(void) {
              sizeof(loff_t);
          }
  -----------
  Command line: `cc ./project/build/meson-private/tmpk86bgc04/testfile.c -o ./project/build/meson-private/tmpk86bgc04/output.obj -c -Werror -Wall -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  ./project/build/meson-private/tmpk86bgc04/testfile.c: In function 'bar':
  ./project/build/meson-private/tmpk86bgc04/testfile.c:3:13: error: statement with no effect [-Werror=unused-value]
      3 |             sizeof(loff_t);
        |             ^~~~~~
  cc1: all warnings being treated as errors
  -----------
  Checking for type "loff_t" : NO
2024-09-11 09:36:53 -04:00
Thomas Haller a22a50a673 compilers: avoid -Wunused-value compiler warning in CLikeCompiler.has_members()
Otherwise, `CFLAGS='-Wall -Werror' meson build` can fail detection:

          void bar(void) {
              struct stat foo;
              foo.st_mtim.tv_nsec;

          }
  -----------
  Command line: `cc ./project/build/meson-private/tmpqz_gi65d/testfile.c -o ./project/build/meson-private/tmpqz_gi65d/output.obj -c -O3 -Werror -Wall -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  ./project/build/meson-private/tmpqz_gi65d/testfile.c: In function 'bar':
  ./project/build/meson-private/tmpqz_gi65d/testfile.c:45:24: error: statement with no effect [-Werror=unused-value]
     45 |             foo.st_mtim.tv_nsec;
        |             ~~~~~~~~~~~^~~~~~~~
  cc1: all warnings being treated as errors
2024-09-11 09:36:53 -04:00
Elliot 18427adbf2 Add lto support to clang-cl and lld-link
Enables lto & thinlto support for clang-cl when used with lld-link.
2024-08-30 14:59:54 -07:00
L. E. Segovia 761e2470d4 compilers: Allow prelinking with Apple Clang 2024-08-26 01:05:42 +03:00
Junjie Mao 85e92331cb compilers: do not strip '-isystem' from C build arguments
Meson accidentally strips '-isystem' from C build args like ['-isystem',
'/path/to/headers'] if the compiler includes the current working directory
in the header search paths. The root cause is that '-isystem'[8:] evaluates
to an empty string and os.path.realpath('') returns the absolute path to
the current working directory, causing meson to think that '-isystem'
specifies a default include path.

Different compiler versions varies whether the current working directory is
in its search paths. For example, on Ubuntu 21.04:

  # gcc -xc -v -E -
  gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  #include "..." search starts here:
  #include <...> search starts here:
   .
   /usr/lib/gcc/x86_64-linux-gnu/10/include
   /usr/local/include
   /usr/include/x86_64-linux-gnu
   /usr/include
  End of search list.

While on Ubuntu 24.04:

  # gcc -xc -v -E -
  gcc version 13.2.0 (Ubuntu 13.2.0-23ubuntu4)
  ...
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/lib/gcc/x86_64-linux-gnu/13/include
   /usr/local/include
   /usr/include/x86_64-linux-gnu
   /usr/include
  End of search list.

Do not check the '-isystem=' and '-isystem/path/to/header' cases when the
option is '-isystem' but the path that follows is not a default search
path.

Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
2024-08-15 02:24:50 -04:00
Jonathan Schleifer 81b151f611 Fix compiling ObjC/ObjC++ on Windows/MinGW
Co-Authored-By: L. E. Segovia <amy@amyspark.me>
2024-08-08 15:56:43 -07:00
Kacper Michajłow 3702b4bdb3 compilers: change get_argument_syntax to static method
This allows to get this fixed value before the class is initialized.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2024-08-07 10:33:08 -04:00
Eli Schwartz 4a352dd8bd
flake8: move unused typing-only imports to TYPE_CHECKING 2024-07-30 14:13:11 -04:00
Sam James 7a306e1a46 compilers: handle -Wno-attributes= for GCC
For other reasons, Meson transforms "-Wno-x" into "-Wx -Wno-x" for GCC,
but this breaks with "-Wno-attributes=x" with:
```
cc1plus: error: arguments ignored for '-Wattributes='; use '-Wno-attributes=' instead
```

Suppress that workaround for -Wno-attributes=.

Closes: https://github.com/mesonbuild/meson/issues/13022
2024-07-19 01:36:41 -04:00
Jussi Pakkanen 61c742fae9 Remove language (AKA compiler) type from OptionKey. 2024-07-17 18:37:51 +03:00
Christoph Reiter d9e2dd6c80 Revert various cross compile changes
c1076241af changed the logic in multiple
places, in particular it looks like it was assumed that is_cross is always
the same as need_exe_wrapper(), but that's not true.

Also the commit only talks about mypy, so this was definitely not intended.

This reverts all the cases where need_exe_wrapper() was introduced back to
is_cross.

The change in backends.py could be a correct simplification, but I don't know
the code base enough, so reverting that too.

See #13403 and #13410
2024-07-16 02:01:21 -04:00
Jussi Pakkanen 0d7bb776e2 Move OptionKey in the option source file. 2024-07-11 11:53:39 +03:00
Dylan Baker d6bddafa26 compilers: Add support for OpenMP from homebrew with AppleClang
Which requires injecting some extra paths and the `-Xpreprocess` flag,
as well as extra search paths for libomp and the headers.

Fixes: #7435
2024-06-26 16:15:47 -04:00
Dylan Baker f900b3270b compilers|dependencies: Move Clang-CL specific logic out of OpenMP dep
And into the Clang-CL mixin.
2024-06-26 16:15:47 -04:00
Dylan Baker 87681980bc compilers: pass Environment to openmp_flags
This will be needed by the Apple compiler
2024-06-26 16:15:47 -04:00
Sam James 2a9f40ff7a
compilers: make lang_map public 2024-06-24 00:36:40 +01:00
Sam James 4ad792e158
compilers: detect: fix pre-processor scraping by defining language
_get_gnu_compiler_defines and _get_clang_compiler_defines were broken
by not defining the language they used.

Neither GCC nor Clang infer the language based on the driver name which means
`self.defines` isn't populated correctly in compilers/cpp.py.

e.g.
```
 $ echo "" | g++ -E -dM - | grep -i cplus

 $ echo "" | g++ -x c++ -E -dM - | grep -i cplus
 #define __cplusplus 201703L
```

Fix that by passing '-cpp -x LANGUAGE' as a first pass. If it fails, try
again without '-cpp -x LANGUAGE' as before, as its portability isn't
certain. We do '-cpp' because during testing, I found Fortran needs this,
although per below, I had to drop Fortran in the end and leave it to the
fallback (existing) path.

Without this change, a63739d394 is only
partially effective. It works if the system has injected Clang options
via /etc/clang configuration files, but not by e.g. patching the driver
(or for GCC there too).

Unfortunately, we have to wimp out for Fortran and fallback to the
old method because you need the language standard (e.g. -x f95).
2024-06-24 00:36:06 +01:00
Jussi Pakkanen 181c3499fd Fix mypy. 2024-06-14 17:19:53 +03:00
Jussi Pakkanen 9a6fcd4d9a Replace direct indexing with named methods. 2024-06-14 17:19:53 +03:00
Jussi Pakkanen c0d86024f5 Rename option variable to optstore to make it unique. 2024-06-14 17:19:53 +03:00
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