Commit Graph

700 Commits

Author SHA1 Message Date
Dylan Baker 201dc64226 add a couple more type annotations 2021-06-02 15:53:17 -07:00
Dylan Baker 113a159514 use an immutable list for an lru_cached functions
When mutable items are stored in an lru cache, changing the returned
items changes the cached items as well. Therefore we want to ensure that
we're not mutating them. Using the ImmutableListProtocol allows mypy to
find mutations and reject them. This doesn't solve the problem of
mutable values inside the values, so you could have to do things like:

```python
ImmutableListProtocol[ImmutableListProtocol[str]]
```

or equally hacky. It can also be used for input types and acts a bit
like C's const:

```python
def foo(arg: ImmutableListProtocol[str]) -> T.List[str]:
    arg[1] = 'foo'  # works while running, but mypy errors
```
2021-06-02 15:53:17 -07:00
Dylan Baker c6ec13e6bf
Only try to get RSP syntax if RSP is supported (#8804) 2021-05-30 00:24:53 +03:00
Xavier Claessens 25fa2d4f7b vsenv: Recommend using "meson compile" wrapper
When meson has setup the VS environment, running ninja to build won't
work, user should use meson wrapper to compile.
2021-05-28 17:34:25 -04:00
Chun-wei Fan bbb6f2c51c ninjabackend.py: Implement `link_whole:` for pre-VS2015
...Update 2, to be exact, since the Visual Studio linker only gained the
`/WHOLEARCHIVE:` feature since Visual Studio 2015 Update 2.

This checks whether we have the corresponding `cl.exe` which is
versioned at or after Visual Studio 2015 Update 2 before we try to apply
the `/WHOLEARCHIVE:xxx` linker flag.  If we aren't, use built-in methods
in Meson to grab the object files of the dependent static lib's, along
with the objects that were `link_whole:`'ed into them, and feed this
list into the linker instead.

This would make `link_whole:` work on Visual Studio 2015 Update 1 and
earlier, including previous Visual Studio versions.
2021-05-27 09:54:37 -07:00
Jussi Pakkanen 43f0aa17b7 Add swift executable support in Xcode. 2021-05-23 17:59:14 +01:00
Dylan Baker bfd06783bd backends: use a set for processed targets instead of a dict
We're only interested in the keys, not in the value (which was always
set to True), so a set is a better data structure anyway.
2021-05-19 23:28:17 +03:00
Dylan Baker 7659ae50a0 ninjabackend: Fix vala type annotations 2021-05-19 23:28:17 +03:00
Dylan Baker b1b8e777a2 rust: override get_linker_always_args
instead of opencoding what should be there in the rust compile rule
2021-05-19 23:28:17 +03:00
Dylan Baker e7e04c814b Add a rust test for internal c linkage
We have code to support this, but no tests. That seems pretty bad.
And better yet, it doesn't work on MSVC in some cases.
2021-05-18 09:34:36 -07:00
Dylan Baker 11d123332d ninjabackend: fix linking dynamic c libraries with rust
The correct name is "dylib" not "shared"
2021-05-17 15:21:27 -07:00
Marco Trevisan (Treviño) 739e499554 ninjabackend: Add pch includes as early as possible not to be overridden
When pch are used for a target meson will make the compiler to include
the pre-compiled header. While this is useful, this needs to happen
before any other header has been included, otherwise:

 1) we won't take advantage of pch for anything else previously included
 2) gcc will just fail as it won't even try to look for a pre-compiled
    header in this case [1]

This case can happen quite a easily when a dependency provides an
included header in its cflags.

As per this, split _generate_single_compile() in two phases, one is
responsible of initializing the compiler data, while the other is
defining commands for the context.

In this way, when pch can be used, we can insert the pch inclusion
earlier than any other provided by the target.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100462
2021-05-08 21:27:35 +03:00
Jussi Pakkanen 1a31882f59 Xcode: make Swift projects work. 2021-04-25 15:35:13 +03:00
Jussi Pakkanen 48e38fbaeb Xcode: fix custom targets that produce objs and libs. 2021-04-16 18:14:01 +03:00
Jussi Pakkanen e80ff985fb Do not add custom target dir automatically when implicit false. 2021-03-29 18:57:34 +03:00
Xavier Claessens 0638e38bfc clangformat: Add clang-format-check target 2021-03-16 21:01:54 -04: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
Remi Thebault 89202aaaef change RSP quote style decision logic
Take into account LDC on Windows
Fixes #8494
2021-03-09 21:17:41 +02:00
Jussi Pakkanen 85796229c2 Fix Fortran dep scanner for upper case file extensions. Closes #8395. 2021-03-06 01:53:52 +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
Dylan Baker d7d80945ea rust: a meson -l argument could be etiher a static or dynamic library
I made an incorrect assumption that -l arguments would always be static
libraries, but they might well be shared libraries.
2021-02-26 14:26:15 -08:00
Dylan Baker 0edd005804 rust: replace for loop with any()
This is a little cleaner, and short circuits correctly, unlike the loop
it replaces
2021-02-23 16:22:56 -08:00
Dylan Baker 6544f151db rust: fix linking with external dependencies
Rust can link with any dependency that uses c linkage, which is pretty
much what we assume across the board anyway.
2021-02-23 16:22:56 -08:00
Jussi Pakkanen 72865a2773 Fix combining C and Fortran. Closes #8377. 2021-02-19 18:18:39 +02:00
Jussi Pakkanen f3727c62c6 Fix VS C++ module support. 2021-02-16 17:05:12 +00:00
Xavier Claessens a155935d24 backends: Always use the command returned by as_meson_exe_cmdline()
Even if the command is not wrapped by meson, it could have been modified
to add java/mono interpreters. This fix potential inconsistency between
wrapped and unwrapped commands.
2021-02-09 19:32:20 +02:00
Jussi Pakkanen 71784e1002 Fix exe wrapper detection for run targets. 2021-02-08 23:19:41 +02:00
Jussi Pakkanen a855bcab1c
Merge pull request #8162 from dcbaker/wip/2021-01/rust-module-bindgen
Add a wrapper to the rust module for bindgen
2021-02-07 16:57:39 +00:00
Jussi Pakkanen 8b82ffa9e4
Merge pull request #8305 from xclaesse/run-target-env
run_target: Add env kwarg
2021-02-07 11:46:41 +00:00
Dylan Baker 4082a3db45 backends/ninja: Implement linking a C ABI target into a rust target 2021-02-06 10:27:04 -08:00
Dylan Baker 456844a4f3 vala: Disable unity builds
Our approach to unity builds with vala is broken, you cannot unify the
generated C files, as they contain duplicate symbols. We would need to
instead combine the files while they are still in their vala form, then
convert that to C and compile the unified C file.

This does not fix the linked issue, as this removed the ability to do
vala unity builds, but it does allow running vala with `--unity=on`.

Related: #5280
2021-02-05 16:31:33 -08:00
Dylan Baker d2c7063c1a ninjabackend: add a few annotations 2021-02-05 16:31:33 -08:00
Xavier Claessens f63e168685 ninjabackend: Remove useless call to replace_paths()
Replacements are already done by eval_custom_target_command() and must
be done BEFORE calling as_meson_exe_cmdline() anyway. replace_paths() is
still used by generators.

Make eval_custom_target_command() more readable by handling error in the
final else case instead of in the middle of elif.
2021-02-05 18:17:08 -05:00
Xavier Claessens b52794b24b backend: Do not check for exe wrapper twice
It is already checked by as_meson_exe_cmdline().
2021-02-05 18:17:08 -05:00
Xavier Claessens 522392e755 run_target: Add env kwarg
Re-implement it in backend using the same code path as for
custom_target(). This for example handle setting PATH on Windows when
command is an executable.
2021-02-05 17:53:09 -05:00
Jeff Moguillansky 9226a92fe0 xcode-backend: add implicit includes
Move helper functions get_source_dir_include_args and
get_build_dir_include_args to backend base class
2021-02-04 13:05:17 -08:00
Xavier Claessens 633264984b custom_target: Add env kwarg 2021-01-27 09:00:54 -05:00
Jussi Pakkanen bb6385111a
Merge pull request #8236 from dcbaker/submit/rust-fix-generated-sources-in-subdir
Submit/rust fix generated sources in subdir
2021-01-25 18:24:28 +00:00
Jussi Pakkanen 99b9433bea
Merge pull request #8226 from jonaslb/fortranstatic
Fixes for fortran: Include dirs for link_whole_targets and capital file suffix
2021-01-23 17:33:38 +00:00
Dylan Baker 23d3b98fc1 split mesonlib into a package
Currently mesonlib does some import tricks to figure out whether it
needs to use windows or posix specific functions. This is a little
hacky, but works fine. However, the way the typing stubs are implemented
for the msvcrt and fnctl modules will cause mypy to fail on the other
platform, since the functions are not implemented.

To aleviate this (and for slightly cleaner design), I've split mesonlib
into a pacakge with three modules. A universal module contains all of
the platform agnositc code, a win32 module contains window specific
code, a posix module contains the posix specific code, and a platform
module contains no-op implementations. Then the package's __init__ file
imports all of the universal functions and all of the functions from the
approriate platform module, or the no-op versions as fallbacks. This
makes mypy happy, and avoids `if`ing all over the code to switch between
the platform specific code.
2021-01-23 12:48:29 +01:00
Dylan Baker 4550cf9500 ninjabackend: Correctly reference custom_target outputs in subdirs with rust
This was missed in the last iteration of fixing things.
2021-01-21 10:59:15 -08:00
Jonas Lundholm Bertelsen 2636eebd64 Unity build reverts to normal for fortran fix
The `determine_ext_objs` function did not take into account that fortran
(and d) does not support unity builds. This caused failures in some
cases.
2021-01-21 14:46:20 +01:00
Fini Jastrow 49cde9653c ninjabackend: Correct RPATH order
[why]
If we build and test a library we need to make sure that we find the
currently build library object first, before an older system installed
one.
This can be broken if the library in question is installed in a custom
path, and another library we depend on also is installed there.

[how]
Just move the rpath to the current build artifacts to the front.

Solves #8030.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2021-01-20 19:00:25 +00:00
Jonas Lundholm Bertelsen ea34a92632 When iterating link_targets, include link_whole_targets too (fortran)
This fixes fortran includes and fortran orderdeps for libraries that
were under link_whole_targets.
2021-01-20 18:18:54 +01:00
Jonas Lundholm Bertelsen bd2394e872 Use case-insensitive suffix check for fortran
In Fortran it is common to use capital F in the suffix (eg. '.F90') if
the source file makes use of preprocessor statements. Such files should
probably be treated like all other fortran files by meson.

Case insensitivity for suffixes was already implemented several places
in meson before this. So most likely, the few places changed here were
oversights anyway.
2021-01-20 18:11:02 +01:00
Dylan Baker caa6d5e16b backend/ninja: Add order dependencies for generated sources in rust 2021-01-19 10:14:12 -08:00
Dylan Baker bff0b41525 rust: Accept generated sources for main.rs
There are still caveats here. Rust/cargo handles generated sources by
writing out all targets of a single repo into a single output directory,
setting a path to that via a build-time environment variable, and then
include those files via a set of functions and macros. Meson's build
layout is naturally different, and ninja makes working with environment
variables at compile time difficult.

Fixes #8157
2021-01-19 10:14:10 -08:00
Dylan Baker 3ae115b57a Replace NinjaBackend is_rust_target with build.uses_rust
we have two functions to do the exact same thing, and they're basically
implemented the same way. Instead, let's just use the BuildTarget one,
as it's more generally available.
2021-01-19 10:12:38 -08:00
Dylan Baker e81acbd606 Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
2021-01-04 12:20:58 -08: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