buildDotnetModule: support native binaries in nuget packages This helps with ie. crossgen2 building, and packages that use protoc

mdarocha 29e770e0 c51141d9

+31
+10
pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
··· 2 2 , stdenv 3 3 , which 4 4 , coreutils 5 + , zlib 6 + , openssl 5 7 , callPackage 6 8 , makeSetupHook 7 9 , makeWrapper ··· 26 28 propagatedBuildInputs = [ dotnet-sdk nuget-source ]; 27 29 substitutions = { 28 30 nugetSource = nuget-source; 31 + dynamicLinker = "${stdenv.cc}/nix-support/dynamic-linker"; 32 + libPath = lib.makeLibraryPath [ 33 + stdenv.cc.cc.lib 34 + stdenv.cc.libc 35 + dotnet-sdk.passthru.icu 36 + zlib 37 + openssl 38 + ]; 29 39 inherit runtimeId; 30 40 }; 31 41 } ./dotnet-configure-hook.sh) { };
+21
pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh
··· 51 51 dotnetRestore "$project" 52 52 done 53 53 54 + echo "Fixing up native binaries..." 55 + # Find all native binaries and nuget libraries, and fix them up, 56 + # by setting the proper interpreter and rpath to some commonly used libraries 57 + for binary in $(find "$HOME/.nuget/packages/" -type f -executable); do 58 + if patchelf --print-interpreter "$binary" >/dev/null 2>/dev/null; then 59 + echo "Found binary: $binary, fixing it up..." 60 + patchelf --set-interpreter "$(cat "@dynamicLinker@")" "$binary" 61 + 62 + # This makes sure that if the binary requires some specific runtime dependencies, it can find it. 63 + # This fixes dotnet-built binaries like crossgen2 64 + patchelf \ 65 + --add-needed libicui18n.so \ 66 + --add-needed libicuuc.so \ 67 + --add-needed libz.so \ 68 + --add-needed libssl.so \ 69 + "$binary" 70 + 71 + patchelf --set-rpath "@libPath@" "$binary" 72 + fi 73 + done 74 + 54 75 runHook postConfigure 55 76 56 77 echo "Finished dotnetConfigureHook"