Commit Graph

1360 Commits

Author SHA1 Message Date
Paolo Bonzini 979805fdc1 coredata: remove unused arguments
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-15 10:10:49 -07:00
Paolo Bonzini 2d1c67f095 options: restore special behavior of CFLAGS vs. c_args
For compatibility with Autotools, CFLAGS is added to the linker command
line if the compiler acts as a linker driver.  However, this behavior
was lost in commit d37d649b0 ("Make all Meson level options overridable
per subproject.", 2025-02-13).

The issue is that (for example) c_link_args is stored in env.options, and
from that point on it is treated as a machine-file option.  This includes
not being able to override it in compilers.get_global_options:

- initialize_from_top_level_project_call places it in pending_options

- add_lang_args passes the right value to add_compiler_option

- add_compiler_option calls add_system_option_internal

- add_system_option_internal fishes the value out of pending_options
  and ignores what get_global_options provided.

Instead, store the putative values of the compiler options coming from
the environment in a separate dictionary, that is only accessed by
get_global_options. This way it never appears in pending_options, and
also there is no internal *_env_args variable anymore.

Fixes: #14533
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-15 02:03:46 -04:00
Peter Harris 043ff22fc7 cpp: Fix cpp_std=vc++14
Fixes a regression introduced in commit d37d649b08 "Make all Meson level
options overridable per subproject." This change results in every file
printing the warning "cl : Command line warning D9002 : ignoring unknown
option '/std:vc++14'"

Now that "get_option_..." is called before overwriting the option (instead
of after), we have to operate on compiler options, not meson options.

There is no such compiler option as /std:vc++14 (the meson option vc++xx is
split into /std:c++xx for the C++ standard version, and a separate flag
that enables Microsoft extensions). Remove the mapping from c++14 to
vc++14.
2025-05-13 09:44:22 -07:00
Daniel Foster 24d7c347f5 compilers/rust: fix syntax of has_argument checks 2025-05-11 03:04:52 -04:00
Martin Dørum a16ec8b0fb cpp: fix _LIBCPP_ENABLE_ASSERTIONS warning
libc++ deprecated _LIBCPP_ENABLE_ASSERTIONS from version 18.
However, the libc++ shipped with Apple Clang backported that
deprecation in version 17 already,
which is the version which Apple currently ships for macOS.
This PR changes the _LIBCPP_ENABLE_ASSERTIONS deprecation check
to use version ">=17" on Apple Clang.
2025-05-02 15:27:58 +03:00
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
Paolo Bonzini 8909a09d2a compilers: clike: log output of sanity check
Particularly if using an exe_wrapper, it can be useful to have output
logged for debugging.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-30 00:14:44 +03:00
Kacper Michajłow ce7e187630 compilers/rust: remove CRT selection from native_static_libs args
This will be handled by target binary link. And if it's not compatible
with what Rust uses, it wouldn't work anyway.
2025-04-16 13:02:28 -04:00
Paolo Bonzini cece1a7e99 linkers: pass system to DynamicLinker.__init__ for Darwin linkers
Apple linkers need to use different arguments on macOS and iOS-like platforms.
Pass the system to the constructor so that it can be examined.

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-16 12:17:25 +03:00
Andrew McNulty f23b0e7f35
interpreter: Error if java sources used with non-jar target (#14424)
If the user specifies java sources as input to a non-jar build
target, raise an error with a message directing them to use the jar
target instead.

Fixes: https://github.com/mesonbuild/meson/issues/13870
2025-04-09 09:13:39 -07: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
Paolo Bonzini 47984f8134 compilers: introduce get_option_std_args
Allow CUDA to completely override the -std arguments but not the rest.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-04 12:46:55 +03:00
Paolo Bonzini 4ecf608936 compilers: remove useless get_option_compile_args
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-04 12:46:55 +03:00
Kacper Michajłow 5d9b9739dd compilers/rust: fix sanity_check for Windows targets
Windows toolchains append `.exe` to executables. When cross-compiling on
Linux, attempting to run `./rusttest` will not execute the generated
`rusttest.exe`.

Fix this by always appending `.exe`, which is a valid filename on all
supported platforms. This is what the `CLikeCompiler` class does too.

While reviewing `rust.py`, there are opportunities for improvements and
better unification with the rest of the Meson code. However, this commit
focuses on fixing cross-compilation with minimal changes.

Fixes: #14374
2025-04-03 11:49:37 +03:00
Dylan Baker 4001d02619
options: move BASE_OPTIONS to the options module
This makes more sense from a "group all options together" It also allows
us to remove a bunch of imports in functions, a clear code smell.
2025-04-02 12:49:07 -04:00
Paolo Bonzini d9af002fa2 compilers: rust: fix derivation of RustdocTestCompiler
Pass down the full_version, otherwise assigning "self.is_beta"
fails.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02 08:44:37 -07:00
Paolo Bonzini 54118b6fbf ninjabackend: generate command line for rust doctests
Adjust get_rust_compiler_args() to accept the crate-type externally, because
rustdoc tests are an executable but are compiled with the parent target's
--crate-type.

Apart from that, the rustdoc arguments are very similar to the parent target, and
are handled by the same functions that were split out of generate_rust_target.

This concludes the backend implementation of doctests, only leaving the
implementation of a doctest() function in the rust module.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02 08:44:37 -07:00
Paolo Bonzini 2c10d77c3c compilers: introduce get_exe() and get_exe_args()
This will be used by rustdoc tests because the Test objects takes a
single string for the command and everything else goes in the args.
But apart from this, the need to split the executable from the
arguments is common so create new methods to do it.

While at it, fix brokenness in the handling of the zig compiler, which
is checking against "zig" but failing to detect e.g. "/usr/bin/zig".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02 08:44:37 -07:00
Paolo Bonzini dfefd838a8 ninjabackend: split out generation of rustc arguments
Allow reusing the code for doctests.  In particular, the sources are
shared between the two cases.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02 08:44:37 -07:00
Andrei Horodniceanu 77dd0429cf mesonbuild/compilers/detect.py: Support Open D ldc and dmd
Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
2025-03-12 09:09:35 -07: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
Dylan Baker e629d191b9 compilers: check for sanitizer arguments via a compiler check
The `b_sanitize` option is used to specify which sanitizers to use. This
option is implemented as a combo option, where it only allows a specific
set of hardcoded choices. This implementation isn't quite scalable:

  - The number of available sanitizers is steadily growing, so we have
    to always catch up with what sanitizers exist out there.

  - Sanitizers can be combined more freely nowadays, but we only allow
    to combine the "address" and "undefined" sanitizers.

  - A hardcoded list is not a good match given that a choice existing as
    an option does not mean that it is supported by the compiler in the
    first place.

Instead of hardcoding available options, it is way more future proof to
instead allow arbitrary values and perform a compiler check. This makes
us support new sanitizers readily while also providing good feedback to
our users why a specific option might not be allowed.

Implement the compiler checks for sanitizers as a first step. Note that
this does not yet loosen the set of allowed sanitizers as we only accept
hardcoded values as specified by the combo option. This restriction will
be lifted in the next commit.
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
Dylan Baker f39637e164 compilers/rust: implement has_argument checks
We're about to convert the `b_sanitize` option into a free-form array
whose value gets verified via a compiler check. This conversion will
also impact the Rust toolchain, which does not yet know to check for
multiple arguments at once.

Implement both `has_multi_arguments()` and `has_multi_link_arguments()`
to prepare the code accordingly.
2025-03-09 18:06:14 -04:00
Charles Brunet 52dd881552 Optimize CLikeCompiler._get_file_from_list() 2025-03-09 15:29:42 -04:00
Dylan Baker 7130468402 compilers: Remove the BaseOption type
This class only served one purpose, to avoid typing the name of the
option twice. Unfortunately the way it was implemented made getting the
type checking right difficult, and required storing the same data twice.
This patch replaces this approach with a dictionary comprehension that
creates the OptionKey from the UserOption. This allows us to initialize
a single dictionary once, avoid typing the name twice, delete lines of
code, and get better type safety.

As an added bonus, it means that the exported data from the module can
be marked module constant, ie, ALL_CAPS.
2025-03-03 11:26:23 -08:00
Dylan Baker f0795e14c5 environment: make fully type safe
This as much as anything is to stop lying to envconfig about the
potential types it will be given.
2025-03-01 13:30:06 +02:00
Marco Rebhan b1b49a237b swift: Add swift_std compiler option 2025-03-01 12:37:46 +02:00
Dylan Baker e196f848c2 compilers: delete dead code after option refactor 2025-02-27 23:33:39 +02:00
Dylan Baker 3f430886dc coredata: delete the OptionsView
This also makes KeyedOptionDictType obsolete and it's removed
2025-02-27 23:33:39 +02:00
Dylan Baker d9f3f6c0b2 use ElementaryOptionValues instead of open coding... again 2025-02-27 23:33:39 +02:00
Dylan Baker 8ebc8c1878 modules/rust: use 'nightly' as the bindgen version if the compiler is nightly
This adds tracking for both nightly and beta to the rust compiler.
2025-02-27 15:27:42 -05:00
Dylan Baker 5d648a112f compilers/detect: Split -beta and -nightly suffixes from rustc
Store both a full version with the nightly and beta suffixes, and the
version as just X.Y.Z. This sort of distinction is why full_version
exists.

This fixes an issue with the bindgen module where we pass invalid
version of X.Y.Z-beta and X.Y.Z-nightly.
2025-02-27 15:27:42 -05:00
Tom Evers 1412abc516 Fixes issue 14089 (detection of Intel compiler) 2025-02-27 07:12:21 -08:00
Paolo Bonzini eca1ac18dc c: add -Wno-vla-larger-than to the exceptions for -Wno*
When supplying -Wno-vla-larger-than to compiler.get_supported_arguments,
meson will inject -Wvla-larger-than as an argument which considered
invalid by GCC, as the converse argument is -Wvla-larger-than=<value>.

Just like CLikeCompiler._has_multi_arguments special-cases
-Wno-attributes=, do the same for -Wno-vla-larger-than.

Resolves: https://github.com/mesonbuild/meson/issues/14208
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-16 22:09:44 +02:00
Jussi Pakkanen d37d649b08 Make all Meson level options overridable per subproject. 2025-02-13 23:57:48 +02:00
Marco Rebhan e42cd6aff6 ninja backend: Use swiftc flag -working-directory if available
This makes SourceKit-LSP work using a meson-generated
compile_commands.json.
2025-02-11 09:58:38 -08:00
Dylan Baker 9fd5281bef options: Replace uses of `UserOption[T.Any]` with a Union of UserOption types
The fact that UserOption is generic is really an implementation detail,
not something to be used publicly. So by having an `AnyOptionType`
alias, we can get better type checking, as can be seen by the patch as a
whole. One of the big fixes it replace open-coded equivlalents of
`MutableKeydOptionDictType` with that type alias.
2025-02-05 17:45:38 +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
Dylan Baker f0a6ba3809 compilers: use super().get_options() instead of CompilerClass.get_options()
Because the latter doesn't always interact with the MRO correctly.
2025-02-05 17:45:38 +02:00
Dylan Baker b51840cf18 compilers: fix the UserStdOption name of the C and C++ compilers 2025-02-05 17:45:38 +02:00
Dylan Baker cd5bc11bb3 options: Get rid of the invalid _U type, and use UserOption[_T] 2025-02-05 17:45:38 +02:00
Paolo Bonzini d34c37f8a0
rust: use f-string to build rpath arguments
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03 20:02:18 -05:00
Paolo Bonzini a19df7da15
ninjabackend: start adjusting for differences between rustc and rustdoc
Add functions to RustCompiler() to account for differences
between rustc and "rustdoc --test": rustdoc always generates
a binary, does not support -g, and does not need --emit.

Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03 20:01:37 -05:00
Paolo Bonzini 103501c274
ninjabackend: unify building rpath args
Implement RustCompiler.build_rpath_args, so that more code can
be shared between non-Rust and Rust targets.  Then, RustCompiler
can override it to convert the arguments to "-C link-arg=" and
add the rustup sysroot.

Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03 20:01:37 -05:00