Merge pull request #50302 from zimbatm/libredirect-misc

libredirect: misc changes
This commit is contained in:
zimbatm 2018-11-14 00:16:56 +01:00 committed by GitHub
commit 695a3d4254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
{ stdenv, coreutils }: { stdenv, lib, coreutils }:
stdenv.mkDerivation { stdenv.mkDerivation {
name = "libredirect-0"; name = "libredirect-0";
@ -8,11 +8,15 @@ stdenv.mkDerivation {
cp ${./test.c} test.c cp ${./test.c} test.c
''; '';
shlibext = stdenv.targetPlatform.extensions.sharedLibrary; libName = "libredirect" + stdenv.targetPlatform.extensions.sharedLibrary;
outputs = ["out" "hook"];
buildPhase = '' buildPhase = ''
$CC -Wall -std=c99 -O3 -shared libredirect.c \ $CC -Wall -std=c99 -O3 -fPIC -ldl -shared \
-o "libredirect$shlibext" -fPIC -ldl ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/$libName"} \
-o "$libName" \
libredirect.c
if [ -n "$doInstallCheck" ]; then if [ -n "$doInstallCheck" ]; then
$CC -Wall -std=c99 -O3 test.c -o test $CC -Wall -std=c99 -O3 test.c -o test
@ -20,18 +24,26 @@ stdenv.mkDerivation {
''; '';
installPhase = '' installPhase = ''
install -vD "libredirect$shlibext" "$out/lib/libredirect$shlibext" install -vD "$libName" "$out/lib/$libName"
mkdir -p "$hook/nix-support"
cat <<SETUP_HOOK > "$hook/nix-support/setup-hook"
${if stdenv.isDarwin then ''
export DYLD_INSERT_LIBRARIES="$out/lib/$libName"
export DYLD_FORCE_FLAT_NAMESPACE=1
'' else ''
export LD_PRELOAD="$out/lib/$libName"
''}
SETUP_HOOK
''; '';
doInstallCheck = true; doInstallCheck = true;
installCheckPhase = if stdenv.isDarwin then '' installCheckPhase = ''
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \ (
DYLD_INSERT_LIBRARIES="$out/lib/libredirect$shlibext" \ source "$hook/nix-support/setup-hook"
DYLD_FORCE_FLAT_NAMESPACE=1 ./test NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" ./test
'' else '' )
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
LD_PRELOAD="$out/lib/libredirect$shlibext" ./test
''; '';
meta = { meta = {