Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Meson presets #10421

Open
rilian-la-te opened this issue May 24, 2022 · 9 comments
Open

Feature Request: Meson presets #10421

rilian-la-te opened this issue May 24, 2022 · 9 comments

Comments

@rilian-la-te
Copy link
Contributor

It would be nice to support MesonPresets.json file in source root, which should be like CMakePresets.json. Then subprojects can define their preferred build modes with presets, and main projects too.

And for use writing JSON once is better, than wrtite a bunch of commandline options every time. And for IDEs JSON is good.

I do not think than CMakePresets.json can be supported directly, but file like this (for automating commandline options and just write like meson --preset to get automatic build is very nice for CI and reproducible builds approach in conjunction with cross-file.

@eli-schwartz
Copy link
Member

Machine files can already contain built-in/project options (anything that is a -D command-line option), so as far as I can tell the feature you want already exists?

@rilian-la-te
Copy link
Contributor Author

@eli-schwartz how to do it automatically like cmake --preset 'clang-release'?

CMake then reads preset from file (not only cache -D variables, but also binary dir, destdir, toolchain file, build configuration and other), and configure itself. Next thing we can do 'cmake --build --preset 'clang-release', and if build subpreset 'clang-release' is defined and inherits first preset, then we can use build configuration and other fancy things.

@eli-schwartz
Copy link
Member

I'm not sure I understand the question.

CC=clang meson setup builddir -Dbuildtype=release -Dc-args=... -Dfoobar=baz -Db_lto=true -Db_ndebug=true ...

Becomes

meson setup builddir --native-file presets/release.ini

This is the same way you'd use any machine file.

What is a "build subpreset"? Only meson setup has configuration options, running ninja doesn't have configuration options -- all you can do is control system resource usage e.g. parallelism by way of number of cores, system load, etc. or debug ninja itself via -d explain or interactively choose to only build one or two targets.

@rilian-la-te
Copy link
Contributor Author

rilian-la-te commented May 24, 2022

@eli-schwartz I see. So, one native file per preset. It is possible to set builddir in native file? CMake Presets have such a feature.

Let's say :

meson --native-file presets/release.ini #should define also build directrory, where meson runs.
meson --compile --native-file presets/release.ini #should invoke ninja in that build directory
meson --install --native-file presets/release.ini #should invoke ninja in that build directory

And such with all meson commands. It is possible now?

Build subpreset define CMake build options (parallelism, sysload and more), which, in fact, goes to ninja or any other generator (VS, XCode)

@eli-schwartz
Copy link
Member

Presets make zero sense for the compile and install commands. They will not be added to Meson and if cmake supports this then this is a bug in cmake's option parsing because they use flags instead of subcommands. This should be reported to cmake upstream and fixed.

@eli-schwartz
Copy link
Member

It is possible to set builddir in native file? CMake Presets have such a feature.

This is currently not possible.

Also it is ambiguous if the builddir is relative (is it relative to your current directory or to the source tree?) and probably broken if it is absolute (only works on one machine, cannot be checked into git) so I wonder what the best choice here is?

Intuitively this doesn't feel like a profile setting, which I guess is why no one thought to make it one before.

@rilian-la-te
Copy link
Contributor Author

@eli-schwartz differences between native files and CMake presets:

  1. It is not a bug in CMake, because they have 3 types of presets - configure + build + test. And for each mode it is possible to do a preset. Presets in this 3 forms is relatively new, and appeared only in CMake 3.20+.
  2. Builddir is relative. It is not ambiguous, because one native file with builddir should invoke meson in same builddir again and again, calling wipe, if settings in native file allows to.
  3. And Meson AFAIK (but I can guess wrong) does not have default location of native files, like cross-files on Meson can be located system-wide or project-wide. CMake has default project-wide location for presets to invoking.

@eli-schwartz
Copy link
Member

Meson already has presets for test, but they are used via add_test_setup() inside meson.build and invoked via meson test --setup=name.

Having special names to build a specific group of targets is possible via alias_target() and build_by_default: <bool> and cmake has similar concepts, so I don't see any point of cmake including "presets" for this.

I see no point in confusingly sharing a file format for setting up configuration options that also supports ignoring most of the file and just using a builddir for non--setup commands. Also, the command-line option to specify a preset is longer to type than -C builddir.

I still believe that cmake is wrong here, but okay, apparently they deliberately added broken concepts. 🤷‍♂️

@xclaesse
Copy link
Member

It seems to me most is already covered by native files indeed. Not sure it really makes sense to have the builddir in a preset, worst case you can also just ship a small configure.sh wrapper that calls "meson setup builddir --native-file presets/foo.ini" if you really want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants