forked from yihuang/python-iavl
-
Notifications
You must be signed in to change notification settings - Fork 4
/
rocksdb.nix
140 lines (127 loc) · 4.62 KB
/
rocksdb.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
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
{
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
cmake,
ninja,
bzip2,
lz4,
snappy,
zlib,
zstd,
windows,
# don't enable jemalloc, error on linux: https://github.com/NixOS/nixpkgs/issues/315628
enableJemalloc ? false,
jemalloc,
enableShared ? !stdenv.hostPlatform.isStatic,
sse42Support ? stdenv.hostPlatform.sse4_2Support,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "rocksdb";
version = "9.7.4";
src = fetchFromGitHub {
owner = "facebook";
repo = finalAttrs.pname;
rev = "v${finalAttrs.version}";
hash = "sha256-u5uuShM2SxHc9/zL4UU56IhCcR/ZQbzde0LgOYS44bM=";
};
nativeBuildInputs = [
cmake
ninja
];
propagatedBuildInputs = [
bzip2
lz4
snappy
zlib
zstd
];
buildInputs =
lib.optional enableJemalloc jemalloc
++ lib.optional stdenv.hostPlatform.isMinGW windows.mingw_w64_pthreads;
outputs = [
"out"
"tools"
];
env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isClang [ "-faligned-allocation" ]);
cmakeFlags = [
"-DPORTABLE=1"
"-DWITH_JEMALLOC=${if enableJemalloc then "1" else "0"}"
"-DWITH_JNI=0"
"-DWITH_BENCHMARK_TOOLS=0"
"-DWITH_TESTS=1"
"-DWITH_TOOLS=0"
"-DWITH_CORE_TOOLS=1"
"-DWITH_BZ2=1"
"-DWITH_LZ4=1"
"-DWITH_SNAPPY=1"
"-DWITH_ZLIB=1"
"-DWITH_ZSTD=1"
"-DWITH_GFLAGS=0"
"-DUSE_RTTI=1"
"-DROCKSDB_INSTALL_ON_WINDOWS=YES" # harmless elsewhere
(lib.optional sse42Support "-DFORCE_SSE42=1")
"-DFAIL_ON_WARNINGS=NO"
] ++ lib.optional (!enableShared) "-DROCKSDB_BUILD_SHARED=0";
# otherwise "cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]"
hardeningDisable = lib.optional stdenv.hostPlatform.isWindows "format";
postPatch =
lib.optionalString (lib.versionOlder finalAttrs.version "9") ''
# Fix gcc-13 build failures due to missing <cstdint> and
# <system_error> includes, fixed upstream since 9.x
sed -e '1i #include <cstdint>' -i options/offpeak_time_info.h
''
+ lib.optionalString (lib.versionOlder finalAttrs.version "8") ''
# Fix gcc-13 build failures due to missing <cstdint> and
# <system_error> includes, fixed upstream since 8.x
sed -e '1i #include <cstdint>' -i db/compaction/compaction_iteration_stats.h
sed -e '1i #include <cstdint>' -i table/block_based/data_block_hash_index.h
sed -e '1i #include <cstdint>' -i util/string_util.h
sed -e '1i #include <cstdint>' -i include/rocksdb/utilities/checkpoint.h
''
+ lib.optionalString (lib.versionOlder finalAttrs.version "7") ''
# Fix gcc-13 build failures due to missing <cstdint> and
# <system_error> includes, fixed upstream since 7.x
sed -e '1i #include <system_error>' -i third-party/folly/folly/synchronization/detail/ProxyLockable-inl.h
''
+ ''
# fixed in https://github.com/facebook/rocksdb/pull/12309
sed -e 's/ZSTD_INCLUDE_DIRS/zstd_INCLUDE_DIRS/' -i cmake/modules/Findzstd.cmake
sed -e 's/ZSTD_INCLUDE_DIRS/zstd_INCLUDE_DIRS/' -i CMakeLists.txt
'';
preInstall =
''
mkdir -p $tools/bin
cp tools/{ldb,sst_dump}${stdenv.hostPlatform.extensions.executable} $tools/bin/
''
+ lib.optionalString stdenv.isDarwin ''
ls -1 $tools/bin/* | xargs -I{} ${stdenv.cc.bintools.targetPrefix}install_name_tool -change "@rpath/librocksdb.${lib.versions.major finalAttrs.version}.dylib" $out/lib/librocksdb.dylib {}
''
+ lib.optionalString (stdenv.isLinux && enableShared) ''
ls -1 $tools/bin/* | xargs -I{} patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib {}
'';
# Old version doesn't ship the .pc file, new version puts wrong paths in there.
postFixup =
''
if [ -f "$out"/lib/pkgconfig/rocksdb.pc ]; then
substituteInPlace "$out"/lib/pkgconfig/rocksdb.pc \
--replace '="''${prefix}//' '="/'
fi
''
+ lib.optionalString stdenv.isDarwin ''
${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/libsnappy.1.dylib" "${snappy}/lib/libsnappy.1.dylib" $out/lib/librocksdb.dylib
${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/librocksdb.${lib.versions.major finalAttrs.version}.dylib" "$out/lib/librocksdb.${lib.versions.major finalAttrs.version}.dylib" $out/lib/librocksdb.dylib
'';
meta = with lib; {
homepage = "https://rocksdb.org";
description = "A library that provides an embeddable, persistent key-value store for fast storage";
changelog = "https://github.com/facebook/rocksdb/raw/v${finalAttrs.version}/HISTORY.md";
license = licenses.asl20;
platforms = platforms.all;
maintainers = with maintainers; [
adev
magenbluten
];
};
})