Skip to content

Commit

Permalink
meson.setupHook: prefer meson commands over ninja
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alyssais committed Feb 11, 2023
1 parent 9b97ad7 commit 5a52cc4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
22 changes: 19 additions & 3 deletions doc/hooks/meson.section.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@

### Meson {#meson}

Overrides the configure phase to run meson to generate Ninja files. To run these files, you should accompany Meson with ninja. By default, `enableParallelBuilding` is enabled as Meson supports parallel building almost everywhere.
Overrides the configure, check, and install phases to run `meson setup`, `meson test`, and `meson install`. For a meson-compatible build phase, you should accompany Meson with ninja. By default, `enableParallelBuilding` is enabled as Meson supports parallel building almost everywhere.

#### Variables controlling Meson {#variables-controlling-meson}

##### `mesonFlags` {#mesonflags}

Controls the flags passed to meson.
Controls the flags passed to `meson setup`.

##### `mesonCheckFlags` {#mesoncheckflags}

Controls the flags passed to `meson test`.

##### `mesonInstallFlags` {#mesoninstallflags}

Controls the flags passed to `meson install`.

##### `mesonBuildType` {#mesonbuildtype}

Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`.
Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to `meson setup`. We default to `plain`.

##### `mesonAutoFeatures` {#mesonautofeatures}

Expand All @@ -24,3 +32,11 @@ What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#c
##### `dontUseMesonConfigure` {#dontusemesonconfigure}

Disables using Meson’s `configurePhase`.

##### `dontUseMesonCheck` {#dontusemesoncheck}

Disables using Meson’s `checkPhase`.

##### `dontUseMesonInstall` {#dontusemesoninstall}

Disables using Meson’s `installPhase`.
2 changes: 2 additions & 0 deletions doc/hooks/ninja.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
### ninja {#ninja}

Overrides the build, install, and check phase to run ninja instead of make. You can disable this behavior with the `dontUseNinjaBuild`, `dontUseNinjaInstall`, and `dontUseNinjaCheck`, respectively. Parallel building is enabled by default in Ninja.

Note that if the [Meson setup hook](#meson) is also active, Ninja's install and check phases will be disabled in favor of Meson's.
30 changes: 30 additions & 0 deletions pkgs/development/tools/build-managers/meson/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,39 @@ mesonConfigurePhase() {
echo "meson: enabled parallel building"
fi

if [[ ${checkPhase-ninjaCheckPhase} = ninjaCheckPhase && -z $dontUseMesonCheck ]]; then
checkPhase=mesonCheckPhase
fi
if [[ ${installPhase-ninjaInstallPhase} = ninjaInstallPhase && -z $dontUseMesonInstall ]]; then
installPhase=mesonInstallPhase
fi

runHook postConfigure
}

mesonCheckPhase() {
runHook preCheck

local flagsArray=($mesonCheckFlags "${mesonCheckFlagsArray[@]}")

echoCmd 'check flags' "${flagsArray[@]}"
meson test --no-rebuild "${flagsArray[@]}"

runHook postCheck
}

mesonInstallPhase() {
runHook preInstall

# shellcheck disable=SC2086
local flagsArray=($mesonInstallFlags "${mesonInstallFlagsArray[@]}")

echoCmd 'install flags' "${flagsArray[@]}"
meson install --no-rebuild "${flagsArray[@]}"

runHook postInstall
}

if [ -z "${dontUseMesonConfigure-}" -a -z "${configurePhase-}" ]; then
setOutputFlags=
configurePhase=mesonConfigurePhase
Expand Down

0 comments on commit 5a52cc4

Please sign in to comment.