-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python: Integrate incremental and CI build
Makes the python bindings build, both incrementally and for CI. Documentation is not yet included
- Loading branch information
Showing
10 changed files
with
151 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.cache | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# This Makefile is only used for development of the Python bindings, it is not | ||
# used in the Nix build. | ||
# The reason this exists is to make it easier to develop the Python bindings in | ||
# tandem with the main Nix. | ||
# The default `make` (defaults to `make build`) calls the main Nix projects | ||
# `make install` before calling the Python bindings' `meson compile`, therefore | ||
# ensuring that the needed Nix dynamic libraries are up-to-date | ||
|
||
builddir=build | ||
|
||
.PHONY: build | ||
build: nix-install setup-done | ||
meson compile -C $(builddir) | ||
|
||
.PHONY: test | ||
test: nix-install setup-done | ||
meson test -C $(builddir) -v | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(builddir) | ||
|
||
# We include the main Nix projects Makefile.config file to know the $(libdir) | ||
# variable, which is where Nix is installed in, which we can then use to setup | ||
# the meson build | ||
include ../Makefile.config | ||
|
||
# We need the file to exist though | ||
../Makefile.config: | ||
@# Throw a good error message in case ./configure hasn't been run yet | ||
@[[ -e ../config.status ]] || ( echo "The main Nix project needs to be configured first, see https://nixos.org/manual/nix/stable/contributing/hacking.html" && exit 1 ) | ||
@# If ./configure is done, we can create the file ourselves | ||
$(MAKE) -C .. Makefile.config | ||
|
||
.PHONY: setup | ||
setup: nix-install | ||
@# Make meson be able to find the locally-installed Nix | ||
PKG_CONFIG_PATH=$(libdir)/pkgconfig:$$PKG_CONFIG_PATH meson setup $(builddir) | ||
|
||
.PHONY: setup-done | ||
setup-done: | ||
@# A better error message in case the build directory doesn't exist yet | ||
@[[ -e $(builddir) ]] || ( echo "Run 'make setup' once to configure the project build directory" && exit 1 ) | ||
|
||
.PHONY: nix-install | ||
nix-install: | ||
@# The python bindings don't technically need an _entire_ Nix installation, | ||
@# but it seems non-trivial to pick out only exactly the files it actually needs | ||
$(MAKE) -C .. install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ self, system, lib, python, ninja, meson, nix, mkShell }: | ||
python.pkgs.buildPythonPackage { | ||
name = "nix"; | ||
format = "other"; | ||
|
||
src = self; | ||
|
||
strictDeps = true; | ||
|
||
nativeBuildInputs = lib.optionals (nix != null) nix.nativeBuildInputs ++ [ | ||
ninja | ||
(meson.override { python3 = python; }) | ||
nix | ||
]; | ||
|
||
buildInputs = lib.optionals (nix != null) nix.buildInputs ++ [ | ||
nix | ||
]; | ||
|
||
# We need to be able to generate tests/common.sh, which requires running | ||
# `make`, which requires having run `autoreconf` and `./configure`. | ||
# So we propagate `autoreconfHook` from nix.nativeBuildInputs for that to | ||
# work, but after that we also need to cd into the python directory and run the | ||
# meson configure phase for the python bindings. | ||
# Can't use `postConfigure` for this because that would create a loop since | ||
# `mesonConfigurePhase` calls `postConfigure` itself. | ||
# A small problem with this is that `{pre,post}Configure` get run twice | ||
dontUseMesonConfigure = true; | ||
preBuild = '' | ||
cd python | ||
mesonConfigurePhase | ||
''; | ||
|
||
mesonBuildType = "release"; | ||
|
||
doInstallCheck = true; | ||
installCheckPhase = "meson test -v"; | ||
|
||
passthru.shell = mkShell { | ||
inputsFrom = [ | ||
self.devShells.${system}.stdenv | ||
(nix.python-bindings.override { nix = null; }) | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
#include <Python.h> | ||
|
||
#include <nix/config.h> | ||
#include <config.h> | ||
|
||
#include <eval.hh> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
cd "$SCRIPT_DIR"/../tests | ||
|
||
source init.sh | ||
|
||
python "$SCRIPT_DIR"/tests.py |