From c06a0b2c8cf527b180740ee38e7d2fccad9fd064 Mon Sep 17 00:00:00 2001 From: Tobias Mayer Date: Fri, 11 Oct 2019 22:58:47 +0200 Subject: [PATCH] zstd: build with CMake CMake is used for static builds because the Makefile does not offer a way to disable the shared library. --- pkgs/tools/compression/zstd/default.nix | 51 ++++++++++--------------- pkgs/top-level/static.nix | 4 ++ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/pkgs/tools/compression/zstd/default.nix b/pkgs/tools/compression/zstd/default.nix index a3aecf88c907..82a6a3a8a53c 100644 --- a/pkgs/tools/compression/zstd/default.nix +++ b/pkgs/tools/compression/zstd/default.nix @@ -1,7 +1,8 @@ -{ stdenv, fetchFromGitHub, fetchpatch, gnugrep +{ stdenv, fetchFromGitHub, fetchpatch, cmake, gnugrep , fixDarwinDylibNames , file -, legacySupport ? false }: +, legacySupport ? false +, enableShared ? true }: stdenv.mkDerivation rec { pname = "zstd"; @@ -14,56 +15,46 @@ stdenv.mkDerivation rec { owner = "facebook"; }; + nativeBuildInputs = [ cmake ] + ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames; + patches = [ - # All 3 from https://github.com/facebook/zstd/pull/1883 + # From https://github.com/facebook/zstd/pull/1883 (fetchpatch { url = "https://github.com/facebook/zstd/commit/106278e7e5fafaea3b7deb4147bdc8071562d2f0.diff"; sha256 = "13z7id1qbc05cv1rmak7c8xrchp7jh1i623bq5pwcihg57wzcyr8"; }) - (fetchpatch { - url = "https://github.com/facebook/zstd/commit/0ede342acc2c26f87ae962fa88e158904d4198c4.diff"; - sha256 = "12l5xbvnzkvr76mvl1ls767paqfwbd9q1pzq44ckacfpz4f6iaap"; - excludes = [ - # I think line endings are causing problems, or something like that - "programs/windres/generate_res.bat" - ]; - }) - (fetchpatch { - url = "https://github.com/facebook/zstd/commit/10552eaffef84c011f67af0e04f0780b50a5ab26.diff"; - sha256 = "1s27ravar3rn7q8abybp9733jhpsfcaci51k04da94ahahvxwiqw"; - }) ] # This I didn't upstream because if you use posix threads with MinGW it will # work find, and I'm not sure how to write the condition. ++ stdenv.lib.optional stdenv.hostPlatform.isWindows ./mcfgthreads-no-pthread.patch; - nativeBuildInputs = stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames; - - makeFlags = [ - "ZSTD_LEGACY_SUPPORT=${if legacySupport then "1" else "0"}" - ] ++ stdenv.lib.optional stdenv.hostPlatform.isWindows "OS=Windows"; + cmakeFlags = [ + "-DZSTD_BUILD_SHARED:BOOL=${if enableShared then "ON" else "OFF"}" + "-DZSTD_LEGACY_SUPPORT:BOOL=${if legacySupport then "ON" else "OFF"}" + "-DZSTD_BUILD_TESTS:BOOL=ON" + ]; + cmakeDir = "../build/cmake"; + dontUseCmakeBuildDir = true; + preConfigure = '' + mkdir -p build_ && cd $_ + ''; checkInputs = [ file ]; doCheck = true; preCheck = '' - substituteInPlace tests/playTests.sh \ + substituteInPlace ../tests/playTests.sh \ --replace 'MD5SUM="md5 -r"' 'MD5SUM="md5sum"' ''; - installFlags = [ - "PREFIX=$(out)" - ]; - - preInstall = '' - substituteInPlace programs/zstdgrep \ + preInstall = stdenv.lib.optionalString enableShared '' + substituteInPlace ../programs/zstdgrep \ --replace ":-grep" ":-${gnugrep}/bin/grep" \ --replace ":-zstdcat" ":-$out/bin/zstdcat" - substituteInPlace programs/zstdless \ + substituteInPlace ../programs/zstdless \ --replace "zstdcat" "$out/bin/zstdcat" ''; - enableParallelBuilding = true; - meta = with stdenv.lib; { description = "Zstandard real-time compression algorithm"; longDescription = '' diff --git a/pkgs/top-level/static.nix b/pkgs/top-level/static.nix index 687086b6ed3b..8723e209e7f9 100644 --- a/pkgs/top-level/static.nix +++ b/pkgs/top-level/static.nix @@ -223,6 +223,10 @@ in { staticOnly = true; }; + zstd = super.zstd.override { + enableShared = false; + }; + llvmPackages_8 = super.llvmPackages_8 // { libraries = super.llvmPackages_8.libraries // rec { libcxxabi = super.llvmPackages_8.libraries.libcxxabi.override {