diff options
author | Sandro <sandro.jaeckel@gmail.com> | 2023-06-22 22:26:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 22:26:53 +0200 |
commit | 67f4868a434351bb28a1fba0b024af109b74680a (patch) | |
tree | 340c32ea28ca36fa4384f25b0c76772cc8acf181 /pkgs/build-support | |
parent | 230a3705fc136d8d65ad524dc0e196193c52b0c6 (diff) | |
parent | 1be24097b3db6b8c485b6996e7616cf75f6f487c (diff) |
Merge pull request #233422 from mdarocha/crossgen-fix
buildDotnetModule: support ReadyToRun and native binaries inside nuget files
Diffstat (limited to 'pkgs/build-support')
5 files changed, 58 insertions, 3 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix index 99d9644f8b701..8d0d27f673454 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix @@ -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) { }; @@ -44,7 +54,7 @@ in name = "dotnet-check-hook"; propagatedBuildInputs = [ dotnet-test-sdk ]; substitutions = { - inherit buildType libraryPath; + inherit buildType runtimeId libraryPath; disabledTests = lib.optionalString (disabledTests != []) (let escapedNames = lib.lists.map (n: lib.replaceStrings [","] ["%2C"] n) disabledTests; diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh index 8f7f773393571..e9567b64cf2c9 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh @@ -15,7 +15,7 @@ dotnetBuildHook() { fi if [ "${selfContainedBuild-}" ]; then - dotnetBuildFlags+=(--runtime "@runtimeId@" "-p:SelfContained=true") + dotnetBuildFlags+=("-p:SelfContained=true") else dotnetBuildFlags+=("-p:SelfContained=false") fi @@ -30,6 +30,12 @@ dotnetBuildHook() { dotnetBuild() { local -r project="${1-}" + + runtimeIdFlags=() + if [[ "$project" == *.csproj ]] || [ "${selfContainedBuild-}" ]; then + runtimeIdFlags+=("--runtime @runtimeId@") + fi + env dotnet build ${project-} \ -maxcpucount:$maxCpuFlag \ -p:BuildInParallel=$parallelBuildFlag \ @@ -38,6 +44,7 @@ dotnetBuildHook() { --configuration "@buildType@" \ --no-restore \ ${versionFlag-} \ + ${runtimeIdFlags[@]} \ ${dotnetBuildFlags[@]} \ ${dotnetFlags[@]} } diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh index fdcf8d54be460..507721ef98181 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh @@ -17,6 +17,11 @@ dotnetCheckHook() { fi for project in ${testProjectFile[@]-${projectFile[@]}}; do + runtimeIdFlags=() + if [[ "$project" == *.csproj ]]; then + runtimeIdFlags=("--runtime @runtimeId@") + fi + env "LD_LIBRARY_PATH=@libraryPath@" \ dotnet test "$project" \ -maxcpucount:$maxCpuFlag \ @@ -26,6 +31,7 @@ dotnetCheckHook() { --no-build \ --logger "console;verbosity=normal" \ ${disabledTestsFlag-} \ + ${runtimeIdFlags[@]} \ "${dotnetTestFlags[@]}" \ "${dotnetFlags[@]}" done diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh index 20e353e2b418f..c046fc3c306b1 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh @@ -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" diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh index 831059f941ca5..8035b42d08608 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh @@ -7,9 +7,12 @@ dotnetInstallHook() { runHook preInstall if [ "${selfContainedBuild-}" ]; then - dotnetInstallFlags+=(--runtime "@runtimeId@" "--self-contained") + dotnetInstallFlags+=("--self-contained") else dotnetInstallFlags+=("--no-self-contained") + # https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained + # Trimming is only available for self-contained build, so force disable it here + dotnetInstallFlags+=("-p:PublishTrimmed=false") fi if [ "${useAppHost-}" ]; then @@ -18,12 +21,19 @@ dotnetInstallHook() { dotnetPublish() { local -r project="${1-}" + + runtimeIdFlags=() + if [[ "$project" == *.csproj ]] || [ "${selfContainedBuild-}" ]; then + runtimeIdFlags+=("--runtime @runtimeId@") + fi + env dotnet publish ${project-} \ -p:ContinuousIntegrationBuild=true \ -p:Deterministic=true \ --output "$out/lib/${pname}" \ --configuration "@buildType@" \ --no-build \ + ${runtimeIdFlags[@]} \ ${dotnetInstallFlags[@]} \ ${dotnetFlags[@]} } @@ -36,6 +46,7 @@ dotnetInstallHook() { --output "$out/share" \ --configuration "@buildType@" \ --no-build \ + --runtime "@runtimeId@" \ ${dotnetPackFlags[@]} \ ${dotnetFlags[@]} } |