Commit Graph

106 Commits

Author SHA1 Message Date
Paolo Bonzini 8e564f16ae compilers: introduce common helper for sanity checks
Avoid reinventing the wheel and instead use a single helper, taking care
of logging and cross compilation.

Fixes: #14373
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-30 00:14:44 +03:00
Dylan Baker 390ea4624c coredata: move MutableKeyedOptionDict to options 2025-04-08 10:00:16 -07:00
Paolo Bonzini ff0c758b2a compilers: move -std options to get_option_std_args, special-casing CUDA
Move building the -std option to the new get_option_std_args method,
special casing CUDA to never include the option from the host compiler.
This fixes again #8523, which was broken by the option refactoring
(unsurprisingly, since the fix was ripped out unceremoniously without
a replacement).

Fixes: #14365
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-04 12:46:55 +03:00
Dylan Baker 251f74dcf3 coredata: remove get_option_for_subproject
This is just a wrapper around `OptionStore.get_option_for`, but without
taking an `OptionKey`. This complicates the subproject passing, since
`OptionKey` is designed to encapsulate the option name and subproject.
2025-03-10 14:14:25 -04:00
Patrick Steinhardt 43ea11ea49 compilers: convert `b_sanitize` to a free-form array option
In the preceding commit we have started to perform compiler checks for
the value of `b_sanitize`, which allows us to detect sanitizers that
aren't supported by the compiler toolchain. But we haven't yet loosened
the option itself to accept arbitrary values, so until now it's still
only possible to pass sanitizer combinations known by Meson, which is
quite restrictive.

Lift that restriction by adapting the `b_sanitize` option to become a
free-form array. Like this, users can pass whatever combination of
comma-separated sanitizers to Meson, which will then figure out whether
that combination is supported via the compiler checks. This lifts a
couple of restrictions and makes the supporting infrastructure way more
future proof.

A couple of notes regarding backwards compatibility:

  - All previous values of `b_sanitize` will remain valid as the syntax
    for free-form array values and valid combo choices is the same. We
    also treat 'none' specially so that we know to convert it into an
    empty array.

  - Even though the option has been converted into a free-form array,
    callers of `get_option('b_sanitize')` continue to get a string as
    value. We may eventually want to introduce a kwarg to alter this
    behaviour, but for now it is expected to be good enough for most use
    cases.

Fixes #8283
Fixes #7761
Fixes #5154
Fixes #1582

Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-03-09 18:06:14 -04:00
Patrick Steinhardt 42a8cfc32b compilers/cuda: fix checking for multiple linker args
When checking for multiple linker args we convert the supplied args to
flags that the compiler understands. But besides these supplied args, we
also try to convert linker flags that convert warnings into errors. This
mechanism causes an error though because we don't know to convert these
flags to linker flags:

    gcc: error: unrecognized command-line option '--warning-as-error'; did you mean '--warn-no-error'?
    -----------

    ERROR: Linker nvcc does not support sanitizer arguments ['-Xcompiler=-fsanitize=address\\,undefined']

As you can see, the flag is passed to the underlying compiler, not to
the underlying linker.

The obvious fix would be to convert them to linker flags, which we can
do by using `-Xlinker=` instead of `-Xcompiler=`. But that is incorrect,
too:

    /nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: unrecognized option '--warning-as-error'
    /nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: use the --help option for usage information
    collect2: error: ld returned 1 exit status
    -----------

    ERROR: Linker nvcc does not support sanitizer arguments ['-Xcompiler=-fsanitize=address\\,undefined']

Now we ended up passing the flag to the underlying linker, but the
`--warning-as-error` flag isn't known by it. What we really ought to do
is to pass on the flag to nvlink, which is the linker driver that
controls the underlying linker.

Do so by using `-Xnvlink=`, which fixes the bug.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-03-09 18:06:14 -04:00
Dylan Baker 35ebae5541 compilers/cuda: implement has_argument checks
Same as the preceding commit, the CUDA toolchain does not yet know to
perform compile checks for multiple arguments. Backfill required
functions.
2025-03-09 18:06:14 -04:00
Jussi Pakkanen d37d649b08 Make all Meson level options overridable per subproject. 2025-02-13 23:57:48 +02:00
Dylan Baker ba3460eb11 options: Add an EnumeratedUserOption class
This will allow us to take choices out of the UserOption class, which
doesn't actually use this attribute.
2025-02-05 17:45:38 +02:00
Dylan Baker 0e11b90d6f options: use dataclasses for UserOption
This reduces code, makes this clearer, and will be a nice step toward
the goal of getting everything typesafe.

For `UserIntegerOption` this makes a fairly nice, but substantial change
in that the old method used a tuple of `(min, value, max)` to pass to the
initializer, while all other types just passed `value`. The new
`UserIntegerOption` does the same, with keyword arguments for the min
and max values.
2025-02-05 17:45:38 +02:00
Dylan Baker fe9f8de1ab compilers: remove Compiler.create_option
This saves a *tiny* bit of typing, but at the cost of requiring either
the current solution of throwing up our hands and saying "typing is too
hard, better to have bugs!" or an extensive amount of `TypedDict`s,
`overloads`, and a very new version of mypy. Let's get our type safety
back, even if it means writing a little bit more code.
2025-02-05 17:45:38 +02:00
Zihua Wu e940d58677
fix LDFLAGS for cuda
LDFLAGS may contain flags that nvcc is unable to handle and these flags
need to be processed before we pass them to nvcc
2024-09-06 16:00:19 -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 f15963194f Rename langopt method
The public facing name of language options is compiler option, so
let's standardise on that.
2024-07-12 15:53:15 +03:00
Jussi Pakkanen 0d7bb776e2 Move OptionKey in the option source file. 2024-07-11 11:53:39 +03: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
Jussi Pakkanen 374fa7f0da Use helper method in remaining compiler classes. 2024-06-08 21:12:56 +03:00
Jussi Pakkanen 5365d9a842 Refactor option classes to their own file. 2024-05-23 21:26:45 +03:00
David Seifert 4861079360 cuda: fix `cuda.find_library()` hardcoded to yield true
* Previously, cuda would just plainly prepend `-l` to the libname.
* By relying on the host compiler to find libraries, we now get
  more subtle failures, such as CUDA modules not being found
  anymore.
* We need to simplify these CUDA modules when nvcc is used for
  linking, since this may have side-effects from the cuda toolchain.

Closes: #13240
2024-05-22 23:54:30 +03:00
David Seifert 89a5bde9d9 cuda: pass static archives to nvcc without -Xlinker= prefix 2024-05-07 22:32:35 -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
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
David Seifert 0cd74c96f1
cuda: respect host compiler `-Werror`
The cuda compiler also executes the host compiler and generally needs to know
the host compiler flags. We did this for regular args but not for error args.
We use `-Xcompiler=` since that's how nvcc tells the difference between args
it uses itself for device code and args it passes to the host compiler.

Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
[eli: fix quoting style]
2024-03-06 14:13:07 -05:00
David Seifert 937d1c639a nvcc: avoid adding `-Wpedantic` to compile lines
* `-Wpedantic` creates useless churn due to its use of gcc-line directives:
  ../foo.cu:1:3: warning: style of line directive is a GCC extension
      1 | namespace Foo {
        |   ^~
  https://stackoverflow.com/a/31001220
2024-02-28 19:34:39 -05:00
wrvsrx e2458c6f94 nvcc compiler: support find dependency header files
This commit supersedes PR #11229 and #10993.

It also adds version check according to [comments](https://github.com/mesonbuild/meson/pull/11229#issuecomment-1370287546)
2023-12-26 23:37:27 -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
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
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
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
Dylan Baker bfce5c45a4 compilers: convert method to get assert control to a boolean
C like compilers only off `-DNDEBUG` to disable asserts. This is not a
universal paradigm however. Rust, for example has an argument that takes
a boolean. To better represent this, we allow passing a `disable`
boolean. `disable` was chosen rather than `enable` because it allowed
all existing logic to be left in place
2023-04-21 15:18:56 +05:30
HiPhish 439a61affa Change "can not" to "cannot" throughout project
The word "cannot" expresses inability to do something whereas "can not"
expresses the ability to refrain from doing something.
2023-04-11 17:10:01 +03:00
Charles Brunet a5a7b29a66 prevent lib prefix warning from pkg-config 2023-03-16 08:27:06 -04:00
David Seifert 9e9fa8f820 cuda: enable C++20 for CUDA 12
https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-compilers
2023-01-31 17:54:43 -05:00
Dylan Baker 2d349eae8c
pylint: enable the set_membership plugin
Which adds the `use-set-for-membership` check. It's generally faster in
python to use a set with the `in` keyword, because it's a hash check
instead of a linear walk, this is especially true with strings, where
it's actually O(n^2), one loop over the container, and an inner loop of
the strings (as string comparison works by checking that `a[n] == b[n]`,
in a loop).

Also, I'm tired of complaining about this in reviews, let the tools do
it for me :)
2022-11-30 16:23:29 -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
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -04:00
Eli Schwartz 0703ee0aef
move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -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
Eli Schwartz 07d9c72e17
flake8: fix wrong numbers of blank line separators 2022-02-16 18:19:13 -05: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
Eli Schwartz 9f384e9207
fix type annotations for compiler toolchain rpaths
We pass around a tuple of rpaths, because rpaths *can* be more than one.
But all the annotations said it would be a str instead.
2021-12-30 15:15:25 -05:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Xavier Claessens a3f3ddf581 cuda: Override std=none to avoid host_compiler to emit -std argument 2021-10-14 14:17:50 -04: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
Dylan Baker e3c72ad7c7 compilers: Fix extra_args parameter
which can also be a callable taking a CompileChekcMode as an argumetn
and returning a list of strings.
2021-08-16 16:21:51 -07:00