1 { lib, stdenv, fetchFromGitHub, cmake, bash, gnugrep
5 , legacySupport ? false
6 , static ? stdenv.hostPlatform.isStatic
7 # these need to be ran on the host, thus disable when cross-compiling
8 , buildContrib ? stdenv.hostPlatform == stdenv.buildPlatform
9 , doCheck ? stdenv.hostPlatform == stdenv.buildPlatform
13 stdenv.mkDerivation rec {
17 src = fetchFromGitHub {
21 sha256 = "sha256-yJvhcysxcbUGuDOqe/TQ3Y5xyM2AUw6r1THSHOqmUy0=";
24 nativeBuildInputs = [ cmake ]
25 ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
26 buildInputs = lib.optional stdenv.hostPlatform.isUnix bash;
29 # This patches makes sure we do not attempt to use the MD5 implementation
30 # of the host platform when running the tests
31 ./playtests-darwin.patch
34 postPatch = lib.optionalString (!static) ''
35 substituteInPlace build/cmake/CMakeLists.txt \
36 --replace 'message(SEND_ERROR "You need to build static library to build tests")' ""
37 substituteInPlace build/cmake/tests/CMakeLists.txt \
38 --replace 'libzstd_static' 'libzstd_shared'
40 "1aexport ${lib.optionalString stdenv.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/build_/lib" \
44 LDFLAGS = lib.optionalString stdenv.hostPlatform.isRiscV "-latomic";
46 cmakeFlags = lib.attrsets.mapAttrsToList
47 (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") {
48 BUILD_SHARED = !static;
49 BUILD_STATIC = static;
50 BUILD_CONTRIB = buildContrib;
51 PROGRAMS_LINK_SHARED = !static;
52 LEGACY_SUPPORT = legacySupport;
53 BUILD_TESTS = doCheck;
56 cmakeDir = "../build/cmake";
57 dontUseCmakeBuildDir = true;
59 mkdir -p build_ && cd $_
62 checkInputs = [ file ];
66 # Patch shebangs for playTests
67 patchShebangs ../programs/zstdgrep
68 ctest -R playTests # The only relatively fast test.
74 substituteInPlace ../programs/zstdgrep \
75 --replace ":-grep" ":-${gnugrep}/bin/grep" \
76 --replace ":-zstdcat" ":-$bin/bin/zstdcat"
78 substituteInPlace ../programs/zstdless \
79 --replace "zstdcat" "$bin/bin/zstdcat"
80 '' + lib.optionalString buildContrib ''
81 cp contrib/pzstd/pzstd $bin/bin/pzstd
82 '' + lib.optionalString stdenv.isDarwin ''
83 install_name_tool -change @rpath/libzstd.1.dylib $out/lib/libzstd.1.dylib $bin/bin/pzstd
86 outputs = [ "bin" "dev" ]
87 ++ lib.optional stdenv.hostPlatform.isUnix "man"
91 updateScript = nix-update-script {
97 description = "Zstandard real-time compression algorithm";
99 Zstd, short for Zstandard, is a fast lossless compression algorithm,
100 targeting real-time compression scenarios at zlib-level compression
101 ratio. Zstd can also offer stronger compression ratio at the cost of
102 compression speed. Speed/ratio trade-off is configurable by small
103 increment, to fit different situations. Note however that decompression
104 speed is preserved and remain roughly the same at all settings, a
105 property shared by most LZ compression algorithms, such as zlib.
107 homepage = "https://facebook.github.io/zstd/";
108 changelog = "https://github.com/facebook/zstd/blob/v${version}/CHANGELOG";
109 license = with licenses; [ bsd3 ]; # Or, at your opinion, GPL-2.0-only.
111 platforms = platforms.all;
112 maintainers = with maintainers; [ orivej ];