nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 150 lines 4.7 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchpatch, 6 cmake, 7 bashNonInteractive, 8 gnugrep, 9 fixDarwinDylibNames, 10 file, 11 legacySupport ? false, 12 static ? stdenv.hostPlatform.isStatic, # generates static libraries *only* 13 enableStatic ? static, 14 # these need to be ran on the host, thus disable when cross-compiling 15 buildContrib ? stdenv.hostPlatform == stdenv.buildPlatform, 16 doCheck ? stdenv.hostPlatform == stdenv.buildPlatform, 17 nix-update-script, 18 19 # for passthru.tests 20 libarchive, 21 rocksdb, 22 arrow-cpp, 23 libzip, 24 curl, 25 python3Packages, 26 haskellPackages, 27}: 28 29stdenv.mkDerivation rec { 30 pname = "zstd"; 31 version = "1.5.7"; 32 33 src = fetchFromGitHub { 34 owner = "facebook"; 35 repo = "zstd"; 36 rev = "v${version}"; 37 hash = "sha256-tNFWIT9ydfozB8dWcmTMuZLCQmQudTFJIkSr0aG7S44="; 38 }; 39 40 nativeBuildInputs = [ cmake ] ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; 41 buildInputs = lib.optional stdenv.hostPlatform.isUnix bashNonInteractive; 42 43 patches = [ 44 # This patches makes sure we do not attempt to use the MD5 implementation 45 # of the host platform when running the tests 46 ./playtests-darwin.patch 47 48 # Pull missing manpages update: 49 # https://github.com/facebook/zstd/pull/4302 50 # TODO: remove with 1.5.8 release 51 (fetchpatch { 52 name = "man-fix.patch"; 53 url = "https://github.com/facebook/zstd/commit/6af3842118ea5325480b403213b2a9fbed3d3d74.patch"; 54 hash = "sha256-i+iv+owUXbKU3UtZBsjfj86kFB3TDlpcVDNsDX8dyZE="; 55 }) 56 ]; 57 58 postPatch = lib.optionalString (!static) '' 59 substituteInPlace build/cmake/CMakeLists.txt \ 60 --replace 'message(SEND_ERROR "You need to build static library to build tests")' "" 61 substituteInPlace build/cmake/tests/CMakeLists.txt \ 62 --replace 'libzstd_static' 'libzstd_shared' 63 sed -i \ 64 "1aexport ${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/build_/lib" \ 65 tests/playTests.sh 66 ''; 67 68 cmakeFlags = 69 lib.attrsets.mapAttrsToList (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") 70 { 71 BUILD_SHARED = !static; 72 BUILD_STATIC = enableStatic; 73 BUILD_CONTRIB = buildContrib; 74 PROGRAMS_LINK_SHARED = !static; 75 LEGACY_SUPPORT = legacySupport; 76 BUILD_TESTS = doCheck; 77 }; 78 79 cmakeDir = "../build/cmake"; 80 dontUseCmakeBuildDir = true; 81 preConfigure = '' 82 mkdir -p build_ && cd $_ 83 ''; 84 85 nativeCheckInputs = [ file ]; 86 inherit doCheck; 87 checkPhase = '' 88 runHook preCheck 89 # Patch shebangs for playTests 90 patchShebangs ../programs/zstdgrep 91 ctest -R playTests # The only relatively fast test. 92 runHook postCheck 93 ''; 94 95 preInstall = '' 96 mkdir -p $bin/bin 97 substituteInPlace ../programs/zstdgrep \ 98 --replace ":-grep" ":-${gnugrep}/bin/grep" \ 99 --replace ":-zstdcat" ":-$bin/bin/zstdcat" 100 101 substituteInPlace ../programs/zstdless \ 102 --replace "zstdcat" "$bin/bin/zstdcat" 103 '' 104 + lib.optionalString buildContrib ( 105 '' 106 cp contrib/pzstd/pzstd $bin/bin/pzstd 107 '' 108 + lib.optionalString stdenv.hostPlatform.isDarwin '' 109 install_name_tool -change @rpath/libzstd.1.dylib $out/lib/libzstd.1.dylib $bin/bin/pzstd 110 '' 111 ); 112 113 outputs = [ 114 "bin" 115 "dev" 116 ] 117 ++ lib.optional stdenv.hostPlatform.isUnix "man" 118 ++ [ "out" ]; 119 120 passthru = { 121 updateScript = nix-update-script { }; 122 tests = { 123 inherit libarchive rocksdb arrow-cpp; 124 libzip = libzip.override { withZstd = true; }; 125 curl = curl.override { zstdSupport = true; }; 126 python-zstd = python3Packages.zstd; 127 haskell-zstd = haskellPackages.zstd; 128 haskell-hs-zstd = haskellPackages.hs-zstd; 129 }; 130 }; 131 132 meta = with lib; { 133 description = "Zstandard real-time compression algorithm"; 134 longDescription = '' 135 Zstd, short for Zstandard, is a fast lossless compression algorithm, 136 targeting real-time compression scenarios at zlib-level compression 137 ratio. Zstd can also offer stronger compression ratio at the cost of 138 compression speed. Speed/ratio trade-off is configurable by small 139 increment, to fit different situations. Note however that decompression 140 speed is preserved and remain roughly the same at all settings, a 141 property shared by most LZ compression algorithms, such as zlib. 142 ''; 143 homepage = "https://facebook.github.io/zstd/"; 144 changelog = "https://github.com/facebook/zstd/blob/v${version}/CHANGELOG"; 145 license = with licenses; [ bsd3 ]; # Or, at your opinion, GPL-2.0-only. 146 mainProgram = "zstd"; 147 platforms = platforms.all; 148 maintainers = with maintainers; [ orivej ]; 149 }; 150}