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

meson.setupHook: prefer meson commands over ninja #213845

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

alyssais
Copy link
Member

@alyssais alyssais commented Jan 31, 2023

Description of changes

Meson now comes with its own set of commands for building, testing, installing etc., that by default wrap around Ninja. The reason to prefer using the Meson commands is that they take additional options (e.g. setting custom timeouts for tests — my motivation for this change).

Here, I've modified the Meson setup hook so instead of Ninja being run automatically, Meson's equivalent commands will be if Meson is present. This only happens when Meson is used to configure, to avoid starting to run Meson directly when dealing with custom build systems that wrap around Meson, like QEMU's.

Naturally the Meson commands don't support entirely the same set of options that the Ninja ones did, but I checked through Nixpkgs to find any packages using Meson that used any options that wouldn't be picked up by this new system. I only found one, and it was just setting checkTarget = "test", which is the default value for Ninja and has no Meson equivalent (because we directly tell Meson to run the tests rather than going through a generic job system like Ninja).

I've tested building all the way to qemu_kvm, which I chose because it has lots of dependencies built with Meson, and also has its own custom Meson-wrapping build system so I could be sure that also still worked.

Fixes, partially: #113829

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@alyssais alyssais requested a review from jtojnar January 31, 2023 20:51
Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, wanted this for a while now: #113829

Copy link

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason to prefer using the Meson commands is that they take additional options (e.g. setting custom timeouts for tests — my motivation for this change).

  • The functionality that is implemented in python (meson foobar subcommands) come with convenience targets in ninja, that run the python tools.
  • The functionality that is implemented in ninja comes with a convenience target in python, that simply runs ninja.

Practically speaking, this means that if you want the default functionality, you can more or less use either entry point interchangeably.

The difference between the two is that building is purely ninja, and everything else is implemented in python. So it makes sense to run meson test and meson install directly if you want to pass additional options, but there's no advantage to running meson compile <args> since it will do nothing other than subprocess out to ninja <args>.

... Oh wait, actually that's not quite true. On Windows, meson compile will first run vcvarsall.bat to set up an MSVC dev cmd environment, if you're using the MSVC compiler and didn't start off in one. This functionality has no reason to exist except that ninja's feature request to not be broken by default, but rather to include functionality for loading an environment block at startup, is in limbo. You don't need this if you use a sane operating system, or if you use a mingw-based compiler even on Windows.

@alyssais
Copy link
Member Author

@eli-schwartz thanks for the clarification/explanation! I appreciate it.

@alyssais
Copy link
Member Author

v2:

  • Drop mesonBuildPhase.
  • Move phase overrides into mesonConfigurePhase to avoid setup hook ordering problems.
  • Don't set TERM=dumb for check/install (which ends up being not at all since we dropped mesonBuildPhase).
  • Fix the flags typos noticed by @jtojnar.

I'll do another test build through qemu_kvm, but once review has settled down because it takes a long time.

@alyssais
Copy link
Member Author

alyssais commented Feb 3, 2023 via email

@alyssais
Copy link
Member Author

alyssais commented Feb 3, 2023

Tested building through to qemu_kvm again.

@alyssais alyssais requested a review from jtojnar February 5, 2023 11:13
Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +31 to +33
if [[ ${checkPhase-ninjaCheckPhase} = ninjaCheckPhase && -z $dontUseMesonCheck ]]; then
checkPhase=mesonCheckPhase
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this in configurePhase will only work when it is not overridden. But I probably would not bother with this too much until someone comes up with an use case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found only one usage of an overridden configurePhase with meson.
#259835

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Feb 11, 2023
@alyssais alyssais requested a review from jtojnar February 11, 2023 17:25
Meson now comes with its own set of commands for building, testing,
installing etc., that by default wrap around Ninja.  The reason to
prefer using the Meson commands is that they take additional
options (e.g. setting custom timeouts for tests — my motivation for
this change).

Here, I've modified the Meson setup hook so that Meson's test and
install commands will be used instead of Ninja's when Meson's
configurePhase is used.  This restriction is to avoid starting to run
Meson directly when dealing with custom build systems that wrap around
Meson, like QEMU's.  We don't use meson's compile command, as it just
runs ninja, and that's handled fine by the existing Ninja setup hook.

Naturally the Meson commands don't support entirely the same set of
options that the Ninja ones did, but I checked through Nixpkgs to find
any packages using Meson that used any options that wouldn't be picked
up by this new system.  I only found one, and it was just setting
checkTarget = "test", which is the default value for Ninja and has no
Meson equivalent (because we directly tell Meson to run the tests
rather than going through a generic job system like Ninja).

Link: NixOS#113829
Co-authored-by: Jan Tojnar <[email protected]>
@alyssais
Copy link
Member Author

alyssais commented Oct 7, 2023

@ofborg eval

@alyssais
Copy link
Member Author

alyssais commented Oct 7, 2023

OfBorg failure is just it failing a test in aws-sdk-cpp.

Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks.

@alyssais alyssais merged commit 10f35ff into NixOS:staging Oct 9, 2023
@alyssais alyssais deleted the meson-hook branch October 9, 2023 10:21
xokdvium added a commit to xokdvium/nixpkgs that referenced this pull request Feb 4, 2025
Motivation for this hook is simple: there's no single documented
way to do trivial things with ctest:

1. Pass additional flags to ctest invocation.
2. Selectively disable tests in a mechanism similar to python's
   `disabledTests` or rust's composable skips in `checkFlags`.
3. Disable parallel checking.

Current state of things has lead to several different solutions:

1. Completely overriding `checkPhase` [1] and invoking ctest manually
   with the necessary flags. This is most often coupled with `-E` for
   disabling test or setting parallel level.
2. Wrangling with weird double string/regex escaping and trying to stuff
   additional parameters and/or exclusion regex via `CMAKE_CTEST_ARGUMENTS`.
   This approach is especially painful when test names have spaces. This is
   the reason I originally decided to implement this hook after wrangling with
   failing darwin tests here [2].
3. Stuffing additional arguments into `checkFlagsArray` with the
   `ARGS` makefile parameter [3].

I don't see any reason to keep the status-quo. Doing something along these
lines has been suggested [4] for both `ctest` and `meson`. Meson setup-hook
has switched from `ninja` to `meson` in [5] with little friction. Doing
the same for cmake in a single sweep would prove problematic due to the
aforementioned zoo of workarounds and hacks for `ctest`. Doing it via
a separate hook would allow us to refactor things piecemeal and without
going through staging. The benefit of the hook is immediately clear and it
would allow to drive the refactor tractor at a comfortable pace.

[1]: pd/pdal/package.nix:117, cc/ccache/package.nix:108, gl/glog/package.nix:79
[2]: NixOS#375955
[3]: op/open62541/package.nix:114
[4]: NixOS#113829
[5]: NixOS#213845
xokdvium added a commit to xokdvium/nixpkgs that referenced this pull request Feb 6, 2025
Motivation for this hook is simple: there's no single documented
way to do trivial things with ctest:

1. Pass additional flags to ctest invocation.
2. Selectively disable tests in a mechanism similar to python's
   `disabledTests` or rust's composable skips in `checkFlags`.
3. Disable parallel checking.

Current state of things has lead to several different solutions:

1. Completely overriding `checkPhase` [1] and invoking ctest manually
   with the necessary flags. This is most often coupled with `-E` for
   disabling test or setting parallel level.
2. Wrangling with weird double string/regex escaping and trying to stuff
   additional parameters and/or exclusion regex via `CMAKE_CTEST_ARGUMENTS`.
   This approach is especially painful when test names have spaces. This is
   the reason I originally decided to implement this hook after wrangling with
   failing darwin tests here [2].
3. Stuffing additional arguments into `checkFlagsArray` with the
   `ARGS` makefile parameter [3].

I don't see any reason to keep the status-quo. Doing something along these
lines has been suggested [4] for both `ctest` and `meson`. Meson setup-hook
has switched from `ninja` to `meson` in [5] with little friction. Doing
the same for cmake in a single sweep would prove problematic due to the
aforementioned zoo of workarounds and hacks for `ctest`. Doing it via
a separate hook would allow us to refactor things piecemeal and without
going through staging. The benefit of the hook is immediately clear and it
would allow to drive the refactor tractor at a comfortable pace.

[1]: pd/pdal/package.nix:117, cc/ccache/package.nix:108, gl/glog/package.nix:79
[2]: NixOS#375955
[3]: op/open62541/package.nix:114
[4]: NixOS#113829
[5]: NixOS#213845
xokdvium added a commit to xokdvium/nixpkgs that referenced this pull request Feb 14, 2025
Motivation for this hook is simple: there's no single documented
way to do trivial things with ctest:

1. Pass additional flags to ctest invocation.
2. Selectively disable tests in a mechanism similar to python's
   `disabledTests` or rust's composable skips in `checkFlags`.
3. Disable parallel checking.

Current state of things has lead to several different solutions:

1. Completely overriding `checkPhase` [1] and invoking ctest manually
   with the necessary flags. This is most often coupled with `-E` for
   disabling test or setting parallel level.
2. Wrangling with weird double string/regex escaping and trying to stuff
   additional parameters and/or exclusion regex via `CMAKE_CTEST_ARGUMENTS`.
   This approach is especially painful when test names have spaces. This is
   the reason I originally decided to implement this hook after wrangling with
   failing darwin tests here [2].
3. Stuffing additional arguments into `checkFlagsArray` with the
   `ARGS` makefile parameter [3].

I don't see any reason to keep the status-quo. Doing something along these
lines has been suggested [4] for both `ctest` and `meson`. Meson setup-hook
has switched from `ninja` to `meson` in [5] with little friction. Doing
the same for cmake in a single sweep would prove problematic due to the
aforementioned zoo of workarounds and hacks for `ctest`. Doing it via
a separate hook would allow us to refactor things piecemeal and without
going through staging. The benefit of the hook is immediately clear and it
would allow to drive the refactor tractor at a comfortable pace.

[1]: pd/pdal/package.nix:117, cc/ccache/package.nix:108, gl/glog/package.nix:79
[2]: NixOS#375955
[3]: op/open62541/package.nix:114
[4]: NixOS#113829
[5]: NixOS#213845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants