Merge pull request #11870 from DeterminateSystems/default-phases

Make the default stdenv phases do the right thing
This commit is contained in:
John Ericson 2024-11-13 16:04:22 -05:00 committed by GitHub
commit be2520551e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 15 deletions

View File

@ -35,20 +35,20 @@ To build Nix itself in this shell:
```console ```console
[nix-shell]$ mesonFlags+=" --prefix=$(pwd)/outputs/out" [nix-shell]$ mesonFlags+=" --prefix=$(pwd)/outputs/out"
[nix-shell]$ dontAddPrefix=1 mesonConfigurePhase [nix-shell]$ dontAddPrefix=1 configurePhase
[nix-shell]$ ninjaBuildPhase [nix-shell]$ buildPhase
``` ```
To test it: To test it:
```console ```console
[nix-shell]$ mesonCheckPhase [nix-shell]$ checkPhase
``` ```
To install it in `$(pwd)/outputs`: To install it in `$(pwd)/outputs`:
```console ```console
[nix-shell]$ ninjaInstallPhase [nix-shell]$ installPhase
[nix-shell]$ ./outputs/out/bin/nix --version [nix-shell]$ ./outputs/out/bin/nix --version
nix (Nix) 2.12 nix (Nix) 2.12
``` ```
@ -90,20 +90,20 @@ $ nix develop .#native-clangStdenvPackages
To build Nix itself in this shell: To build Nix itself in this shell:
```console ```console
[nix-shell]$ mesonConfigurePhase [nix-shell]$ configurePhase
[nix-shell]$ ninjaBuildPhase [nix-shell]$ buildPhase
``` ```
To test it: To test it:
```console ```console
[nix-shell]$ mesonCheckPhase [nix-shell]$ checkPhase
``` ```
To install it in `$(pwd)/outputs`: To install it in `$(pwd)/outputs`:
```console ```console
[nix-shell]$ ninjaInstallPhase [nix-shell]$ installPhase
[nix-shell]$ nix --version [nix-shell]$ nix --version
nix (Nix) 2.12 nix (Nix) 2.12
``` ```
@ -167,7 +167,7 @@ It is useful to perform multiple cross and native builds on the same source tree
for example to ensure that better support for one platform doesn't break the build for another. for example to ensure that better support for one platform doesn't break the build for another.
Meson thankfully makes this very easy by confining all build products to the build directory --- one simple shares the source directory between multiple build directories, each of which contains the build for Nix to a different platform. Meson thankfully makes this very easy by confining all build products to the build directory --- one simple shares the source directory between multiple build directories, each of which contains the build for Nix to a different platform.
Nixpkgs's `mesonConfigurePhase` always chooses `build` in the current directory as the name and location of the build. Nixpkgs's `configurePhase` always chooses `build` in the current directory as the name and location of the build.
This makes having multiple build directories slightly more inconvenient. This makes having multiple build directories slightly more inconvenient.
The good news is that Meson/Ninja seem to cope well with relocating the build directory after it is created. The good news is that Meson/Ninja seem to cope well with relocating the build directory after it is created.
@ -176,13 +176,13 @@ Here's how to do that
1. Configure as usual 1. Configure as usual
```bash ```bash
mesonConfigurePhase configurePhase
``` ```
2. Rename the build directory 2. Rename the build directory
```bash ```bash
cd .. # since `mesonConfigurePhase` cd'd inside cd .. # since `configurePhase` cd'd inside
mv build build-linux # or whatever name we want mv build build-linux # or whatever name we want
cd build-linux cd build-linux
``` ```
@ -190,7 +190,7 @@ Here's how to do that
3. Build as usual 3. Build as usual
```bash ```bash
ninjaBuildPhase buildPhase
``` ```
> **N.B.** > **N.B.**

View File

@ -203,7 +203,7 @@ $ xdg-open ./result/share/doc/nix/internal-api/html/index.html
or inside `nix-shell` or `nix develop`: or inside `nix-shell` or `nix develop`:
```console ```console
$ mesonConfigurePhase $ configurePhase
$ ninja src/internal-api-docs/html $ ninja src/internal-api-docs/html
$ xdg-open src/internal-api-docs/html/index.html $ xdg-open src/internal-api-docs/html/index.html
``` ```
@ -224,7 +224,7 @@ $ xdg-open ./result/share/doc/nix/external-api/html/index.html
or inside `nix-shell` or `nix develop`: or inside `nix-shell` or `nix develop`:
``` ```
$ mesonConfigurePhase $ configurePhase
$ ninja src/external-api-docs/html $ ninja src/external-api-docs/html
$ xdg-open src/external-api-docs/html/index.html $ xdg-open src/external-api-docs/html/index.html
``` ```

View File

@ -137,7 +137,7 @@ Functional tests are run during `installCheck` in the `nix` package build, as we
The whole test suite (functional and unit tests) can be run with: The whole test suite (functional and unit tests) can be run with:
```shell-session ```shell-session
$ mesonCheckPhase $ checkPhase
``` ```
### Grouping tests ### Grouping tests

View File

@ -31,6 +31,35 @@ in {
# Make bash completion work. # Make bash completion work.
XDG_DATA_DIRS+=:$out/share XDG_DATA_DIRS+=:$out/share
# Make the default phases do the right thing.
# FIXME: this wouldn't be needed if the ninja package set buildPhase() instead of $buildPhase.
# FIXME: mesonConfigurePhase shouldn't cd to the build directory. It would be better to pass '-C <dir>' to ninja.
cdToBuildDir() {
if [[ ! -e build.ninja ]]; then
cd build
fi
}
configurePhase() {
mesonConfigurePhase
}
buildPhase() {
cdToBuildDir
ninjaBuildPhase
}
checkPhase() {
cdToBuildDir
mesonCheckPhase
}
installPhase() {
cdToBuildDir
ninjaInstallPhase
}
''; '';
# We use this shell with the local checkout, not unpackPhase. # We use this shell with the local checkout, not unpackPhase.