aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
AgeCommit message (Collapse)AuthorFilesLines
2023-03-29Make --vsenv a readonly builtin optionXavier Claessens1-1/+1
We need to remember its value when reconfiguring, but the Build object is not reused, only coredata is. This also makes CLI more consistent by allowing `-Dvsenv=true` syntax. Fixes: #11309
2023-03-20Add restat = 1 to the fortran_COMPILER ruleVolker Weißmann1-1/+4
gfortran does not update the modification time of *.mod files. Fixes #11552
2023-03-01rust: Fix handling of proc-macros in rust-project.jsonSebastian Dröge1-7/+9
The proc-macro code was not running at all because of a missing dash in the crate type, and the proc macro dylib path was not generated as a path but including the `-o ` commandline parameter prefix.
2023-03-01rust: Store absolute paths in rust-project.jsonSebastian Dröge1-2/+6
As meson requires source_dir!=build_dir and stores the rust-project.json inside the build directory, while software like rust-analyzer expects it at the root of the source directory, manual steps are needed for making them work together. One option, as described in the documentation, is per project configuration. Another option, that works correctly with compile-commands.json and clangd, is to store a symlink to the file in the build directory at the root of the source directory. As currently rust-project.json stores paths relative to the location of the file itself and rust-analyzer does not resolve symlinks, this does not work. To solve this, store absolute paths in rust-project.json as is already done in compile_commands.json for the directory.
2023-02-22Implement rustc controlled whole-archive linkingDylan Baker1-1/+51
Rustc as of version 1.61.0 has support for controlling when whole-archive linking takes place, previous to this it tried to make a good guess about what you wanted, which worked most of the time. This is now implemented. Additionally, rustc makes some assumptions about library names (specifically static names), that meson does not keep. This can be fixed with rustc 1.67, where a new +verbatim modifier has been added. We can then force rustc to use the name we give it. Before that, we can sneak through `/WHOELARCHIVE:` in cases of dynamic linking (into a dll or exe), but we can't force the archiver to do what we want (rustc considers the archiver to be an implementation detail). The only solution I can come up with is to copy the library to the format that rustc expects. I've run into some issues with that as well, so we warn in that case. The decisions to leave static into static broken on MSVC for 1.61–1.66 was made because: 1) The work around is non-trivial, and we would have to support that workaround for a long time 2) The number of users of Rust in Meson is small 3) The number of users of Rust in Meson on Windows, with MSVC is tiny 4) Using rustup to update rustc on windows is trivial, and solves the problem completely Fixes: #10723 Fixes: #11247 Co-authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
2023-02-21backend/ninja: fix rust cfg parsingKarol Herbst1-1/+1
2023-02-10cython: wire up support for emitting and using depfilesEli Schwartz1-1/+5
This solves rebuild issues when e.g. importing a .pxd header from a .pyx file, just like C/C++ source headers. The transpiler needs to run again in this case. This functionality is present in the 3.0.0 alphas of cython, and is also backported to 0.29.33. Fixes #9049
2023-02-10backends: handle cython ninja rules a bit more idiomaticallyEli Schwartz1-6/+7
We want to use as much default ninja behavior as we can, so reuse $out instead of repeating the output file as a string in $ARGS, and raise that into the build rule so it is only listed once.
2023-02-01pylint 2.16: remove pointless parens around equality assignmentsEli Schwartz1-1/+1
Given the construct `foo = (bar == baz)` some people like parentheses and some do not. They're pointless and don't mean anything, though. I don't feel this is particularly helpful to code clarity, tbh, and pylint now notices this and warns about it in our current pylint config. I think this is reasonable, so let's remove the odd parens.
2023-02-01simplify instantiation of builtin type using builtins instead of functionsEli Schwartz1-1/+1
2023-01-15BUG: Fix generated sources not being included as dependencies in cython ↵Thomas Li1-0/+14
transpilation
2023-01-10backends: Stop passing generator exes to ExecutableSerialisation as stringsDylan Baker1-3/+2
The code below this already handles being passed an Executable or ExternalProgram, and it does it correctly, since it handles host binaries that need an exe_wrapper correctly, while the code in the generator paths doesn't. The xcode backend is, like always, problematic, it doesn't handle things the same way as the ninja and vscode backends, and generates a shell script instead of using meson as a wrapper when needed (it seems likely that just forcing the meson path for xcode would be better). I don't have a working mac to develop a fix for, so I've left a todo comment there. Fixes: #11264
2023-01-08avoid detecting masm as a MSVC-like compiler for detecting showincludesEli Schwartz1-2/+2
It's msvc-like but, just like Intel Fortran, doesn't support this argument.
2023-01-08msvc: handle filename extensions for incdetect based on the compiler languageEli Schwartz1-2/+3
It is possible, albeit possibly inadvisable, for the exact combination of MSVC and "$CXX has C++ specific flags in it" to occur. When this happens, and cl.exe is given a filename ending in .c, it complains that you cannot compile a .c file with that option. Instead, pick the first filename matching that language and use that as the temporary filename. This more or less matches what we do in compiler-time checks. And it's the proper thing to do, rather than assume that cl.exe, when detected as the current C++ compiler, can *also* compile C because it's *also* a C compiler. Fixes #11257
2022-12-05when generating optional utility targets in ninja, skip existing aliases tooEli Schwartz1-7/+6
When auto-generating e.g. a `clang-format` target, we first check to see if the user has already defined one, and if so we don't bother creating our own. We check for two things: - if a ninja target already exists, skip - if a run_target was defined, skip The second check is *obviously* a duplicate of the first check. But the first check never actually worked, because all_outputs was only generated *after* generating all utility rules and actually writing out the build.ninja file. The check itself compares against nothing, and always evaluates to false no matter what. Fix this by reordering the target creation logic so we track outputs immediately, but only error about them later. Now, we no longer need to special-case run_target at all, so we can drop that whole logic from build.py and interpreter.py, and simplify the tracked state. Fixes defining an `alias_target()` for a utility, which tried to auto-generate another rule and errored out. Also fixes doing the same thing with a `custom_target()` although I cannot imagine why anyone would want to produce an output file named `clang-format` (unless clang itself decided to migrate to Meson, which would be cool but feels unlikely).
2022-11-30pylint: enable the set_membership pluginDylan Baker1-1/+1
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-29pylint: enable the bad_builtin checkerDylan Baker1-2/+2
This finds uses of deny-listed functions, which defaults to map and filter. These functions should be replaced by comprehensions in idiomatic python because: 1. comprehensions are more heavily optimized and are often faster 2. They avoid the need for lambdas in some cases, which make them faster 3. you can do the equivalent in one statement rather than two, which is faster 4. They're easier to read 5. if you need a concrete instance (ie, a list) then you don't have to convert the iterator to a list afterwards
2022-11-17backend/ninja: replace ` ` with `_` in rust crate-namesDylan Baker1-2/+2
Because spaces aren't allowed and result in compilation failures
2022-10-31Revert "backends/ninja: run `ranlib -c $out` when using the apple ar"Eli Schwartz1-13/+2
This reverts commit bdc6f243e9f95246b5801d2c0ccf64173fb280f3. This is part of #10628 and needs to be reverted, as it breaks other things. See https://github.com/mesonbuild/meson/pull/10628#issuecomment-1230560772
2022-10-24Not all compilers support depfileXavier Claessens1-1/+2
2022-10-23Add cc.preprocess() method for c-like compilersXavier Claessens1-0/+3
This introduce a new type of BuildTarget: CompileTarget. From ninja backend POV it is the same thing as any other build target, except that it skips the final link step. It could be used in the future for transpilers too.
2022-10-23Compilers: Add a preprocessor mode for clike compilersXavier Claessens1-1/+3
A compiler object can now return a list of "modes", they are new compiler object specialized for a specific task.
2022-10-18ninja: Simplify getting rule name from compiler objectXavier Claessens1-17/+11
2022-10-13Add b_thinlto_cache for automatically configuring incremental ThinLTOTatsuyuki Ishi1-1/+2
2022-09-27compilers: Cleanup a bit languages/suffixes listsXavier Claessens1-1/+1
Use set where order does not matter, fix is_source() to really mean only source suffixes.
2022-09-26ninjabackend: Fix get_target_generated_sources() return typeXavier Claessens1-10/+7
Type annotation, documentation string, and implementation were doing 3 different things. Change implementation to match type annotation which makes the most sense because it match what get_target_sources() does. All callers only use keys from the returned dictionary any way, but that's going to change in next commits.
2022-09-19pylint: enable consider-using-inDylan Baker1-1/+1
2022-09-19pylint: enable use-maxsplit-argDylan Baker1-1/+1
This finds a bunch of places where we can do more efficient string splitting.
2022-09-19compilers: perform targeted imports for detectEli Schwartz1-1/+1
Only import the ones we need for the language we are detecting, once we actually detect that language. This will allow finally dropping the main imports of these files in a followup commit.
2022-09-19compilers: don't use instance checks to determine propertiesEli Schwartz1-16/+12
In various situations we want to figure out what type of compiler we have, because we want to know stuff like "is it the pgi one", or "does it use msvc style". The compiler object has this property already, via an API specifically designed to communicate this info, but instead we performed isinstance checks on a compiler class. This is confusing and indirect, and has the side effect of requiring more imports everywhere. We should do away with it.
2022-09-12rust: Generate a rust-project.json file when rust targets are presentDylan Baker1-1/+111
When at least one Rust target is present, we now generate a rust-project.json file, which can be consumed by rust-analyzer. This is placed in the build directory, and the editor must be configured to look for this (as it is not a default search path).
2022-09-02backend/ninja: omit --backend when regenerating build dirKonstantin Kharlamov1-3/+1
Currently a cosmetic bug is present: once a build dir was regenerated, meson would start showing: User defined options backend: ninja This is not true as user have not defined the option, it is default. Fix this by omitting the `--backend ninja` parameter from "regenerate" In my tests this does not affect the situation when one specifies `--backend ninja` explicitly, it still shows the backend as user-defined after reconfiguration. Fixes: https://github.com/mesonbuild/meson/issues/10632
2022-08-24backend/ninja: properly track objects extracted from fortran sourcesDylan Baker1-7/+26
We need this to ensure that .mod files are created before we start compiling, and to ensure that the proper include directory arguments are generated.
2022-07-25backends/ninja: run `ranlib -c $out` when using the apple arDylan Baker1-2/+13
Apple's AR is old, and doesn't add externed symbols to the symbol table, instead relying on the user calling ranlib with -c. We need to do that for the user
2022-07-25ninja depscanner: handle C++ sources named capital CEli Schwartz1-2/+6
In commit 4ca9a16288f51cce99624a2ef595d879acdc02d8 we added unreliable support (it warns you if you try it) for gcc-compatible treatment of uppercase-C files being C++ instead of C. In order to handle it correctly, we needed to evaluate can-compile by special-casing "C" to avoid lowercasing it for comparisons. This didn't cover all cases where we check if "C" is a C++ language file. We also straight-up check the language of a file (rather than working backwards to see if a C++ compiler can compile it) when doing module scanning, and this needs to special-case "C" as well. We also had one case where we only checked lowercase fortran extensions, but not lowercase C++ extensions. While we are at it, use lowercase for C++ as well, except the "C" special case. Fixes #10629
2022-07-21ar linker: detect the "osx ld" case (where generating thin archives won't ↵Justin Blanchard1-1/+1
work) based on host OS, not build OS.
2022-07-16Fix finding of Visual studio path in mingw64Ty1-2/+2
Ninja backend will fail to find the vs dep dependency prefix string in a mingw64 environment. This change simply updates the regex to be able to capture mingw64's unique file separation pattern.
2022-06-19Merge pull request #10464 from rtbo/fix_generated_depsJussi Pakkanen1-2/+9
add D generated files to order-only deps
2022-06-17fix parameter expansion in several error messagesMichael Mera1-3/+3
At several points in the code base, f-strings are not correctly expanded due to missing 'f' string prefix. This fixes all the occurrences I could find.
2022-06-14take override_option('unity=...') into account when allowing extract_objects()Paolo Bonzini1-2/+2
A single target could be picked for unity build, and in that case extract_objects() should not be allowed. Likewise for the opposite case, where extract_objects() should be allowed if unity build is disabled for a single target. A test that covers that case is added later.
2022-06-13ninja backend: generate additional meta-rules for test/benchmarks targetsEli Schwartz1-8/+16
'meson-test-prereq' now depends on any targets that were formerly added directly to 'all'. Behavior is not changed -- the all target still depends on this other meta-rule, and thus indirectly depends on all targets it used to depend on. It is now possible to build just the targets needed for the testsuite and then e.g. run `meson test --no-rebuild`.
2022-06-10treewide: various cleanups to move imports for mypy into typechecking blocksEli Schwartz1-2/+3
Along the way, add __future__ annotations where lacking.
2022-06-10flake8: remove import that was never usedEli Schwartz1-1/+0
Introduced via commit 0d0a4fa0fe02ca8297743a5a8e64ee72060cc990, probably in the course of heavy rebasing.
2022-06-09use compilers.lang_suffixes to determine langRemi Thebault1-1/+1
2022-06-08backends/ninja: Add missing type annotationDylan Baker1-1/+1
2022-06-05add D generated files to order-only depsRemi Thebault1-2/+9
2022-06-01modules: move gnome targets into gnome moduleDylan Baker1-1/+2
They're not used outside of the gnome module anyway, and they create some annoying potentials for dependency loops
2022-05-31relax target name restrictions to cater to internal useEli Schwartz1-2/+2
We don't want to allow targets that conflict with: - our aliased meson-* targets for phony commands - any meson-*/ directories we create for internal purposes We do want to allow targets such as: - our own meson-*.X manpages There are a couple routes we could take. Using a better restriction, such as `meson-internal__*`, is trivially done for our aliased targets, but changing directory names is... awkward. We probably cannot do this, and doing the former but not the latter is not very useful. We could also carefully allow patterns we know we won't use, such as file extensions, but which the manpages need, which works for our directories and for many aliased targets, but run_target() is user-specified and can be anything. Use a hybrid approach to cover both use cases. We will now allow target names that fulfill *all* the following criteria: - it begins with "meson-" - it doesn't continue with "internal__" - it has a file extension
2022-05-31ninja backend: simplify generation of phony targetsEli Schwartz1-64/+33
Every phony target has a special indirection rule created because ninja is bad at deleting generated outputs and tries to delete phony outputs too. Instead of invoking this as a separate helper post-creation function to create the alias, wrap NinjaBuildElement and create it behind the scenes. This simplifies target naming and means one less line at every single use site.
2022-05-06Add some scaffolding needed for C++ modules in GCC.Jussi Pakkanen1-0/+2
Further work pending GCC bug #105467 and/or Ninja bug #1962.