10 legacySupport ? false,
11 static ? stdenv.hostPlatform.isStatic, # generates static libraries *only*
12 enableStatic ? static,
13 # these need to be ran on the host, thus disable when cross-compiling
14 buildContrib ? stdenv.hostPlatform == stdenv.buildPlatform,
15 doCheck ? stdenv.hostPlatform == stdenv.buildPlatform,
28 stdenv.mkDerivation rec {
32 src = fetchFromGitHub {
36 hash = "sha256-qcd92hQqVBjMT3hyntjcgk29o9wGQsg5Hg7HE5C0UNc=";
39 nativeBuildInputs = [ cmake ] ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
40 buildInputs = lib.optional stdenv.hostPlatform.isUnix bash;
43 # This patches makes sure we do not attempt to use the MD5 implementation
44 # of the host platform when running the tests
45 ./playtests-darwin.patch
48 postPatch = lib.optionalString (!static) ''
49 substituteInPlace build/cmake/CMakeLists.txt \
50 --replace 'message(SEND_ERROR "You need to build static library to build tests")' ""
51 substituteInPlace build/cmake/tests/CMakeLists.txt \
52 --replace 'libzstd_static' 'libzstd_shared'
54 "1aexport ${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/build_/lib" \
59 lib.attrsets.mapAttrsToList (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}")
61 BUILD_SHARED = !static;
62 BUILD_STATIC = enableStatic;
63 BUILD_CONTRIB = buildContrib;
64 PROGRAMS_LINK_SHARED = !static;
65 LEGACY_SUPPORT = legacySupport;
66 BUILD_TESTS = doCheck;
69 cmakeDir = "../build/cmake";
70 dontUseCmakeBuildDir = true;
72 mkdir -p build_ && cd $_
75 nativeCheckInputs = [ file ];
79 # Patch shebangs for playTests
80 patchShebangs ../programs/zstdgrep
81 ctest -R playTests # The only relatively fast test.
88 substituteInPlace ../programs/zstdgrep \
89 --replace ":-grep" ":-${gnugrep}/bin/grep" \
90 --replace ":-zstdcat" ":-$bin/bin/zstdcat"
92 substituteInPlace ../programs/zstdless \
93 --replace "zstdcat" "$bin/bin/zstdcat"
95 + lib.optionalString buildContrib (
97 cp contrib/pzstd/pzstd $bin/bin/pzstd
99 + lib.optionalString stdenv.hostPlatform.isDarwin ''
100 install_name_tool -change @rpath/libzstd.1.dylib $out/lib/libzstd.1.dylib $bin/bin/pzstd
109 ++ lib.optional stdenv.hostPlatform.isUnix "man"
113 updateScript = nix-update-script { };
115 inherit libarchive rocksdb arrow-cpp;
116 libzip = libzip.override { withZstd = true; };
117 curl = curl.override { zstdSupport = true; };
118 python-zstd = python3Packages.zstd;
119 haskell-zstd = haskellPackages.zstd;
120 haskell-hs-zstd = haskellPackages.hs-zstd;
125 description = "Zstandard real-time compression algorithm";
127 Zstd, short for Zstandard, is a fast lossless compression algorithm,
128 targeting real-time compression scenarios at zlib-level compression
129 ratio. Zstd can also offer stronger compression ratio at the cost of
130 compression speed. Speed/ratio trade-off is configurable by small
131 increment, to fit different situations. Note however that decompression
132 speed is preserved and remain roughly the same at all settings, a
133 property shared by most LZ compression algorithms, such as zlib.
135 homepage = "https://facebook.github.io/zstd/";
136 changelog = "https://github.com/facebook/zstd/blob/v${version}/CHANGELOG";
137 license = with licenses; [ bsd3 ]; # Or, at your opinion, GPL-2.0-only.
138 mainProgram = "zstd";
139 platforms = platforms.all;
140 maintainers = with maintainers; [ orivej ];