Commit Graph

913 Commits

Author SHA1 Message Date
David Seifert b6e5683764 cuda: disable thin archives when 'cuda' is enabled globally
Bug: mesonbuild/meson/pull/9453
Bug: mesonbuild/meson/issues/9479#issuecomment-953485040
2024-05-07 22:32:35 -07:00
Benjamin Gilbert 1684259f10 backend/ninja: use generate_basic_compiler_args() for C#, Java, Swift
C#, Java, and Swift targets were manually collecting compiler arguments
rather than using the helper function for this purpose.  This caused each
target type to add arguments in a different order, and to forget to add
some arguments respectively:

C#:    /nologo, -warnaserror
Java:  warning level (-nowarn, -Xlint:all, -Xdoclint:all), debug arguments
       (-g, -g:none), -Werror
Swift: -warnings-as-errors

Fix this.  Also fix up some no-longer-unused argument processing in the
Compiler implementations.
2024-04-27 08:09:03 -07:00
Dylan Baker 27dc1bcacb backend/ninja: use re.match instead of re.search
Since we've already determined that the first character is the start of
the expression anyway.
2024-04-24 20:40:34 -07:00
Dylan Baker f603a266ec backend: fix type annotation of Backend.generate
`func(value: dict = None)` is invalid, it must be `func(value: dict |
None = None)`, or in our older syntax: `T.Optional[T.Dict] = None`
2024-04-24 20:40:34 -07:00
Dylan Baker cf0fecfcef backend/ninja: Fix bug in NinjaRule.length_estimate
The code would create a dictionary that was of type `str : list[str] |
str | None`. Then would later try to call `len(' '.join(dict[key]))`.
This would result in two different bugs:

 1. If the value is `None` it would except, since None isn't iterable
    and cannot be converted to a string
 2. If the value was a string, then it would double the length of the
    actual string and return that, by adding a space between each
    character
2024-04-24 20:40:34 -07:00
Dylan Baker fb5a0b4b61 backend/ninja: add typing annotations to NinjaRule 2024-04-24 20:40:34 -07:00
Dylan Baker 9e3b3db705 backend/ninja: Fix cases where None is passed when unexpected
When getting debug file arguments we can sometimes pass None, where a
None is unexpected. This becomes a particular problem in the Cuda
compiler, where the output will unconditionally be concatenated with a
static string, resulting in an uncaught exception. This is really easy
to spot once we annotate the functions in question, where a static type
checker like mypy easily spots the issue.

This commit adds those annotations, and then fixes the resulting error.

Fixes: #12997
2024-04-18 13:12:15 -07:00
Jussi Pakkanen 516a485136
Merge pull request #13021 from dcbaker/submit/depscanner-fixes-and-speedups
Cleanups, fixes, and speedups for the depscanner
2024-03-29 23:54:06 +02:00
Dylan Baker 2171a017be backend/ninja: Don't run -t cleandead when using dyndeps
There's a known ninja bug
(https://github.com/ninja-build/ninja/issues/1952) that running this
with dyndeps will result in Ninja deleting implicit outputs from the
dyndeps, leading to pointless rebuilds. For reference, this is what
CMake does as well.
2024-03-29 13:06:54 -07:00
Dylan Baker 2f8d51c833 backend/ninja: don't rewrite the pickle data if it hasn't changed
Which prevents spurious rebuilds of dyndeps
2024-03-29 13:06:54 -07:00
Dylan Baker 433117fc5a scripts/depscan: pick language once, at configure time
We already have to decide whether to scan a file at configure time, so
we don't want to have to do it again at compile time, every time the
depscan rule is run. We can do this by saving and passing the language
to use in the pickle, so depscan doesn't have to re-calculate it. As an
added bonus, this removes an import from depscan
2024-03-29 13:06:54 -07:00
Dylan Baker fae1363bd3 scripts/depscan: combine pickle and JSON data into a single file
We don't need to write and pass two separate files to the depscanner,
I've used the pickle because the pickle serializer/deserializer should
be faster than JSON, thought I haven't tested.
2024-03-29 13:06:54 -07:00
Dylan Baker 934c9074bd backend/ninja: add missing typing annotations 2024-03-28 15:30:16 -07:00
Dylan Baker 875a9b789f backend/ninja: remove duplicate isinstance() check 2024-03-28 15:30:16 -07:00
Dylan Baker 2812b21de5 backend/ninja: use A dataclass for TargetDependencyScannerInfo 2024-03-28 15:30:16 -07: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
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
Xavier Claessens 5e0a3073da rust: Link with rlib external dependencies
When linking with a Rust rlib, we should also link with its external
system dependencies. This was currently done only for C ABI crates, do
it for both rlib and staticlib now.
2024-03-05 09:18:32 -05:00
dragonmux 5495dc4315 backend/ninjabackend: Implemented logic for passing the discovered gcovr and llvm-cov along to the code coverage backend 2024-02-24 11:35:02 -08:00
dragonmux cfada46694 scripts/coverage: Implemented handling for passing the gcovr and llvm-cov binaries to use to the script 2024-02-24 11:35:02 -08:00
Stephan Lachnit 43fe006190 Fix warning when using scan-build
Using scan-build gives the following warning:

"Running the setup command as `meson [options]` instead of
`meson setup [options]` is ambiguous and deprecated."

This commit fixes this issue by adding the setup keyword to the meson command.
2024-02-19 09:12:12 -05:00
Stas Sergeev 92f638e1f9 compiler.preprocess: add depends kwarg
This patch adds 'depends' keyword to compiler.preprocess().
It allows to execute other targets before doing the preprocessing.
Test-case is added to demonstrate that functionality: it
generates the header before preprocessing the C source that
uses that generated header.

Thanks to @bruchar1 for getting this patch to work.
2024-01-17 13:37:36 -08:00
Alyssa Ross 1ca2c74d16 rust: fix linking static executables
For the same reason as for static libraries, we have to use -l when
generating static executables.

Fixes: https://github.com/mesonbuild/meson/issues/12585
2024-01-17 13:36:15 -08:00
Valeri ae857e841b
Vala: fixes to gresource handling (#12418)
* Vala: depend on gresources

Valac uses gresource at compile time to look up .ui files

* Automatically pass `--gresourcesdir` to valac

* gnome.compile_resources: clean up duplicate paths better

* Add a test for improved gresouce handling
2024-01-11 17:55:02 +02:00
byteblob ce2db13e94 ninja: Use platform dependent quote instead of shlex.quote() in gcc_rsp_quote() 2024-01-09 10:40:58 -08:00
wrvsrx d4fb2d693d ninja backend: manually escape cuda target name
Nvcc doesn't support `-MQ` flag, so we have to manually escape cuda
target name.
This commit escape `$out` to `$CUDA_ESCAPED_TARGET`, so now we can just
use `-MT` flag in nvcc to generate header dependencies.
2023-12-26 23:37:27 -05:00
Sergey Vlasov 5ff6049945 swift: Support swift_args
Fixes #12533
2023-12-26 10:33:08 -08: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
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
Daniele Nicolodi 5883089f6c ninja backend: Remove outdated comment
Generation of both C and C++ from Cython is supported via the
cython_language option.
2023-12-09 23:45:05 -08:00
Daniele Nicolodi 76ab2db086 ninja backend: Adjust naming and comments
Meson supports other transpilers generating source code for which
compilation rules need to be generated other than Vala. Reflect this
in variable names and comments to avoid confusion.
2023-12-09 23:45:05 -08:00
Daniele Nicolodi c2ea14fbd2 ninja backend: Make values passed to bool argument consistent 2023-12-09 23:45:05 -08:00
Daniele Nicolodi 7fbadfdeab ninja backend: Remove always true check 2023-12-09 23:45:05 -08:00
Eli Schwartz 5f659af870
ninja backend: don't hide all compiler warnings for transpiled languages
This was originally added for vala only, with the rationale that vala
generates bad code that has warnings. Unfortunately, the rationale was
fatally flawed. The compiler warns about a number of things, which the
user can control depending on their code (or their code generator's
code), but some of those things are absolutely critical to warn about.

In particular, GCC 14 and clang 17 are updating their defaults to warn
-- and error by default for -- invalid C code that breaks the standard,
but has been silently accepted for over 20 years "because lots of people
do it". The code in question is UB, and compilers will generate faulty
machine code that behaves erroneously and probably has a mass of CVEs
waiting to happen.

Compiler warnings are NOT safe to just... universally turn off. Compiler
warnings could be either:

- coding style lints

- threatening statements that the code is factually and behaviorally wrong

There is no magic bullet to ignore the former while respecting the
latter. And the very last thing we should ever do is pass `-w`, since
that causes ALL warnings to be disabled, even the manually added
`-Werror=XXX`.

If vala generated code creates warnings, then the vala compiler can
decrease the log level by generating better code, or by adding warning
suppression pragmas for *specific* issues, such as unused functions.
2023-12-05 19:51:56 -05:00
Xavier Claessens 2da53e943a rust: Add transitive dependencies to ninja rules
In the case r1 -> s1 -> s2 where s1 and s2 are uninstalled C static
libraries, the libs1.a rule does not depend on libs2.a. That means that
r1 rule must depend on both s1 and s2.
2023-11-13 23:17:14 +02:00
Xavier Claessens bd99f0bf1c rust: Make sure -l and -L are a single arg
CompilerArgs would otherwise dedup and reorder them.
2023-11-09 16:20:01 -05:00
Xavier Claessens d25d8e2772 rust: Fix linking with C libraries (again)
Pass link arguments directly down to linker by using `-C link-args=`
instead of letting rustc/linker resolve `-l` arguments. This solves
problems with e.g. +verbatim not being portable. Note that we also pass
`-l` args as `-Clink-args=-l` because rustc would otherwise reorder
arguments and put `-lstdc++` before `-Clink-args=libfoo++.a`.

However, when building a rlib/staticlib we should still use `-l`
arguments because that allows rustc to bundle static libraries we
link-whole. In that case, since there is no platform specific dynamic
linker, +verbatim works.

This also fix installed staticlib that now bundle uninstalled static
libraries it links to (recursively). This is done by putting them all
into self.link_whole_targets instead of putting their objects into
self.objects, and let rustc do the bundling. This has the extra
advantage that rustc can bundle static libries built with CustomTarget.

Disable bundling in all other cases, otherwise we could end up with
duplicated objects in static libraries, in diamond dependency graph
case.

Fixes: #12484
2023-11-09 16:20:01 -05:00
Xavier Claessens 91f2050813 rust: Add unique metadata id
This solves StableCrateId collision when using multiple versions of the
same crate.
2023-11-06 12:52:30 -05:00
Andrew McNulty 74712f2dbc scan-build: Exclude subprojects from scan-build report
When a user invokes the scan-build target that Meson generates
all subprojects are included in the resulting report. This commit
modifies the invocation of scan-build to exclude all bugs that
scan-build finds in the subprojects from the final report.

A release note has also been added describing the changed behaviour.
2023-11-02 18:41:51 -04:00
Xavier Claessens de03bf51d8 rust: Do not use +verbatim on MacOS
It seems broken and fails on our CI:
https://github.com/rust-lang/rust/issues/116674
2023-11-02 07:55:32 -04:00
Xavier Claessens 3500349df1 rust: Fix link arguments
Reduce code duplication by iterating target.get_dependencies() instead
of iterating target.link_targets and target.link_whole_targets
separately. This has the extra benefit of taking into account
transitive dependencies.

- For indirect C ABI static libraries, this adds missing "-l static="
  arguments.
- For indirect Rust ABI dependencies, this adds missing "-L" arguments.
- Verbatim modifier was used only for link_whole_targets, it's now
  always used when available.

Fixes: #11694
2023-11-02 07:55:32 -04:00
Aditya Vidyadhar Kamath f4d19db25e
Use target.aix_so_archive to decide to archive shared library in AIX
Previously, AIX support was updated to archive shared libraries per AIX
platform conventions, which expect .a files that contain .so files. This
is usually correct, but an edge case occurs for loadable plugins, e.g.
what meson creates for `shared_module()`. A notable example is python
extensions (SciPy, for example).

These should *not* be archived, because the .so file itself needs to be
loaded as a plugin. For example, SciPy fails to import in the python
interpreter.

Handle this by differentiating between plugins and regular libraries,
and only archiving when safe to do so.

Fixes #12219
2023-10-31 19:18:17 -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
Nirbheek Chauhan 4ebe03713d ninjabackend: Use the right ranlib for static linker rules
Fixes https://github.com/mesonbuild/meson/issues/12349
2023-10-12 09:31:04 -07:00
Ada 4c9927e8b7 Fix MSVC linker error LNK1170 with long rspfiles
The MSVC linker errors out if a line in the rspfile is too long.
The resolution is to use the built-in ninja keyword $in_newline instead of $in, which splits each input into separate lines.
2023-10-12 02:48:45 +05:30
Dylan Baker 523a27c6f0 build: Use typed_kwargs for language args
This also moves the repacking into the interpreter, making the build
implementation simpler and removing a layering violation. This also
makes use a defaultdict to remove the need to call `.get()`
2023-10-09 17:33:48 -04:00
Dylan Baker cbca191948 interpreter: Handle BuildTarget.vala_args as Files in the interpreter
Way back in Meson 0.25, support was added to `vala_args` for Files.
Strangely, this was never added to any other language, though it's been
discussed before. For type safety, it makes more sense to handle this in
the interpreter level, and pass only strings into the build IR.

This is accomplished by adding a `depend_files` field to the
`BuildTarget` class (which is not exposed to the user), and adding the
depend files into that field, while converting the arguments to relative
string paths. This ensures both the proper build dependencies happen, as
well as that the arguments are always strings.
2023-10-09 17:33:48 -04:00
Nigel Kukard 2c4a1b6324 Add support for lcov 2.0
lcov 2.0 deprecates `--rc lcov_branch_coverage=1` for `--rc branch_coverage=1` and
gives an error when an exclude is used on a non existing directory.

I added a version check for lcov and removed the subprojects directory from the
exclusion list if it does not exist.

Fixes #11995
2023-10-08 23:13:06 -04:00
Nomura 3cac6ea545 Add env kwarg in generator.process() 2023-10-05 09:59:43 -07:00