1{ lib, stdenv, fetchFromGitHub, cmake
2, fetchpatch
3, static ? stdenv.hostPlatform.isStatic
4}:
5
6stdenv.mkDerivation rec {
7 pname = "snappy";
8 version = "1.1.10";
9
10 src = fetchFromGitHub {
11 owner = "google";
12 repo = "snappy";
13 rev = version;
14 hash = "sha256-wYZkKVDXKCugycx/ZYhjV0BjM/NrEM0R6A4WFhs/WPU=";
15 };
16
17 patches = [
18 # Re-enable RTTI, without which other applications can't subclass
19 # snappy::Source (this breaks Ceph, as one example)
20 # https://tracker.ceph.com/issues/53060
21 # https://build.opensuse.org/package/show/openSUSE:Factory/snappy
22 (fetchpatch {
23 url = "https://build.opensuse.org/public/source/openSUSE:Factory/snappy/reenable-rtti.patch?rev=a759aa6fba405cd40025e3f0ab89941d";
24 sha256 = "sha256-RMuM5yd6zP1eekN/+vfS54EyY4cFbGDVor1E1vj3134=";
25 })
26 # Fix -Wsign-compare warning on clang.
27 (fetchpatch {
28 url = "https://github.com/google/snappy/commit/27f34a580be4a3becf5f8c0cba13433f53c21337.patch";
29 sha256 = "sha256-eq6ueeMAkd2bYmPJcKAZZzd5QlXyeWOrsxFIwR8KOpQ=";
30 })
31 ];
32
33 outputs = [ "out" "dev" ];
34
35 nativeBuildInputs = [ cmake ];
36
37 cmakeFlags = [
38 "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}"
39 "-DSNAPPY_BUILD_TESTS=OFF"
40 "-DSNAPPY_BUILD_BENCHMARKS=OFF"
41 ];
42
43 postInstall = ''
44 substituteInPlace "$out"/lib/cmake/Snappy/SnappyTargets.cmake \
45 --replace 'INTERFACE_INCLUDE_DIRECTORIES "''${_IMPORT_PREFIX}/include"' 'INTERFACE_INCLUDE_DIRECTORIES "'$dev'"'
46
47 mkdir -p $dev/lib/pkgconfig
48 cat <<EOF > $dev/lib/pkgconfig/snappy.pc
49 Name: snappy
50 Description: Fast compressor/decompressor library.
51 Version: ${version}
52 Libs: -L$out/lib -lsnappy
53 Cflags: -I$dev/include
54 EOF
55 '';
56
57 #checkTarget = "test";
58
59 # requires gbenchmark and gtest but it also installs them out $dev
60 doCheck = false;
61
62 meta = with lib; {
63 homepage = "https://google.github.io/snappy/";
64 license = licenses.bsd3;
65 description = "Compression/decompression library for very high speeds";
66 platforms = platforms.all;
67 };
68}