blob: a9ba21a78f81987820ea7442eb9b75057b2e9c2f (
plain) (
blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
{
description = "RelationalNT CMake build";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
picosha2 = {
url = "github:okdshin/PicoSHA2";
flake = false;
};
};
outputs = { self, nixpkgs, picosha2 }:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs systems;
# Shared per-system derivations used by both the package and the dev shell.
mkDeps = system:
let
pkgs = import nixpkgs { inherit system; };
# Maps the unofficial::sqlite3::sqlite3 CMake
# target to the system SQLite3 package. Required because CMakeLists.txt
# calls target_link_libraries(... unofficial::sqlite3::sqlite3).
unofficialSqlite3Config = pkgs.writeTextDir
"share/unofficial-sqlite3/unofficial-sqlite3-config.cmake"
''
include(CMakeFindDependencyMacro)
find_dependency(SQLite3 REQUIRED)
if(NOT TARGET unofficial::sqlite3::sqlite3)
add_library(unofficial::sqlite3::sqlite3 INTERFACE IMPORTED)
target_link_libraries(unofficial::sqlite3::sqlite3 INTERFACE SQLite::SQLite3)
endif()
'';
# PicoSHA2 is a single-header library; extract just the header.
picosha2Headers = pkgs.runCommand "picosha2-headers" { } ''
mkdir -p $out/include
install -m644 ${picosha2}/picosha2.h $out/include/picosha2.h
'';
stdenv = if pkgs.stdenv.isDarwin then pkgs.stdenv else pkgs.gccStdenv;
cc = if pkgs.stdenv.isDarwin then pkgs.stdenv.cc else pkgs.gcc;
in { inherit pkgs unofficialSqlite3Config picosha2Headers stdenv cc; };
in
{
packages = forAllSystems (system:
let
inherit (mkDeps system) pkgs unofficialSqlite3Config picosha2Headers stdenv;
in
{
default = stdenv.mkDerivation {
pname = "rnt";
version = "0.1.0";
src = self;
nativeBuildInputs = [
pkgs.cmake
pkgs.ninja
];
buildInputs = [
pkgs.catch2_3
picosha2Headers
pkgs.sqlite
unofficialSqlite3Config
];
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Release"
];
doCheck = true;
checkPhase = ''
runHook preCheck
ctest --output-on-failure
runHook postCheck
'';
installPhase = ''
runHook preInstall
mkdir -p "$out/bin" "$out/lib" "$out/include" "$out/share/licenses/rnt"
install -m755 RelationalNT "$out/bin/RelationalNT"
install -m755 RNT_tests "$out/bin/RNT_tests"
for lib in libRNT.so libRNT.dylib; do
if [ -f "$lib" ]; then
install -m755 "$lib" "$out/lib/$lib"
fi
done
install -m644 ../include/RNT_C_API.h "$out/include/RNT_C_API.h"
install -m644 "${self}/LICENSE" "$out/share/licenses/rnt/LICENSE"
runHook postInstall
'';
meta = {
description = "RNT database kernel inspired by the Windows NT object manager";
license = pkgs.lib.licenses.agpl3Only;
mainProgram = "RelationalNT";
maintainers = [
{ name = "Marcos Magueta"; }
];
};
};
});
devShells = forAllSystems (system:
let
inherit (mkDeps system) pkgs unofficialSqlite3Config picosha2Headers stdenv cc;
in
{
default = pkgs.mkShell.override { inherit stdenv; } {
packages = [
pkgs.catch2_3
pkgs.clang-tools
pkgs.cmake
pkgs.doxygen
pkgs.graphviz
pkgs.ninja
picosha2Headers
pkgs.sqlite
unofficialSqlite3Config
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.gcc
pkgs.gdb
];
CC = "${cc}/bin/cc";
CXX = "${cc}/bin/c++";
CMAKE_PREFIX_PATH = pkgs.lib.makeSearchPathOutput "dev" "" [
picosha2Headers
pkgs.sqlite
unofficialSqlite3Config
];
CMAKE_INCLUDE_PATH = pkgs.lib.makeSearchPathOutput "dev" "include" [
picosha2Headers
pkgs.sqlite
];
CMAKE_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.sqlite
];
CPATH = pkgs.lib.makeSearchPathOutput "dev" "include" [
picosha2Headers
pkgs.sqlite
];
C_INCLUDE_PATH = pkgs.lib.makeSearchPathOutput "dev" "include" [
pkgs.sqlite
];
CPLUS_INCLUDE_PATH = pkgs.lib.makeSearchPathOutput "dev" "include" [
picosha2Headers
pkgs.sqlite
];
LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.sqlite
];
DYLD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.sqlite
];
PKG_CONFIG_PATH = pkgs.lib.makeSearchPathOutput "dev" "lib/pkgconfig" [
pkgs.sqlite
];
shellHook = ''
export NIX_CFLAGS_COMPILE="-I${picosha2Headers}/include -I${pkgs.sqlite.dev}/include $NIX_CFLAGS_COMPILE"
export NIX_LDFLAGS="-L${pkgs.sqlite.out}/lib $NIX_LDFLAGS"
'';
};
});
apps = forAllSystems (system: {
default = {
type = "app";
program = "${self.packages.${system}.default}/bin/RelationalNT";
};
});
};
}
|