Commit Graph

146 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
Eli Schwartz 4a352dd8bd
flake8: move unused typing-only imports to TYPE_CHECKING 2024-07-30 14:13:11 -04:00
Christoph Reiter 76bd5548ae Revert logic also in followup commit
In 8d7ffe6e86 need_exe_wrapper() use was copied which was just reverted,
so replace with is_cross there too, to keep things in sync.
2024-07-16 02:01:21 -04: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
Axel Ricard 8d7ffe6e86 fix sanity check for d cross-compilation 2024-05-22 23:53: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
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 6b569527bc compilers: Allow setting env and workdir for run checks
This is not exposed in API, but will be used internally.
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
Jussi Pakkanen 9afe62232c Fix lint warning. 2024-02-26 19:53:16 +02: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 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
Dylan Baker 74771d2119 compilers/d: use DFeatures for get_features_args 2023-10-16 13:28:32 -07:00
Dylan Baker 6599c32fd3 compilers/d: remove duplicate method from subclass
The DCompiler and DmDLikeCompiler classes both implement the exact same
`get_feature_args()` method. The DmdLikeCompiler inherits the DCompiler.
As such, removing it doesn't change the behavior of anything, but
decreases the chances of bugs being introduced, as well as LoC.
2023-10-16 13:28:32 -07: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
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
Andres Freund 808d5934dd Use caching in Compiler.sizeof() and Compiler.alignment() 2023-02-27 20:09:32 -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
Axel Ricard 23fcea16e5 Don't ignore documentation-related flags for D compilers
Fixes #11085
2022-11-29 01:45:23 +02:00
David Robillard 81d7c24a59 Add warning_level=everything
Adds a new maximum warning level that is roughly equivalent to "all warnings".
This adds a way to use `/Wall` with MSVC (without the previous broken warning),
`-Weverything` with clang, and almost all general warnings in GCC with
strictness roughly equivalent to clang's `-Weverything`.

The GCC case must be implemented by meson since GCC doesn't provide a similar
option.  To avoid maintenance headaches for meson, this warning level is
defined objectively: all warnings are included except those that require
specific values or are specific to particular language revisions.  This warning
level is mainly intended for new code, and it is expected (nearly guaranteed)
that projects will need to add some suppressions to build cleanly with it.

More commonly, it's just a handy way to occasionally take a look at what
warnings are present with some compiler, in case anything interesting shows up
you might want to enable in general.

Since the warnings enabled at this level are inherently unstable with respect
to compiler versions, it is intended for use by developers and not to be set as
the default.
2022-11-27 16:50:48 -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
Jan Tojnar a590cfde0c compilers: Add optimization=plain option
https://github.com/mesonbuild/meson/pull/9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
2022-10-09 14:43:18 +03:00
Eli Schwartz 27748f9cd1
fix linker regression for compilers that don't accept LDFLAGS directly
e.g. ldc -- the compiler needs to process args before consuming them.

Fixes #10693
2022-08-24 23:49:14 -04:00
Eli Schwartz 0703ee0aef
move various unused typing-only imports into type-checking blocks 2022-07-03 14:11:31 -04:00
Remi Thebault f24ad87e05 implement and test a few compiler checks for D
- run
 - sizeof
 - alignment
 - has_header
2022-04-30 10:07:38 -04:00
Fini Jastrow c16fdaeeca linkers: Add support for mold linker
[why]
Support for the relatively new mold linker is missing. If someone wants
to use mold as linker `LDFLAGS="-B/path/to/mold"` has to be added instead
of the usual `CC_LD=mold meson ...` or `CXX_LD=mold meson ...`.

[how]
Allow `mold' as linker for clang and newer GCC versions (that versions
that have support).

The error message can be a bit off, because it is generic for all GNU
like compilers, but I guess that is ok. (i.e. 'mold' is not listed as
possible linker, even if it would be possible for the given compiler.)

[note]
GCC Version 12.0.1 is not sufficient to say `mold` is supported. The
expected release with support will be 12.1.0.
On the other hand people that use the un-released 12.0.1 will probably
have built it from trunk. Allowing 12.0.1 is helping bleeding edge
developers to use mold in Meson already now.

Fixes: #9072

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-04-30 10:06:22 -04:00
Eli Schwartz 530338782c compilers/d: fix mangling of rpath-link in DMD-like compilers
We didn't consider that it has arguments following it, so the resulting
compiler command line ended up with stuff like:

-L=-rpath-link -L=-L=/path/to/directory -L=more-args

and the directory for rpath-link got eaten up as a regular -L path to
the compiler rather than being passed as -Xlinker to the linker.

Then the -rpath-link would consume the next -Xlinker argument, end up
with the wrong rpath-link (may or may not cause link errors) and then
disappear arguments we need.

As an example failure mode, if the next argument is -soname this treats
the soname text as an input file, which probably does not exist if it
was generated in a subdirectory, and also because it can never be
successfully built in the first place -- though if it did, it would link
to itself which is very wrong.
2022-03-01 18:34:58 -08:00
Tobias Pankrath 91ca3e2d58 dlang: fix #9250 invalid include flag for root directory 2022-02-06 14:16:51 -08: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
Denis Feklushkin 1b1ecec920 ldc2: invoke -Oz instead of -Os 2021-11-22 12:35:28 -08:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Dylan Baker 9795323b86 pylint: check for duplicate imports
I ran into one of these from LGTM, and it would be nice if pylint could
warn me as part of my local development process instead of waiting for
the CI to tell me.
2021-09-24 10:36:05 -07:00
Dylan Baker 4d7031437c pylint: turn on superflous-parens
We have a lot of these. Some of them are harmless, if unidiomatic, such
as `if (condition)`, others are potentially dangerous `assert(...)`, as
`assert(condtion)` works as expected, but `assert(condition, message)`
will result in an assertion that never triggers, as what you're actually
asserting is `bool(tuple[2])`, which will always be true.
2021-08-31 16:28:54 -04:00
Paolo Bonzini 3efed376c3 linkers: remove is_shared_module argument to get_soname_args
The argument is now unused, drop it.
2021-07-14 22:53:04 +02:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Dylan Baker 40e3577a65 split program related classes and functions out of dependencies
Dependencies is already a large and complicated package without adding
programs to the list. This also allows us to untangle a bit of spaghetti
that we have.
2021-03-19 08:47:10 -04:00
Remi Thebault c756d97895 Fix D lib search path translation
This requires quite a complex and messy logic.
As @dcbaker suggested in #8491, this could be replaced by
an abstraction over linker flags instead of having GNU flags
translated.
2021-03-17 10:14:55 -07:00
Dylan Baker 2be074b1d4 ninjabackend: Use rsp_file_syntax method
This also makes us of the new enum value in the backend, for better type
saftey.
2021-03-14 22:05:55 -07:00
Dylan Baker 320412b3bb compilers/linkers: Add a methhod for getting the rspfile syntax 2021-03-14 22:05:55 -07:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Eli Schwartz 4340bf34fa
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only --keep-percent-format"

and committing the results. I have not touched string formatting for
now.

- use set literals
- simplify .format() parameter naming
- remove __future__
- remove default "r" mode for open()
- use OSError rather than compatibility aliases
- remove stray parentheses in function(generator) scopes
2021-03-04 17:11:26 -05:00
Remi Thebault 25848fc05f fix missing versions with generated source 2021-03-02 09:31:40 -08:00
Remi Thebault 3bf207ab1b D add build dir to -J switch 2021-03-01 09:51:40 -08:00