zstd: don't build contrib when cross-compiling

Tests and `./gen_html` from contrib need to run
on host architecture. Disable them when doing
cross-compiliation.
This commit is contained in:
Jonathan Ringer 2021-07-10 12:08:31 -07:00 committed by Jonathan Ringer
parent babb761ac6
commit 03e499425d

View file

@ -3,6 +3,9 @@
, file , file
, legacySupport ? false , legacySupport ? false
, static ? stdenv.hostPlatform.isStatic , static ? stdenv.hostPlatform.isStatic
# these need to be ran on the host, thus disable when cross-compiling
, buildContrib ? stdenv.hostPlatform == stdenv.buildPlatform
, doCheck ? stdenv.hostPlatform == stdenv.buildPlatform
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@ -40,7 +43,7 @@ stdenv.mkDerivation rec {
(name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") { (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") {
BUILD_SHARED = !static; BUILD_SHARED = !static;
BUILD_STATIC = static; BUILD_STATIC = static;
BUILD_CONTRIB = true; BUILD_CONTRIB = buildContrib;
PROGRAMS_LINK_SHARED = !static; PROGRAMS_LINK_SHARED = !static;
LEGACY_SUPPORT = legacySupport; LEGACY_SUPPORT = legacySupport;
BUILD_TESTS = doCheck; BUILD_TESTS = doCheck;
@ -53,7 +56,7 @@ stdenv.mkDerivation rec {
''; '';
checkInputs = [ file ]; checkInputs = [ file ];
doCheck = stdenv.hostPlatform == stdenv.buildPlatform; inherit doCheck;
checkPhase = '' checkPhase = ''
runHook preCheck runHook preCheck
# Patch shebangs for playTests # Patch shebangs for playTests
@ -64,7 +67,6 @@ stdenv.mkDerivation rec {
preInstall = '' preInstall = ''
mkdir -p $bin/bin mkdir -p $bin/bin
cp contrib/pzstd/pzstd $bin/bin/pzstd
substituteInPlace ../programs/zstdgrep \ substituteInPlace ../programs/zstdgrep \
--replace ":-grep" ":-${gnugrep}/bin/grep" \ --replace ":-grep" ":-${gnugrep}/bin/grep" \
--replace ":-zstdcat" ":-$bin/bin/zstdcat" --replace ":-zstdcat" ":-$bin/bin/zstdcat"
@ -73,6 +75,8 @@ stdenv.mkDerivation rec {
--replace "zstdcat" "$bin/bin/zstdcat" --replace "zstdcat" "$bin/bin/zstdcat"
'' + lib.optionalString stdenv.isDarwin '' '' + lib.optionalString stdenv.isDarwin ''
install_name_tool -change @rpath/libzstd.1.dylib $out/lib/libzstd.1.dylib $bin/bin/pzstd install_name_tool -change @rpath/libzstd.1.dylib $out/lib/libzstd.1.dylib $bin/bin/pzstd
'' + lib.optionalString buildContrib ''
cp contrib/pzstd/pzstd $bin/bin/pzstd
''; '';
outputs = [ "bin" "dev" ] outputs = [ "bin" "dev" ]