zstd: build with CMake

CMake is used for static builds because the Makefile does not
offer a way to disable the shared library.
This commit is contained in:
Tobias Mayer 2019-10-11 22:58:47 +02:00
parent 3ad650a14b
commit c06a0b2c8c
2 changed files with 25 additions and 30 deletions

View File

@ -1,7 +1,8 @@
{ stdenv, fetchFromGitHub, fetchpatch, gnugrep { stdenv, fetchFromGitHub, fetchpatch, cmake, gnugrep
, fixDarwinDylibNames , fixDarwinDylibNames
, file , file
, legacySupport ? false }: , legacySupport ? false
, enableShared ? true }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "zstd"; pname = "zstd";
@ -14,56 +15,46 @@ stdenv.mkDerivation rec {
owner = "facebook"; owner = "facebook";
}; };
nativeBuildInputs = [ cmake ]
++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames;
patches = [ patches = [
# All 3 from https://github.com/facebook/zstd/pull/1883 # From https://github.com/facebook/zstd/pull/1883
(fetchpatch { (fetchpatch {
url = "https://github.com/facebook/zstd/commit/106278e7e5fafaea3b7deb4147bdc8071562d2f0.diff"; url = "https://github.com/facebook/zstd/commit/106278e7e5fafaea3b7deb4147bdc8071562d2f0.diff";
sha256 = "13z7id1qbc05cv1rmak7c8xrchp7jh1i623bq5pwcihg57wzcyr8"; 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 ] # 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. # work find, and I'm not sure how to write the condition.
++ stdenv.lib.optional stdenv.hostPlatform.isWindows ./mcfgthreads-no-pthread.patch; ++ stdenv.lib.optional stdenv.hostPlatform.isWindows ./mcfgthreads-no-pthread.patch;
nativeBuildInputs = stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames; cmakeFlags = [
"-DZSTD_BUILD_SHARED:BOOL=${if enableShared then "ON" else "OFF"}"
makeFlags = [ "-DZSTD_LEGACY_SUPPORT:BOOL=${if legacySupport then "ON" else "OFF"}"
"ZSTD_LEGACY_SUPPORT=${if legacySupport then "1" else "0"}" "-DZSTD_BUILD_TESTS:BOOL=ON"
] ++ stdenv.lib.optional stdenv.hostPlatform.isWindows "OS=Windows"; ];
cmakeDir = "../build/cmake";
dontUseCmakeBuildDir = true;
preConfigure = ''
mkdir -p build_ && cd $_
'';
checkInputs = [ file ]; checkInputs = [ file ];
doCheck = true; doCheck = true;
preCheck = '' preCheck = ''
substituteInPlace tests/playTests.sh \ substituteInPlace ../tests/playTests.sh \
--replace 'MD5SUM="md5 -r"' 'MD5SUM="md5sum"' --replace 'MD5SUM="md5 -r"' 'MD5SUM="md5sum"'
''; '';
installFlags = [ preInstall = stdenv.lib.optionalString enableShared ''
"PREFIX=$(out)" substituteInPlace ../programs/zstdgrep \
];
preInstall = ''
substituteInPlace programs/zstdgrep \
--replace ":-grep" ":-${gnugrep}/bin/grep" \ --replace ":-grep" ":-${gnugrep}/bin/grep" \
--replace ":-zstdcat" ":-$out/bin/zstdcat" --replace ":-zstdcat" ":-$out/bin/zstdcat"
substituteInPlace programs/zstdless \ substituteInPlace ../programs/zstdless \
--replace "zstdcat" "$out/bin/zstdcat" --replace "zstdcat" "$out/bin/zstdcat"
''; '';
enableParallelBuilding = true;
meta = with stdenv.lib; { meta = with stdenv.lib; {
description = "Zstandard real-time compression algorithm"; description = "Zstandard real-time compression algorithm";
longDescription = '' longDescription = ''

View File

@ -223,6 +223,10 @@ in {
staticOnly = true; staticOnly = true;
}; };
zstd = super.zstd.override {
enableShared = false;
};
llvmPackages_8 = super.llvmPackages_8 // { llvmPackages_8 = super.llvmPackages_8 // {
libraries = super.llvmPackages_8.libraries // rec { libraries = super.llvmPackages_8.libraries // rec {
libcxxabi = super.llvmPackages_8.libraries.libcxxabi.override { libcxxabi = super.llvmPackages_8.libraries.libcxxabi.override {