Skip to content

Commit

Permalink
nix(ldfi2): patchelf the dynamically linked libraries on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 30, 2021
1 parent 659e5b1 commit 236173e
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ stdenv.mkDerivation {
pname = "detsys";
version = "latest";

# NOTE: We cannot use `gitignoreSource` here, because the `bazel-bin`
# directory which we need to read from is ignored by git.
src = ./.;
# NOTE: When a `go_binary` is compiled with gotags it for some reason ends up
# in `bazel-out` rather than `bazel-bin`, which is why we need to add both
# below.
#
# TODO(stevan): k8-fastbuild-ST-578d10beb4b5 is probably unique to my machine,
# need to figure out how to get this path in a generic way in bazel.
src = if nix-build-all
then []
else [ ./bazel-bin/src ./bazel-out/k8-fastbuild-ST-578d10beb4b5/bin ];

phases = [ "installPhase" "installCheckPhase" ];

nativeBuildInputs = if stdenv.isLinux then [ patchelf ] else [];

propagatedBuildInputs = [ z3 ]
++ lib.optional (nix-build-all || nix-build-checker) [ checker ]
++ lib.optional (nix-build-all || nix-build-cli) [ cli ]
Expand All @@ -48,30 +56,34 @@ stdenv.mkDerivation {
installPhase = ''
mkdir -p $out/bin
# TODO(stevan): Is there a nicer way to access the two source directories?
export bazelBin="$(echo $src | cut -d ' ' -f 1)"
export bazelOut="$(echo $src | cut -d ' ' -f 2)"
${if nix-build-checker || nix-build-all then ''
install -D ${checker.out}/bin/detsys-checker $out/bin
'' else ''
install -D $src/bazel-bin/src/checker/checker-bin $out/bin/detsys-checker
install -D $bazelBin/checker/checker-bin $out/bin/detsys-checker
''
}
${if nix-build-cli || nix-build-all then ''
install -D ${cli.out}/bin/detsys $out/bin
'' else ''
install -D $src/bazel-bin/src/cli/cli_/cli $out/bin/detsys
install -D $bazelBin/cli/cli_/cli $out/bin/detsys
''
}
${if nix-build-db || nix-build-all then ''
install -D ${db.out}/bin/detsys-db $out/bin
cp -R ${db.out}/migrations $out
'' else ''
install -D $src/bazel-bin/src/db/db_/db $out/bin/detsys-db
install -D $bazelBin/db/db_/db $out/bin/detsys-db
# TODO(stevan): migrations need to be stored somewhere...
''
}
${if nix-build-debugger || nix-build-all then ''
install -D ${debugger.out}/bin/detsys-debug $out/bin
'' else ''
install -D $src/bazel-bin/src/debugger/cmd/detsys-debug/detsys-debug_/detsys-debug \
install -D $bazelOut/src/debugger/cmd/detsys-debug/detsys-debug_/detsys-debug \
$out/bin/detsys-debug
''
}
Expand All @@ -85,19 +97,28 @@ stdenv.mkDerivation {
${if nix-build-ldfi || nix-build-all then ''
install -D ${ldfi.out}/bin/detsys-ldfi $out/bin
'' else ''
install -D $src/bazel-bin/src/ldfi2/ldfi2 $out/bin/detsys-ldfi
install -D $bazelBin/ldfi2/ldfi2 $out/bin/detsys-ldfi
${lib.optionalString stdenv.isLinux ''
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
"$out/bin/detsys-ldfi"
rpath=${lib.makeLibraryPath [ z3 stdenv.cc.cc gmp libffi ]}
patchelf --set-rpath "$out/lib:$rpath" \
"$out/bin/detsys-ldfi"
''
}
# TODO(stevan): Darwin probably needs fixing as well?
''
}
${if nix-build-ltl || nix-build-all then ''
install -D ${ltl.out}/bin/detsys-ltl $out/bin
'' else ''
install -D $src/bazel-bin/src/ltl/ltl $out/bin/detsys-ltl
install -D $bazelBin/ltl/ltl $out/bin/detsys-ltl
''
}
${if nix-build-scheduler || nix-build-all then ''
install -D ${scheduler.out}/bin/detsys-scheduler $out/bin
'' else ''
install -D $src/bazel-bin/src/scheduler/scheduler-bin $out/bin/detsys-scheduler
install -D $bazelBin/scheduler/scheduler-bin $out/bin/detsys-scheduler
''
}
'';
Expand Down

0 comments on commit 236173e

Please sign in to comment.