aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend
AgeCommit message (Collapse)AuthorFilesLines
2023-03-30backend/vs: ensure that build dir is preferred to src dirBarnabás PƑcze1-1/+2
Previously, the VS backend would add the the include directories in the reverse order that the Ninja backend does it, which means that the source directories would be preferred over the build directories. For example, this would cause the compiler to choose the file from the source directory if a file with the same name is found in both. Fixes 57ec097b5 ("vs: Use CompilerArgs() for compile and link args") Fixes #11630
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-28backends: fix bug where meson_exe crashed if constructed with found programsEli Schwartz1-1/+1
Because we base the pickled data name on the name property of the command being run... and for built targets, `exe.name` is always just the name. However, for an ExternalProgram this is just whatever string we searched for, so, NOT just the basename. This became a bigger issue once we started using generator() with the actual program in commit 6aeec808367f05463394e30a8d40834e97c7afc0, rather than first casting it to a string, because the VS backend *always* uses the meson_exe approach for various reasons related to VS being VS. Outside of that, it's difficult to actually get an ExternalProgram object passed to meson_exe -- CustomTarget lowers it to a string, capture is handled via argparse instead of pickling, etc. Fixes #11593
2023-03-28Add support for meson.options as a replacement for meson_options.txtDylan Baker1-0/+1
We will still try to load `meson_options.txt` if `meson.options` doesn't exist. Because there are some advantages to using `meson.options` even with older versions of meson (such as better text editor handling) we will not warn about the existence of a `meson.options` file if a `meson_options.txt` file or symlink also exists. The name `meson.options` was picked instead of alternative proposals, such as `meson_options.build` for a couple of reasons: 1. meson.options is shorter 2. While the syntax is the same, only the `option()` function may be called in meson.options, while, it may not be called in meson.build 3. While the two files share a syntax and elementary types (strings, arrays, etc), they have different purposes: `meson.build` declares build targets, `meson.options` declares options. This is similar to the difference between C's `.c` and `.h` extensions. As an implementation detail `Interpreter.option_file` has been removed, as it is used exactly once, in the `project()` call to read the options, and we can just calculate it there and not store it. Fixes: #11176
2023-03-27find dll path on WindowsCharles Brunet1-10/+34
When running tests on Windows (or for devenv), paths of shared libraries need to be added to the PATH envvar for Windows to be able to find them. Meson is currently using the path of the import lib, which is wrong in many cases. This fix does two things: if there is a variable bindir in the pkg-config file, those variable values are added to the list of path. This is for conan dependencies, if conan decides to export those paths. See https://github.com/conan-io/conan/issues/13532 . The fallback is to replace `lib` by `bin` in the import library path. This heuristic will work most of the time (but the bin directory could have a different name, or the dll itself could have a different name). In all cases, it cannot be worse than current implementation, and it solves many cases.
2023-03-20backends: add a new "none" backendEli Schwartz2-0/+34
It can only be used for projects that don't have any rules at all, i.e. they are purely using Meson to: - configure files - run (script?) tests - install files that exist by the end of the setup stage This can be useful e.g. for Meson itself, a pure python project.
2023-03-20backends: simplify class setupEli Schwartz9-9/+25
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-03-01backends: fix source dir stripping from rpathsStefan Hajnoczi1-2/+9
Commit e88887be4a08 ("Only remove substring if it is part of string") removed the source dir from the rpath when the following check succeeds: if absdir.startswith(self.environment.get_source_dir()): rel_to_src = absdir[len(self.environment.get_source_dir()) + 1:] For example, absdir '/myproject/foo' starts with source dir '/myproject', so we want to generate the relative path 'foo'. This code doesn't work with absdir '/myproject-libs/foo' though, because we'll incorrectly turn it into a relative path 'libs/foo' after stripping away '/myproject-'. Use os.path.commonpath() instead of str.startswith() so path components are correctly handled. Cc: Niklas Claesson <niklas.claesson@cosylab.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
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 Baker3-7/+6
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
2023-01-03backends/backends: Add helpful message for getting rid of warningDylan Baker1-1/+1
2022-12-27add builtin option to install licensesEli Schwartz1-6/+12
Unless `meson.install_dependency_manifest()` is explicitly used, this will cause a default implied one to be installed.
2022-12-27add license_files kwarg to projectEli Schwartz1-0/+8
Hook this up to installed dependency manifests. This is often needed above and beyond just an SPDX string -- e.g. many licenses have custom copyright lines.
2022-12-07Remove useless EmptyExternalProgramXavier Claessens1-4/+1
It is only used by Environment.get_exe_wrapper() and every callers were handling None already. Type annotation was wrong, it already could return None for the case an exe wrapper is needed but none is provided.
2022-12-07devenv: Always include env for HOST machineXavier Claessens1-3/+1
Cross compiled executables could still be run with an exe wrapper, or with proper binfmt installed. Fixes: #10999
2022-12-07devenv: Add executables locations to both PATH and WINEPATHXavier Claessens1-7/+12
Handles the case when wine-binfmt is installed, which makes .exe files executable without without specifying an exe wrapper.
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 Baker2-3/+3
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-30tests: Write out LD_LIBRARY_PATH for built shared librariesDaniel Stone1-1/+14
When a test executable references a local shared library, make sure that we apply the appropriate $LD_LIBRARY_PATH so that the linker can find it at runtime. The DT_RUNPATH entry does ensure that the binary references the path to the shared library build, however the RUNPATH list is only searched after $LD_LIBRARY_PATH. So if the user has a shared library of the same name in their $LD_LIBRARY_PATH, this will be the version found and used for running the test. This is bad if you're trying to use Meson to test a shared library you're developing and have installed in a local prefix which is under $LD_LIBRARY_PATH. Fixes #1635
2022-11-29pylint: enable the bad_builtin checkerDylan Baker2-3/+3
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-24Fix various spelling errorsDavid Robillard1-1/+1
Found with codespell.
2022-11-17backend/ninja: replace ` ` with `_` in rust crate-namesDylan Baker1-2/+2
Because spaces aren't allowed and result in compilation failures
2022-11-10Fix options overrides for vsbackendDenis Fortin1-1/+1
Use OptionOverrideProxy instead of pure options. Closes #10393
2022-11-02backends: Try guessing install tag for all installed filesXavier Claessens1-3/+11
It was only trying to guess install tag, and log missing tags, for files installed by install_data(). Do it also for all other files, especially custom_taget() that commonly installs generated headers.
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-23vs backend: Add support for CompileTargetXavier Claessens2-0/+46
Since vs backend only support the C compiler, everything else are custom targets. Convert CompileTarget into a Generator to reuse existing code. This will be useful in the future to support transpilers, and assemblers.
2022-10-23Add cc.preprocess() method for c-like compilersXavier Claessens2-0/+5
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-13fix: don't set FavorSizeOrSpeed in vs backend if optimization disabled (/Od ↔Luke Elliott1-1/+2
set). Debugging is broken with clang-cl when FavorSizeOrSpeed is set.
2022-10-13Add b_thinlto_cache for automatically configuring incremental ThinLTOTatsuyuki Ishi1-1/+2
2022-10-09run wrapped-due-to-env commands on unix via the env programEli Schwartz1-1/+18
First, check if the env program exists. If it does, it is faster than doing it via a python script `basically-env.py` that maybe imports all of mesonbuild.* as a side effect of project structure. We do not, however, use env for setting up PATH additions, since env can override an environment variable but not extend it. So in that case we still need to wrap the command via python. By default, all run_targets (at least) are wrapped and now wrap via the `env` program as they export e.g. MESONINTROSPECT='/usr/bin/meson introspect'
2022-10-09compilers: Add optimization=plain optionJan Tojnar1-2/+5
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-04pylint: enable consider-merging-isinstanceDylan Baker1-1/+1
2022-10-03pylint: enable unnecessary-lambdaDylan Baker1-1/+1
2022-09-29Add cross-compile support for Microsoft GDK platformsCaleb Cornett1-2/+9
2022-09-28Move classes used by scripts to their own moduleXavier Claessens1-22/+2
Those classes are used by wrapper scripts and we should not have to import the rest of mesonlib, build.py, and all their dependencies for that. This renames mesonlib/ directory to utils/ and add a mesonlib.py module that imports everything from utils/ to not have to change `import mesonlib` everywhere. It allows to import utils.core without importing the rest of mesonlib.
2022-09-28Automatically tag systemtap filesXavier Claessens1-0/+2