Promote `rc` (Windows resource compiler) to a proper Meson language

`rc` is now a first-class Meson language, just like `nasm` or `masm`.
Users can declare it with `project('foo', 'c', 'rc')` or
`add_languages('rc')`, and pass `.rc` files directly as sources to build
targets. The `RCFLAGS` environment variable and
`add_project_arguments(language: 'rc')` now work as expected.

Fix #4736

Once we are making a real language and not hand-rolling a simulacrum of
one, it is easy to support `RCFLAGS`. In fact, it is hard to *forget* to
support `RCFLAGS` --- that's the beauty of using existing abstractions.

This is not the easiest way to fix #4736, but I do think it is the best
way long term, because it helps ensure other deviations from how
language support is supposed to work --- of which a missing `*FLAGS`
variable is just one possible example --- are also far less likely.

The issue I am most worried about is the treatment of `depends` and
`depend_files`. As described in the docs, those have to be
hand-migrated, and the result is slightly different behavior in terms of
which exact build steps depend on what. The lack of fine-grained code of
compilation vs linking build depends, or per-language depends (so we
don't have to make assumptions about compilation units) is certainly
preexisting, and arguably a problem. So one could say well that should
be fixed first before we write our shim.

Implementation details:

**Resource Compiler hierarchy** mirrors the `GnuLikeCompiler` /
`VisualStudioLikeCompiler` split used for C/C++:

- `VisualStudioLikeResourceCompiler` — `/I`, `/fo`, `/nologo`, `.res`
  suffix
  - `WindowsResourceCompiler` (`rc.exe`)
  - `LlvmRcCompiler` (`llvm-rc`)
- `GnuLikeResourceCompiler` — `-I`, `-o`, `.o` suffix
  - `WindresCompiler` (`windres`)
  - `LlvmWindresCompiler` (`llvm-windres`)
  - `WineResourceCompiler` (`wrc`)

**`windows.compile_resources()`** is now a thin deprecated shim that
ensures the `rc` language is detected and returns the source files for
the normal compile pipeline to handle.

Key changes:

- `mesonbuild/compilers/rc.py`: new file with the mixin hierarchy
  described above

- `mesonbuild/compilers/detect.py`: `detect_rc_compiler()` function

- `mesonbuild/compilers/compilers.py`: `rc` in `Language`,
  `lang_suffixes`, `CFLAGS_MAPPING`; new `get_object_suffix()` on
  `Compiler` base class

- `mesonbuild/envconfig.py`: `rc` moved from `ENV_VAR_TOOL_MAP` to
  `ENV_VAR_COMPILER_MAP` (supports both `RC` and `WINDRES` env vars)

- `mesonbuild/backend/backends.py`: use `compiler.get_object_suffix()`
  for output file extension

- `mesonbuild/backend/ninjabackend.py`: skip link rule generation for
  compilers without a linker (`rc`)

- `mesonbuild/modules/windows.py`: simplified from 196 to ~80 lines
16 files changed
tree: 1f5ab471dbd9ed5ae90dfbc76ed5185f4b0ad8c1
  1. .github/
  2. ci/
  3. cross/
  4. data/
  5. docs/
  6. graphics/
  7. man/
  8. manual tests/
  9. mesonbuild/
  10. packaging/
  11. test cases/
  12. tools/
  13. unittests/
  14. .editorconfig
  15. .flake8
  16. .gitattributes
  17. .gitignore
  18. .mailmap
  19. .mypy.ini
  20. .pylintrc
  21. azure-pipelines.yml
  22. CODEOWNERS
  23. contributing.md
  24. COPYING
  25. MANIFEST.in
  26. meson.py
  27. pyproject.toml
  28. README.md
  29. run_cross_test.py
  30. run_format_tests.py
  31. run_meson_command_tests.py
  32. run_mypy.py
  33. run_project_tests.py
  34. run_shell_checks.py
  35. run_single_test.py
  36. run_tests.py
  37. run_unittests.py
  38. setup.cfg
  39. setup.py
  40. skip_ci.py
README.md

Status

PyPI Build Status Codecov

Dependencies

  • Python (version 3.7 or newer)
  • Ninja (version 1.8.2 or newer)

Latest Meson version supporting previous Python versions:

  • Python 3.9: 1.11
  • Python 3.8: 1.11
  • Python 3.7: 1.11
  • Python 3.6: 0.61.5
  • Python 3.5: 0.56.2
  • Python 3.4: 0.45.1

Installing from source

Meson is available on PyPI, so it can be installed with pip3 install meson. The exact command to type to install with pip can vary between systems, be sure to use the Python 3 version of pip.

If you wish you can install it locally with the standard Python command:

python3 -m pip install meson

For builds using Ninja, Ninja can be downloaded directly from Ninja GitHub release page or via PyPI

python3 -m pip install ninja

More on Installing Meson build can be found at the getting meson page.

Creating a standalone script

Meson can be run as a Python zip app. To generate the executable run the following command:

./packaging/create_zipapp.py --outfile meson.pyz --interpreter '/usr/bin/env python3' <source checkout>

Running

Meson requires that you have a source directory and a build directory and that these two are different. In your source root must exist a file called meson.build. To generate the build system run this command:

meson setup <source directory> <build directory>

Depending on how you obtained Meson the command might also be called meson.py instead of plain meson. In the rest of this document we are going to use the latter form.

You can omit either of the two directories, and Meson will substitute the current directory and autodetect what you mean. This allows you to do things like this:

cd <source root>
meson setup builddir

To compile, cd into your build directory and type ninja. To run unit tests, type ninja test.

More on running Meson build system commands can be found at the running meson page or by typing meson --help.

Contributing

We love code contributions. See the contribution page on the website for details.

IRC

The channel to use is #mesonbuild either via Matrix (web interface) or OFTC IRC.

Further info

More information about the Meson build system can be found at the project's home page.

Meson is a registered trademark of Jussi Pakkanen.