Commit Graph

56 Commits

Author SHA1 Message Date
Chun-wei Fan 9bbceeee06 Visual Studio: Drop /utf-8 if it is not supported
We assume /utf-8 for all C builds unless /source-charset or
/execution-charset is specified, but then this will cause trouble for
Visual Studio 2013 or earler since the /utf-8 flag is only supported
since Visual Studio 2015.  Specifically, if we try to check whether
compiler flags are supported, those checks will fail since /utf-8 is
never supported on these older Visual Studio versions.

Drop /utf-8 from get_always_args() if we are using Visual Studio 2013
or earlier.
2023-02-07 15:32:22 +05:30
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Charles Brunet 3729b6bcd4 remove /utf-8 option when /validate-charset- is present 2023-02-01 11:33:17 -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
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 5e0f22896f Compilers: Add a preprocessor mode for clike compilers
A compiler object can now return a list of "modes", they are new
compiler object specialized for a specific task.
2022-10-23 12:21:46 +02: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
Alf Henrik Sauge 06bf9a5cda Fix purely white space issues reported by flake8 2022-08-26 17:12:40 -04:00
Eli Schwartz 46793145ba
Revert /utf-8 changes in the visualstudio mixin to the 0.62.0 state
Specifically, this is a combination of the following:

- Revert "visualstudio.py: Apply /utf-8 only on clang or VS2015+"

  This reverts commit 6e7c3efa79.

- Revert "Visual Studio: Only use /utf-8 on VS2015 or later or clang-cl"

  This reverts commit 8ed151bbd7.

The changes were broken and untested, although this is because of a lack
of general CI testing for all languages on Windows. At least, this broke
the use of ifort, and possibly more.

The changes are fundamentally a bit "exciting", as they step out of the
hierarchy of compiler definitions and apply arguments almost willy-nilly.

And apparently it's leaky all over the place. I don't understand all of
what is going on with it, but it plainly failed to achieve its desired
goal and needs to be rolled back ASAP.
2022-07-11 17:58:02 -04:00
Chun-wei Fan 6e7c3efa79 visualstudio.py: Apply /utf-8 only on clang or VS2015+
In PR 10263, we didn't account for that we may have initialize the Visual
Studio-like compiler two times, once for a C compiler and once for the
C++ compiler, so we end up with Meson breaking on Visual Studio 2013
or earlier, such as when building GLib.

Fix this by setting up the always_args member of
the VisualStudioLikeCompiler instance during __init__() as needed, so that
we avoid falling into modifying shared objects.
2022-06-21 21:08:06 +03:00
Khairul Azhar Kasmiran 6b7bc608b7 compiler.has_argument: Add `-Werror=unknown-warning-option` to clang-cl cmd line 2022-05-06 23:09:52 +03:00
Chun-wei Fan 8ed151bbd7 Visual Studio: Only use /utf-8 on VS2015 or later or clang-cl
The compiler flag only exists on Visual Studio 2015 or later, or clang-cl,
and using this always can interfere with compiler feature detection when
this flag is not supported.

So, remove '/utf-8' from always_args if we are on Visual Studio 2013 or
earlier.
2022-04-25 20:29:16 +03:00
Marvin Scholz 1b03441bc4 visualstudio: do not query underscore define with MSVC
MSVC does not has the builtin define to check for the symbol
prefix, so do not try to query it at all, to save some time.
2022-03-31 10:55:55 +02:00
Gatgat f3a8e5d3b2 Fix system include arguments for clang-cl 2022-01-15 22:00:05 +05:30
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
Sahnvour d9c73a6a7b clang-cl: add a translation pass for `-isystem` args to work 2021-12-08 00:53:29 +02:00
Luke Elliott d014ccf8d7 Fix _calculate_toolset_version for VS2022. 2021-11-27 21:46:16 +02:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Xavier Claessens ea02c1c48a msvc: Assume UTF8 source by default
Currently every project that uses UTF8 for its source files must add
'/utf-8' argument otherwise they don't work non-English locale MSVC.

Since meson.build itself is assumed to be UTF8 by default, seems better
to assume it for source files by default too.

For example:
- https://gitlab.freedesktop.org/gstreamer/gst-build/-/blob/master/meson.build#L62
- https://gitlab.gnome.org/GNOME/glib/-/blob/main/meson.build#L29
2021-09-01 19:26:36 +03: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
Peter Harris be015a37d7
Visual Studio Address Sanitizer updates
* Allow address sanitizer for Visual Studio 2019 version 16.9

Address Sanitizer was first supported with the current syntax in Visual
Studio 16.9.0 (cl version 19.28.29910).

* VS: Convert /fsanitize=address to project file setting
2021-05-15 18:47:04 +03:00
Alexander Neumann 8f12102549 deactivate intrinsic functions if no optimizations are requested 2021-05-10 19:17:39 +03:00
D Scott Phillips 703fd6d1fa
compilers: clang-cl: Also accept .s files (#8520)
* compilers: clang-cl: Also accept .s files

clang-cl has support for gas-compatible assembly files.

* Add clang-cl to '128 generated assembly' test
2021-03-24 12:43:51 +02:00
Jussi Pakkanen d76345b4be Add address sanitizer support for Visual Studio. 2021-03-09 13:52:15 -08:00
Vili Väinölä 96405c3923 Add /Od flag to msvc optimization 0 args
Without specifying optimization the used optimization depends on vs runtime-library.
With mdd it is /Od but with md it is /O2.
2021-03-08 22:11:04 +02: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
Marios Staikopoulos f8681b12e1 MSVC and Clang-Cl Compiler Argument Cleanup
This commit performs some cleanup for the msvc and clang-cl arguments.

* "Disable Debug" (`/Od`) is no longer manually specified for optimization levels {`0`,`g`} (it is already the default for MSVC).
* "Run Time Checking" (`/RTC1`) removed from `debug` buildtype by default
* Clang-CL `debug` buildtype arguments now match MSVC arguments
* There is now no difference between `buildtype` flags and `debug` + `optimization` flags
2021-01-20 14:11:16 -05:00
Marios Staikopoulos a3d8dc546c Removal of /ZI on MSVC Debug
The /ZI flag adds in "Edit and Continue" debug information, which will
cause massive slowdown. It is not a flag that we should be adding by
default to debug builds.

/Zi will still be added.
2021-01-17 21:03:35 +00:00
Dylan Baker 71db6b04a3 use OptionKey for builtin and base options
I would have prefered to do these seperatately, but they are combined in
some cases, so it was much easier to convert them together.

this eliminates the builtins_per_machine dict, as it's duplicated with
the OptionKey's machine parameter.
2021-01-04 12:20:40 -08:00
Laurin-Luis Lehning 4053babf9c Slight consistency changes to get_gui_app_args 2020-12-14 11:23:53 -08:00
Laurin-Luis Lehning 2fb4d1f751 Make win_subsystem a linker property 2020-12-14 11:23:53 -08:00
Peter Harris 8b8a610ea4 vs: add static_from_buildtype to b_vscrt 2020-10-14 19:35:28 +03:00
Jussi Pakkanen 1a0603835e Add win_subsystem kwarg. Closes #7765. 2020-10-07 18:55:25 +03:00
Dylan Baker e7f0890cb9 compilers: move get_dependency_gen_args to base Compiler
So that every subclass doesn't have to reimplement it. Especially since
the Gnu implementation moved out of the CCompiler and into the
GnuLikeCompiler mixin
2020-10-01 15:05:00 -07:00
Vili Väinölä d1638a4fde compilers/VS: fix build to use optimization and debug flags
- Fixed using debug and optimization built-in options in MSVC.
- Fixed that VS backend does not create pdb files in release mode.
VS implicitly adds the debug fields if left out.
- Fix that it is possible to add debug info with ninja backend with
optimizations.
2020-09-29 19:25:50 +03:00
Dylan Baker 682d22129c compilers: Tell mypy that the compiler mixins are just that
We do this by making the mixins inherit the Compiler class only when
mypy is examining the code (using some clever inheritance shenanigans).
This caught a bunch of issues, and also lets us delete a ton of code.
2020-09-24 12:14:13 -07:00
Dylan Baker 4911e8eef4 compilers/mixins: make visual studio type safe 2020-09-24 12:14:13 -07:00
Dylan Baker d326c87fe2 compilers: Use a distinct type for compile/link results
Currently we do some crazy hackery where we add extra properties to a
Popen object and return that. That's crazy. Especially since some of our
hackery is to delete attributes off of the Popen we don't want. Instead,
let's just have a discrete type that has exactly the properties we want.
2020-09-24 12:14:13 -07:00
Martin Storsjö deb1d7caba Canonicalize target architectures aarch64/armv* into arm64/arm for MSVC tools
If the architectures are taken from the output of "clang-cl --version",
we need to convert these names into names that the MSVC tools accept
as the -machine: parameter.
2020-09-17 11:23:36 +00:00
Xavier Claessens 6bf61b2a38 visualstudio: warning_level 0 should not map to /W1
In every other compilers level 0 maps to no argument at all.
2020-07-22 15:54:13 -04:00
Peter Harris 9462f0c7bc msvc: Avoid spurious openmp link warnings
The linker that comes with MSVC does not understand the /openmp flag.
This results in a string of

    LINK : warning LNK4044: unrecognized option '/openmp'; ignored

warnings, one for each static_library linked with an executable.

Avoid this by only setting the linker openmp flag when the compiler is
not MSVC.
2020-06-06 12:04:28 -04:00
Dylan Baker b8294b4436 compilers: Error if invalid linker selected 2020-03-17 10:40:39 -07:00
Dylan Baker 06bbf6cf93 linkers: Move import_library_args to from VS compiler to linker
This is the argument to name the implib when using the Visual Studio
Linker. This is needed by LDC and DMD when using link.exe or
lld-link.exe on windows, and is really a linker argument not a compiler
argument.
2020-03-09 16:55:08 -07:00
Dylan Baker 3f8d6af9c2 compilers: Use /Zi instead of /ZI with clang-cl
Clang-cl doesn't support /ZI, so we need to use either /Zi or /Z7, which
both do the same thing for clang-cl (though not for msvc)

Fixes #6414
2020-01-28 10:52:00 -08:00
Dylan Baker 0f47ca95c1 compilers: Split ClangCL and MSVC mixins
Instead of checking the compiler id inside the VisualStudioLikeCompiler
class, this creates two subclasses that each represent the divergent
behavior of the two compilers
2020-01-28 10:52:00 -08:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Dylan Baker 47dfe34c85 Consider compiler arguments in linker detection logic
If a user passes -fuse-ld=gold to gcc or clang, they expect that they'll
get ld.gold, not whatever the default is. Meson currently doesn't do
that, because it doesn't pass these arguments to the linker detection
logic. This patch fixes that. Another case that this is needed is with
clang's --target option

This is a bad solution, honestly, and it would be better to use $LD or a
cross/native file but this is needed for backwards compatability.

Fixes #6057
2019-12-12 10:57:27 -08:00
Dylan Baker ef9aeb188e Allow selecting the dynamic linker
This uses the normal meson mechanisms, an LD environment variable or via
cross/native files.

Fixes: #6057
2019-12-02 16:39:06 -08:00
Wolfgang Stöggl f037e7ef45 Fix typos found by codespell
- Typos were found by codespell v1.16.0
2019-11-06 09:55:30 -05:00