buildDotnetModule: support native binaries in nuget packages

This helps with ie. crossgen2 building, and packages that use protoc
This commit is contained in:
mdarocha 2023-06-21 17:06:26 +02:00
parent c51141d997
commit 29e770e0eb
2 changed files with 31 additions and 0 deletions

View file

@ -2,6 +2,8 @@
, stdenv
, which
, coreutils
, zlib
, openssl
, callPackage
, makeSetupHook
, makeWrapper
@ -26,6 +28,14 @@ in
propagatedBuildInputs = [ dotnet-sdk nuget-source ];
substitutions = {
nugetSource = nuget-source;
dynamicLinker = "${stdenv.cc}/nix-support/dynamic-linker";
libPath = lib.makeLibraryPath [
stdenv.cc.cc.lib
stdenv.cc.libc
dotnet-sdk.passthru.icu
zlib
openssl
];
inherit runtimeId;
};
} ./dotnet-configure-hook.sh) { };

View file

@ -51,6 +51,27 @@ EOF
dotnetRestore "$project"
done
echo "Fixing up native binaries..."
# Find all native binaries and nuget libraries, and fix them up,
# by setting the proper interpreter and rpath to some commonly used libraries
for binary in $(find "$HOME/.nuget/packages/" -type f -executable); do
if patchelf --print-interpreter "$binary" >/dev/null 2>/dev/null; then
echo "Found binary: $binary, fixing it up..."
patchelf --set-interpreter "$(cat "@dynamicLinker@")" "$binary"
# This makes sure that if the binary requires some specific runtime dependencies, it can find it.
# This fixes dotnet-built binaries like crossgen2
patchelf \
--add-needed libicui18n.so \
--add-needed libicuuc.so \
--add-needed libz.so \
--add-needed libssl.so \
"$binary"
patchelf --set-rpath "@libPath@" "$binary"
fi
done
runHook postConfigure
echo "Finished dotnetConfigureHook"