lol
1# This builder is for FoundationDB CMake build system.
2
3{ lib, fetchFromGitHub
4, cmake, ninja, boost, python3, openjdk, mono, libressl
5
6, gccStdenv, llvmPackages
7, useClang ? false
8, ...
9}:
10
11let
12 stdenv = if useClang then llvmPackages.libcxxStdenv else gccStdenv;
13
14 tests = with builtins;
15 builtins.replaceStrings [ "\n" ] [ " " ] (lib.fileContents ./test-list.txt);
16
17 makeFdb =
18 { version
19 , branch # unused
20 , sha256
21 , rev ? "refs/tags/${version}"
22 , officialRelease ? true
23 , patches ? []
24 }: stdenv.mkDerivation {
25 pname = "foundationdb";
26 inherit version;
27
28 src = fetchFromGitHub {
29 owner = "apple";
30 repo = "foundationdb";
31 inherit rev sha256;
32 };
33
34 buildInputs = [ libressl boost ];
35 nativeBuildInputs = [ cmake ninja python3 openjdk mono ]
36 ++ lib.optional useClang [ llvmPackages.lld ];
37
38 separateDebugInfo = true;
39 dontFixCmake = true;
40
41 cmakeFlags =
42 [ "-DCMAKE_BUILD_TYPE=Release"
43 (lib.optionalString officialRelease "-DFDB_RELEASE=TRUE")
44
45 # FIXME: why can't libressl be found automatically?
46 "-DLIBRESSL_USE_STATIC_LIBS=FALSE"
47 "-DLIBRESSL_INCLUDE_DIR=${libressl.dev}"
48 "-DLIBRESSL_CRYPTO_LIBRARY=${libressl.out}/lib/libcrypto.so"
49 "-DLIBRESSL_SSL_LIBRARY=${libressl.out}/lib/libssl.so"
50 "-DLIBRESSL_TLS_LIBRARY=${libressl.out}/lib/libtls.so"
51
52 # LTO brings up overall build time, but results in much smaller
53 # binaries for all users and the cache.
54 (lib.optionalString (!useClang) "-DUSE_LTO=ON")
55
56 # Gold helps alleviate the link time, especially when LTO is
57 # enabled. But even then, it still takes a majority of the time.
58 # Same with LLD when Clang is available.
59 (lib.optionalString useClang "-DUSE_LD=LLD")
60 (lib.optionalString (!useClang) "-DUSE_LD=GOLD")
61 ];
62
63 inherit patches;
64
65 # fix up the use of the very weird and custom 'fdb_install' command by just
66 # replacing it with cmake's ordinary version.
67 postPatch = ''
68 for x in bindings/c/CMakeLists.txt fdbserver/CMakeLists.txt fdbmonitor/CMakeLists.txt fdbbackup/CMakeLists.txt fdbcli/CMakeLists.txt; do
69 substituteInPlace $x --replace 'fdb_install' 'install'
70 done
71 '';
72
73 # the install phase for cmake is pretty wonky right now since it's not designed to
74 # coherently install packages as most linux distros expect -- it's designed to build
75 # packaged artifacts that are shipped in RPMs, etc. we need to add some extra code to
76 # cmake upstream to fix this, and if we do, i think most of this can go away.
77 postInstall = ''
78 mv $out/sbin/fdbserver $out/bin/fdbserver
79 rm -rf \
80 $out/lib/systemd $out/Library $out/usr $out/sbin \
81 $out/var $out/log $out/etc
82
83 mv $out/fdbmonitor/fdbmonitor $out/bin/fdbmonitor && rm -rf $out/fdbmonitor
84
85 rm -rf $out/lib/foundationdb/
86 mkdir $out/libexec && ln -sfv $out/bin/fdbbackup $out/libexec/backup_agent
87
88 mkdir $out/include/foundationdb && \
89 mv $out/include/*.h $out/include/*.options $out/include/foundationdb
90
91 # move results into multi outputs
92 mkdir -p $dev $lib
93 mv $out/include $dev/include
94 mv $out/lib $lib/lib
95
96 # python bindings
97 # NB: use the original setup.py.in, so we can substitute VERSION correctly
98 cp ../LICENSE ./bindings/python
99 substitute ../bindings/python/setup.py.in ./bindings/python/setup.py \
100 --replace 'VERSION' "${version}"
101 rm -f ./bindings/python/setup.py.* ./bindings/python/CMakeLists.txt
102 rm -f ./bindings/python/fdb/*.pth # remove useless files
103 rm -f ./bindings/python/*.rst ./bindings/python/*.mk
104
105 cp -R ./bindings/python/ tmp-pythonsrc/
106 tar -zcf $pythonsrc --transform s/tmp-pythonsrc/python-foundationdb/ ./tmp-pythonsrc/
107
108 # java bindings
109 mkdir -p $lib/share/java
110 mv lib/fdb-java-*.jar $lib/share/java/fdb-java.jar
111
112 # include the tests
113 mkdir -p $out/share/test
114 (cd ../tests && for x in ${tests}; do
115 cp --parents $x $out/share/test
116 done)
117 '';
118
119 outputs = [ "out" "dev" "lib" "pythonsrc" ];
120
121 meta = with lib; {
122 description = "Open source, distributed, transactional key-value store";
123 homepage = "https://www.foundationdb.org";
124 license = licenses.asl20;
125 platforms = [ "x86_64-linux" ];
126 maintainers = with maintainers; [ thoughtpolice ];
127 };
128 };
129in makeFdb