aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend
AgeCommit message (Collapse)AuthorFilesLines
2023-09-25Add clang-tidy-fix targetLei YU1-0/+1
Add the `clang-tidy-fix` target to apply clang-tidy fixes to the source code. This is done by calling `run-clang-tidy` with `-fix` argument. Add a test case to run `clang-tidy-fix` and verify the file is changed. Signed-off-by: Lei YU <yulei.sh@bytedance.com>
2023-09-22rust: properly rematerialize static dependencies as well as dynamic onesDylan Baker1-2/+3
Rustc expects to be provided both a search path `-L`, and a link arg `-l kind=libname`, but we don't handle that correctly. Because we combine -L and -l arguments from pkg-config the backend must rematerialize the -L and -l split. We currently don't do this for static archives.
2023-09-19Rust: Fix both_libraries() caseXavier Claessens1-3/+2
Rustc does not produce object files we can reuse to build both libraries. Ideally this should be done with a single target that has both `--crate-type` arguments instead of having 2 different build rules. As temporary workaround, build twice and ensure they don't get conflicts in intermediary files created by rustc by passing target's private directory as --out-dir. See https://github.com/rust-lang/rust/issues/111083.
2023-09-19Rust: Replace rust_crate_type with rust_abiXavier Claessens1-10/+1
Meson already knows if it's a shared or static library, user only need to specify the ABI (Rust or C).
2023-09-18Remove get_pkgconfig_variable()Xavier Claessens1-1/+1
Make sure that pkgconfig_define is a pair of strings and not a list with more than 2 strings.
2023-09-18xcode: Check for apple framework deps by nameAlbert Tang1-6/+5
If `dependencies.platform.AppleFrameworks` has not been imported by this time, Meson crashes. Better to check by name instead.
2023-09-13install_{data,headers,subdir}: implement follow_symlinksArsen Arsenović1-5/+9
This permits users who rely on following symlinks to stay on the old default of following them.
2023-09-10Recognise more include search path opts when populating ↵Dan Hawson1-40/+33
'NMakeIncludeSearchPath' to help intellisense Added to existing '/I' and '-I' extraction with '-isystem', '/clang:-isystem', '/imsvc', '/external:I', which are forms of 'system' header include search path options for gcc, clang, clang-cl, and cl (msvc). Factored 3 separate 'extract_...(...)' functions into one since they were always called together on the same args; a new combined '_extract_nmake_fields(...)' func avoids repeated iterations and checks.
2023-09-07Fix crash when installing a vala library and python sourcesXavier Claessens1-4/+0
Installing python sources causes the python module to call create_install_data() before Ninja backends adds extra outputs to Vala targets. Target objects are supposed to be immutable, adding outputs that late is totally wrong. Add extra vala outputs immediately, but be careful because the main output is only added later in post_init(). Luckily the base class already puts a placeholder item in self.outputs for the main filename so we can just replace self.outputs[0] instead of replacing the whole list which would contain vala outputs at that stage. This is surprisingly what SharedLibrary was already doing.
2023-09-06backends/ninja: run `ranlib -c $out` when using the apple arDylan Baker1-1/+12
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
2023-08-18ninja backend: fix the automatic restat of outputs when reconfiguringEli Schwartz1-3/+3
The most notable problem this causes is that when running `meson setup --reconfigure` the build.ninja file is erroneously seen as out of date, so ninja immediately tries to regenerate it again as it didn't see the file get updated. There are two problems. The first problem is that we looked for the wrong file. Ninja creates a few internal files, and one of them is the one we care about: `.ninja_log`, which contains stat'ed timestamps for build outputs to aid in checking when things are out of date. But the thing we actually checked for is `.ninja_deps`, a file that contains a compressed database of depfile outputs. If the latter exists, then the former surely exists too. Checking for the wrong file meant that we would restat outputs, but only when some build edges were previously built that had depfile outputs. The second problem is that we checked for this in os.getcwd() instead of the configured build directory. This very easily fails to be correct, except when reconfigure is triggered directly by ninja itself, in which case we didn't need the restat to begin with.
2023-08-18Add more descriptive description to CustomTargetCharles Brunet1-2/+2
Allow modules using CustomTarget to modify the command description used by ninja backend. This result in more precise logs when building a project.
2023-08-11remove useless type annotationsEli Schwartz1-2/+2
These annotations all had a default initializer of the correct type, or a parent class annotation.
2023-08-03ExecutableSerialisation: capture and feed are optional stringsXavier Claessens1-6/+6
capture is the optional filename stdout is redirected to. feed is the optional filename stdin reads from.
2023-08-02Optimize extract_dll_paths in ninja backendCharles Brunet1-24/+29
On my project, this function was a bottleneck in setup time. By properly caching it, the cumtime for this function went from 26s to 4.3s when I profiled it.
2023-07-26Fix install_data() default install pathDaniele Nicolodi1-3/+0
This fixes two issues in constructing the default installation path when install_dir is not specified: - inside a subproject, install_data() would construct the destination path using the parent project name instead than the current project name, - when specifying preserve_path, install_data() would construct the destination path omitting the project name. Fixes #11910.
2023-07-25make 'gui_app' an interpreter only conceptDylan Baker2-12/+5
Since it's deprecated anyway, we don't really want to plumb it all the way down into the build and backend layers. Instead, we can just turn it into a `win_subsystem` value in the interpreter if `win_subsystem` isn't already set.
2023-07-24ninjabackend: add or correct various bits of typingEli Schwartz1-24/+24
Down from 607 mypy errors to 379.
2023-07-24ninjabackend: track all outputs using a setEli Schwartz1-3/+3
We need to verify that we don't produce multiple rules for the same file. This uniqueness check is easy to do with a set, but the original old implementation used a dict with True as the value. This isn't a terrible way to implement a set -- we do it for our own internal OrderedSet implementation, even, and back in prehistory (python 2.3) the standard library's set type was one. But it was deleted and replaced with a fast native implementation, and we should too.
2023-07-24ninjabackend: remove useless and unused API bits in phony targetsEli Schwartz1-21/+21
I originally refactored this wrapper function in commit dd2f1c4c57874a0efcd9f6d331985c408101c30d and at the time I made it take the following call pattern: ``` self.create_phony_target(self.all_outputs, ..., implicit_outs=None) ``` I am not sure *why*. There are a couple problems here: - When creating a phony target, there are never implicit outs and we never try to create them. - It's invalid to call it without self.all_outputs as the first argument, so really we should just use that directly. This made the function signature pointlessly longer and more complicated.
2023-07-23backend: fix checking dep instance for xcodeAlbert Tang1-5/+5
2023-07-21Display more timestamps when profiling ninjaCharles Brunet1-0/+7
When running setup with `--profile-self` option, there are currently no logs after "Found ninja...". However, there are still some lengthy processes for generating targets and ninja.build. This add more log entries, when profiling, only for the purpose of displaying the timestamps of the different steps in ninja generation.
2023-07-19fix implicit_reexport issues and enforce them going forwardEli Schwartz1-7/+7
This detects cases where module A imports a function from B, and C imports that same function from A instead of B. It's not part of the API contract of A, and causes innocent refactoring to break things.
2023-07-17Merge pull request #11976 from tristan957/cleanupsJussi Pakkanen1-1/+1
Some various type related cleanups
2023-07-13Fix display of generatorCharles Brunet1-2/+2
2023-07-12Fix return type of debugfile functionsTristan Partin1-1/+1
It was returning None in some cases while being marked as returning string.
2023-07-10backends: Always take options from targetXavier Claessens4-30/+32
This fixes cases where override_options is not being used. Fixes: #11923
2023-07-10Revert "backends: Cache creation of install data"Eli Schwartz1-1/+0
This reverts commit 904b47085fdd985175b4b2c3224f65b9d33f04d7. This is not a real bottleneck, and we want to create it thrice -- once before the backend is generated. The final install data needs to be created fresh. Update unittest to demonstrate the issue. Fixes https://bugs.gentoo.org/910050
2023-07-05Merge pull request #11742 from xclaesse/link-whole-casesJussi Pakkanen2-3/+17
Fix niche cases when linking static libs
2023-07-02genvslite: greatly simplify the implementation of non-genvslite backendsEli Schwartz5-31/+23
By avoiding Java-style variable naming, the code becomes considerably more readable while simultaneously becoming *more* easy to understand. It's no longer necessary to ask questions like "what's a captured buildtype" when trying to read through the code for a backend, because it can be dismissed as not relevant to the current context by re-reading it as "context for vslite". The primary goal here has been to revert regressions in the developer experience for users of the ninja backend, so there may still be issues in vs2010backend.py Post-facto application of issues that were raised during review, ignored, and merged despite such.
2023-06-28Experimental 'genvslite' WIP. (#11049)GertyP6-337/+886
* Capture all compile args from the first round of ninja backend generation for all languages used in building the targets so that these args, defines, and include paths can be applied to the .vcxproj's intellisense fields for all buildtypes/configurations. Solution generation is now set up for mutiple build configurations (buildtypes) when using '--genvslite'. All generated vcxprojs invoke the same high-level meson compile to build all targets; there's no selective target building (could add this later). Related to this, we skip pointlessly generating vcxprojs for targets that aren't buildable (BuildTarget-derived), which aren't of interest to the user anyway. When using --genvslite, no longer inject '<ProjectReference ...>' dependencies on which a generated .vcxproj depends because that imposes a forced visual studio build dependency, which we don't want, since we're essentially bypassing VS's build in favour of running 'meson compile ...'. When populating the vcxproj's shared intellisense defines, include paths, and compiler options fields, we choose the most frequent src file language, since this means more project src files can simply reference the project shared fields and fewer files of non-primary language types need to populate their full set of intellisense fields. This makes for smaller .vcxproj files. Paths for generated source/header/etc files, left alone, would be added to solution projects relative to the '..._vs' build directory, where they're never generated; they're generated under the respective '..._[debug/opt/release]' ninja build directories that correspond to the solution build configuration. Although VS doesn't allow conditional src/header listings in vcxprojs (at least not in a simple way that I'm aware of), we can ensure these generated sources get adjusted to at least reference locations under one of the concrete build directories (I've chosen '..._debug') under which they will be generated. Testing with --genvslite has revealed that, in some cases, the presence of 'c:\windows\system32;c:\windows' on the 'Path' environment variable (via the make-style project's ExecutablePath element) is critical to getting the 'meson compile ...' build to succeed. Not sure whether this is some 'find and guess' implicit defaults behaviour within meson or within the MSVC compiler that some projects may rely on. Feels weird but not sure of a better solution than forcibly adding these to the Path environment variable (the Executable Path property of the project). Added a new windows-only test to windowstests.py ('test_genvslite') to exercise the --genvslite option along with checking that the 'msbuild' command invokes the 'meson compile ...' of the build-type-appropriate-suffixed temporary build dir and checks expected program output. Check and report error if user specifies a non-ninja backend with a 'genvslite' setup, since that conflicts with the stated behaviour of genvslite. Also added this test case to 'WindowsTests.test_genvslite' I had problems tracking down some problematic environment variable behaviour, which appears to need a work-around. See further notes on VSINSTALLDIR, in windowstests.py, test_genvslite. 'meson setup --help' clearly states that positional arguments are ... [builddir] [sourcedir]. However, BasePlatformTests.init(...) was passing these in the order [sourcedir] [builddir]. This was producing failures, saying, "ERROR: Neither directory contains a build file meson.build." but when using the correct ordering, setup now succeeds. Changed regen, run_tests, and run_install utility projects to be simpler makefile projects instead, with commands to invoke the appropriate '...meson.py --internal regencheck ...' (or install/test) on the '[builddir]_[buildtype]' as appropriate for the curent VS configuration. Also, since the 'regen.vcxproj' utility didn't work correctly with '--genvslite' setup build dirs, and getting it to fully work would require more non-trivial intrusion into new parts of meson (i.e. '--internal regencheck', '--internal regenerate', and perhaps also 'setup --reconfigure'), for now, the REGEN project is replaced with a simpler, lighter-weight RECONFIGURE utility proj, which is unlinked from any solution build dependencies and which simply runs 'meson setup --reconfigure [builddir]_[buildtype] [srcdir]' on each of the ninja-backend build dirs for each buildtype. Yes, although this will enable the building/compiling to be correctly configured, it can leave the solution/vcxprojs stale and out-of-date, it's simple for the user to 'meson setup --genvslite ...' to fully regenerate an updated, correct solution again. However, I've noted this down as a 'fixme' to consider implementing the full regen behaviour for the genvslite case. * Review feedback changes - - Avoid use of 'captured_compile_args_per_buildtype_and_target' as an 'out' param. - Factored a little msetup.py, 'run(...)' macro/looping setup steps, for genvslite, out into a 'run_genvslite_setup' func. * Review feedback: Fixed missing spaces between multi-line strings. * 'backend_name' assignment gets immediately overwritten in 'genvslite' case so moved it into else/non-genvslite block. * Had to bump up 'test cases/unit/113 genvslites/...' up to 114; it collided with a newly added test dir again. * Changed validation of 'capture' and 'captured_compile_args_...' to use MesonBugException instead of MesonException. * Changed some function param and closing brace indentation.
2023-06-27Merge pull request #11902 from dcbaker/submit/rust-module-enhancementsJussi Pakkanen1-1/+59
Rust module enhancements for mesa
2023-06-27Archive shared library in AIX (#11850)Aditya Kamath1-0/+22
* Archive shared library in AIX This code change to ensure we archive shared libraries in AIX. The things we do are: Archive shared library Install archived shared library Build all must build the archived shared library blibpath must have the archived shared library dependency. * Archive shared library in AIX. Made changes as per the review comments given in the first PR request. They are:- Use self.environment.machines[t.for_machine].is_aix() Remove trial spaces Use of val instead of internal Changed comments wherever requested * Space after octothorpe * Fixed failed test case causing build break during install section * Moved AIX specific code to AIXDynamicLinker from backend * Fix indentation, trailing spaces, add type annotations and Linux/macOS build break * Remove some more trailing space issues * Fixed the wrong return type in linkers
2023-06-27rust: Override the default MSVCRT when linking Rust and !rust togetherDylan Baker1-1/+54
Rust by default links with the default MSVCRT, (dynamic, release). MSVCRT's cannot be mixed, so if Meson compiles a C or C++ library and links it with the debug MSVCRT, then tries to link that with the Rust library there will be failures. There is no built-in way to fix this for rustc, so as a workaround we inject the correct arguments early in the linker line (before any libs at least) to change the runtime. This seems to work and is recommended as workaround in the upstream rust bug report: https://github.com/rust-lang/rust/issues/39016. Given that this bug report has been opened since 2017, it seems unlikely to be fixed anytime soon, and affects all (currently) released versions of Rust.
2023-06-27rust: get stdlib arguments for non-rust languages when linkingDylan Baker1-0/+5
Otherwise we might not get things like libstdc++, which we need.
2023-06-26Revert "modules: move gnome targets into gnome module"Eli Schwartz1-2/+1
This reverts commit a2def550c586aeba4269588e79a1a308467f2582. This results in a 2k line file being unconditionally imported at startup, and transitively loading two more (for a total cost of 2759 lines of code), and it's not clear it was ever needed to begin with...
2023-06-26linkers: delay implementations import until detect is runEli Schwartz2-2/+2
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 ab20eb5bbc21ae855bcd211131132d2778602bcf.
2023-06-26fix regression in handling output overwriting for ar-like linkersEli Schwartz1-2/+2
Linkers that aren't actually ar, were refactored into a base class in commit 253ff71e6b801786290b6ecb23aea61dcfeebeca, which however didn't take into account that we were doing checks for this.
2023-06-26tree-wide: reduce unneeded imports on specific Dependency implsEli Schwartz2-7/+8
We can check something's subtype using properties, without importing the module up front and doing isinstance checks on specific subclasses of the interface -- or worse, solving cyclic imports by doing the import inside the function. ;)
2023-06-21rust: fix -C prefer-dynamic behaviorAlyssa Ross1-9/+10
I noticed when building a project that uses a proc macro that Meson passed -C prefer-dynamic for the executable, and not the proc macro, while cargo passed -C prefer-dynamic for the proc macro, but not for the executable. Meson's behavior broke setting -C panic=abort on the executable. As far as we can tell, because we explicitly pass each library path to rustc, the only thing -C prefer-dynamic affects in Meson is how the standard libraries are linked. Generally, one does not want the standard libraries to be dynamically linked, because if the Rust compiler is ever updated, anything linked against the old standard libraries will likely break, due to the lack of a stable Rust ABI. Therefore, I've reorganised Meson's behavior around the principle that the standard libraries should only be dynamically linked when Rust dynamic linking has already been opted into in some other way. The details of how this manifests are now explained in the documentation.
2023-06-20backends/vs: add sundry type annotationsEli Schwartz1-25/+28
We went from 192 mypy errors down to 144.
2023-06-20backends/xcode: simplify an obviously too-complicated functionEli Schwartz1-6/+3
This function has a pretty unique name, and a simple grep shows that it is only ever called as: ``` add_comment(PbxComment('...........')) ``` It doesn't need to include logic such as handling str. Moreover it looks like that handling was broken anyway... it handled the case where comment is type str, by constructing a new PbxComment(str) instead of PbxComment(comment), a condition that cannot ever be valid (and crashed due to other assertions). Fixes: mesonbuild/backend/xcodebackend.py:148:42: error: Argument 1 to "PbxComment" has incompatible type "type[str]"; expected "str" [arg-type]
2023-06-20delete dead code that has never been referencedEli Schwartz1-5/+0
2023-06-20backends/xcode: various sundry low-effort typing fixesEli Schwartz1-36/+36
I slapped the obvious type annotations onto a bunch of places, and got the errors down from 668 to 112.
2023-06-20backends/ninja: add sundry typing improvementsEli Schwartz1-18/+20
2023-06-20use truncating division for code that explicitly needs an intEli Schwartz1-1/+1
We are going to truncate it down below with int() anyway, no need to carry extra precision. And mypy complains if the type changes between float and int.
2023-06-20ninja backend: simplify code by using dataclassesEli Schwartz1-2/+2
2023-06-11ninja backend: fix cleandead deleting files that meson implicitly createsEli Schwartz1-3/+13
Specifically, when those files can be created by a build rule with one version of meson.build, and created as e.g. a shared_library alias symlink in another version of meson.build, the cleandead command will delete important files just because they don't happen to be created by ninja itself. Work around this by making a dummy rule that exists solely to insert the files into the build graph to trick ninja into not deleting them. Closes #11861
2023-05-31preprocess: Allow preprocessing any file extensionsXavier Claessens1-2/+8
2023-05-29avoid endless reconfigure loops when a build directory is copied aroundEli Schwartz1-1/+3
ninja's configured command for regenerating a build directory on any action that *requires* reconfiguring, specifies the source and build directories as they were known during initial project generation. This means that if the build directory is no longer the *same* build directory, we will regenerate... the original location, rather than the location we want. After that, ninja notices that build.ninja is still out of date, so it goes and reconfigures again. And again. And again. This is probably broken intentions, but endless reconfigure loops are a kind of evil beyond all evils. There are no valid options here whatsoever other than: - doing what the user actually meant - spawning a clear error message describing why meson refuses to work, then exiting with a fatal error But it turns out that it's actually pretty easy to do what the user actually meant, and reconfigure the current build directory instead of the original one. This permanently breaks the link between the two. Fixes #6131