Skip to content

Commit

Permalink
Make the default stdenv phases do the right thing
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Nov 12, 2024
1 parent 14edb78 commit e6aae64
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
24 changes: 12 additions & 12 deletions doc/manual/source/development/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ To build Nix itself in this shell:

```console
[nix-shell]$ mesonFlags+=" --prefix=$(pwd)/outputs/out"
[nix-shell]$ dontAddPrefix=1 mesonConfigurePhase
[nix-shell]$ ninjaBuildPhase
[nix-shell]$ dontAddPrefix=1 configurePhase
[nix-shell]$ buildPhase
```

To test it:

```console
[nix-shell]$ mesonCheckPhase
[nix-shell]$ checkPhase
```

To install it in `$(pwd)/outputs`:

```console
[nix-shell]$ ninjaInstallPhase
[nix-shell]$ installPhase
[nix-shell]$ ./outputs/out/bin/nix --version
nix (Nix) 2.12
```
Expand Down Expand Up @@ -90,20 +90,20 @@ $ nix develop .#native-clangStdenvPackages
To build Nix itself in this shell:

```console
[nix-shell]$ mesonConfigurePhase
[nix-shell]$ ninjaBuildPhase
[nix-shell]$ configurePhase
[nix-shell]$ buildPhase
```

To test it:

```console
[nix-shell]$ mesonCheckPhase
[nix-shell]$ checkPhase
```

To install it in `$(pwd)/outputs`:

```console
[nix-shell]$ ninjaInstallPhase
[nix-shell]$ installPhase
[nix-shell]$ nix --version
nix (Nix) 2.12
```
Expand Down Expand Up @@ -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.
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.
The good news is that Meson/Ninja seem to cope well with relocating the build directory after it is created.

Expand All @@ -176,21 +176,21 @@ Here's how to do that
1. Configure as usual

```bash
mesonConfigurePhase
configurePhase
```

2. Rename the build directory

```bash
cd .. # since `mesonConfigurePhase` cd'd inside
cd .. # since `configurePhase` cd'd inside
mv build build-linux # or whatever name we want
cd build-linux
```

3. Build as usual

```bash
ninjaBuildPhase
buildPhase
```

> **N.B.**
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/source/development/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ $ xdg-open ./result/share/doc/nix/internal-api/html/index.html
or inside `nix-shell` or `nix develop`:

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

```
$ mesonConfigurePhase
$ configurePhase
$ ninja src/external-api-docs/html
$ xdg-open src/external-api-docs/html/index.html
```
2 changes: 1 addition & 1 deletion doc/manual/source/development/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```shell-session
$ mesonCheckPhase
$ checkPhase
```

### Grouping tests
Expand Down
29 changes: 29 additions & 0 deletions packaging/dev-shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ in {
# Make bash completion work.
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.
Expand Down

0 comments on commit e6aae64

Please sign in to comment.