-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
95 lines (88 loc) · 3 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
description = "Flake for my project using gcc14 and C++23";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
match_version = "0.0.1";
pkgs = import nixpkgs { inherit system; };
google-benchmark = pkgs.callPackage ./google-benchmark.nix { };
# Read all files in the examples folder and filter for .cpp files.
exampleFiles = builtins.filter (f: builtins.match ".*\\.cpp$" f != null) (
builtins.attrNames (builtins.readDir ./examples)
);
# Create a derivation for each example file.
examplesDerivations = builtins.listToAttrs (
map (
file:
let
# Strip the ".cpp" extension.
name = builtins.substring 0 (builtins.stringLength file - 4) file;
in
{
name = name;
value = pkgs.stdenv.mkDerivation {
pname = name;
version = match_version;
# Make the entire repository available so that both examples/ and include/ are visible.
src = ./.;
buildInputs = [ pkgs.gcc14 ];
configurePhase = "";
buildPhase = ''
g++ -std=c++23 -O3 examples/${file} -Iinclude -o ${name}
'';
installPhase = ''
mkdir -p $out/bin
cp ${name} $out/bin/
'';
};
}
) exampleFiles
);
in
{
# Development shell available on all systems.
devShells.default = pkgs.mkShell {
buildInputs = [ pkgs.gcc14 ];
};
# Define packages: your tests plus all the examples.
packages = pkgs.lib.recursiveUpdate {
tests = pkgs.stdenv.mkDerivation {
pname = "cppmatch_tests";
version = match_version;
src = ./.;
buildInputs = [ pkgs.gcc14 ];
configurePhase = "";
buildPhase = "g++ -std=c++23 test/main.cpp -g -O3 -Iinclude -o cppmatch_tests";
installPhase = ''
mkdir -p $out/bin
cp cppmatch_tests $out/bin/
'';
};
benchmark = pkgs.llvmPackages_20.stdenv.mkDerivation {
pname = "cppmatch_benchmark";
version = match_version;
src = ./.;
buildInputs = [ google-benchmark];
configurePhase = "";
buildPhase = ''
clang++ -std=c++23 -g -O3 benchmark/main.cpp -Iinclude -I${google-benchmark}/include -L${google-benchmark}/lib -lbenchmark -pthread -o cppmatch_benchmark
'';
installPhase = ''
mkdir -p $out/bin
cp cppmatch_benchmark $out/bin/
'';
};
} examplesDerivations;
}
);
}