aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
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-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-07-25make 'gui_app' an interpreter only conceptDylan Baker1-5/+2
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-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-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 Claessens1-11/+10
This fixes cases where override_options is not being used. Fixes: #11923
2023-07-05Merge pull request #11742 from xclaesse/link-whole-casesJussi Pakkanen1-1/+1
Fix niche cases when linking static libs
2023-07-02genvslite: greatly simplify the implementation of non-genvslite backendsEli Schwartz1-5/+3
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)GertyP1-2/+47
* 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 Schwartz1-1/+1
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-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/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
2023-05-21Allow generator.process(generator.process(...))Volker Weißmann1-1/+4
Fixes #1141
2023-05-20rust: Add system libs used by rust std to staticlib external depsXavier Claessens1-0/+3
2023-05-15Metrowerks: move PCH args to the end of the command lineNomura1-1/+7
2023-05-13Fix paths of Fortran order dependenciesVolker Weißmann1-4/+5
Fixes #11047
2023-05-01extract_all_objects: Include PCH object with MSVCXavier Claessens1-1/+1
This changes the object file name with ninja backend to match the name used by vs backend and add it in outputs of the ninja rule.
2023-04-27Don't use dyndep scanner when preprocessingVolker Weißmann1-0/+2
Fixes #11504
2023-04-24Initial support for Metrowerks C/C++ compilerNomura1-1/+17
2023-04-21rust: Add new `rust_dependency_map` target configurationSebastian Dröge1-11/+9
This allows changing the crate name with which a library ends up being available inside the Rust code, similar to cargo's dependency renaming feature or `extern crate foo as bar` inside Rust code.
2023-04-20intro: add more details to generated json filesCharles Brunet1-18/+43
This will help with the writing of tools to generate VisualStudio project and solution files, and possibly for other IDEs as well. - Used compilers a about `host`, `build` and `target` machines arere listed in `intro-compilers.json` - Informations lister in `intro-machines.json` - `intro-dependencies.json` now includes internal dependencies, and relations between dependencies. - `intro-targets.json` now includes dependencies, `vs_module_defs`, `win_subsystem`, and linker parameters.
2023-04-20rust: Also disallow `.` in Rust library target namesSebastian Dröge1-2/+2
2023-04-19rust: Don't use prefer-dynamic in case of proc-macro Rust dependenciesSebastian Dröge1-2/+3
They're only used at build-time and whether they exist or not should not have any effect on the final build artifact.
2023-04-14rust: Use `isinstance(d, build.StaticLibrary)` instead of comparing the type ↵Sebastian Dröge1-1/+1
name string
2023-04-14rust: Link staticlib/cdylib link targets like link targets from any other ↵Sebastian Dröge1-1/+4
language staticlib/cdylib only provide a C ABI, i.e. contain no Rust metadata, and can be linked like a link target from any other language.
2023-04-14rust: Don't prefer dynamic linking of Rust libraries for cdylibsSebastian Dröge1-5/+9
cdylibs provide a plain C ABI to its consumers and should not be treated like dylib/proc-macro shared libraries that provide a Rust ABI.
2023-04-14rust: Convert dashes in crate names to underscoresSebastian Dröge1-4/+14
Dashes can't be used as identifiers in Rust and cargo is converting dashes in crate names to underscores for the same reason.