Merge pull request #304780 from corngood/dotnet-self-contained-fix

dotnet: fix --self-contained builds
This commit is contained in:
David McFarland 2024-04-23 20:54:01 -03:00 committed by GitHub
commit d57d53726a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 22 additions and 33 deletions

View File

@ -2,7 +2,6 @@
, stdenv
, buildDotnetModule
, fetchFromGitHub
, autoPatchelfHook
, fontconfig
, xorg
, libglvnd
@ -27,7 +26,6 @@ buildDotnetModule rec {
dotnetFlags = [ "-p:Runtimeidentifier=linux-x64" ];
nativeBuildInputs = [
autoPatchelfHook
copyDesktopItems
graphicsmagick
];

View File

@ -4,7 +4,6 @@
fetchFromGitHub,
buildDotnetModule,
dotnetCorePackages,
autoPatchelfHook,
zlib,
openssl,
}:
@ -25,7 +24,6 @@ buildDotnetModule rec {
dotnet-sdk = dotnetCorePackages.sdk_7_0;
dotnet-runtime = dotnetCorePackages.aspnetcore_7_0;
nativeBuildInputs = [autoPatchelfHook];
buildInputs = [stdenv.cc.cc.lib zlib];
runtimeDeps = [openssl zlib];

View File

@ -15,7 +15,6 @@
, makeDesktopItem
, copyDesktopItems
, icoutils
, autoPatchelfHook
, bintools
, fixDarwinDylibNames
, autoSignDarwinBinariesHook
@ -40,8 +39,7 @@ buildDotnetModule rec {
nativeBuildInputs = [
copyDesktopItems
icoutils
] ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ bintools fixDarwinDylibNames ]
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ bintools fixDarwinDylibNames ]
++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [ autoSignDarwinBinariesHook ];
buildInputs = [

View File

@ -25,6 +25,7 @@ assert if type == "sdk" then packages != null else true;
, writeShellScript
, mkNugetDeps
, callPackage
, dotnetCorePackages
}:
let
@ -44,6 +45,8 @@ let
mkCommon = callPackage ./common.nix {};
targetRid = dotnetCorePackages.systemToDotnetRid stdenv.targetPlatform.system;
in
mkCommon type rec {
inherit pname version;
@ -88,21 +91,21 @@ mkCommon type rec {
# Tell autoPatchelf about runtime dependencies.
# (postFixup phase is run before autoPatchelfHook.)
postFixup = lib.optionalString stdenv.isLinux ''
postFixup = lib.optionalString stdenv.targetPlatform.isLinux ''
patchelf \
--add-needed libicui18n.so \
--add-needed libicuuc.so \
$out/shared/Microsoft.NETCore.App/*/libcoreclr.so \
$out/shared/Microsoft.NETCore.App/*/*System.Globalization.Native.so \
$out/packs/Microsoft.NETCore.App.Host.linux-x64/*/runtimes/linux-x64/native/singlefilehost
$out/packs/Microsoft.NETCore.App.Host.${targetRid}/*/runtimes/${targetRid}/native/*host
patchelf \
--add-needed libgssapi_krb5.so \
$out/shared/Microsoft.NETCore.App/*/*System.Net.Security.Native.so \
$out/packs/Microsoft.NETCore.App.Host.linux-x64/*/runtimes/linux-x64/native/singlefilehost
$out/packs/Microsoft.NETCore.App.Host.${targetRid}/*/runtimes/${targetRid}/native/*host
patchelf \
--add-needed libssl.so \
$out/shared/Microsoft.NETCore.App/*/*System.Security.Cryptography.Native.OpenSsl.so \
$out/packs/Microsoft.NETCore.App.Host.linux-x64/*/runtimes/linux-x64/native/singlefilehost
$out/packs/Microsoft.NETCore.App.Host.${targetRid}/*/runtimes/${targetRid}/native/*host
'';
passthru = {

View File

@ -63,7 +63,7 @@
'' + build);
in
if run == null
then build
then built
else
runCommand "${built.name}-run" { src = built; nativeBuildInputs = runInputs; } (
lib.optionalString (runtime != null) ''
@ -71,8 +71,10 @@
export DOTNET_ROOT=${runtime}
'' + run);
# Setting LANG to something other than 'C' forces the runtime to search
# for ICU, which will be required in most user environments.
checkConsoleOutput = command: ''
output="$(${command})"
output="$(LANG=C.UTF-8 ${command})"
# yes, older SDKs omit the comma
[[ "$output" =~ Hello,?\ World! ]] && touch "$out"
'';
@ -98,6 +100,15 @@
run = checkConsoleOutput "$src/test";
};
self-contained = mkDotnetTest {
name = "self-contained";
template = "console";
usePackageSource = true;
build = "dotnet publish --use-current-runtime --sc -o $out";
runtime = null;
run = checkConsoleOutput "$src/test";
};
single-file = mkDotnetTest {
name = "single-file";
template = "console";

View File

@ -1,6 +1,5 @@
{ lib
, stdenv
, autoPatchelfHook
, buildDotnetModule
, dotnetCorePackages
, fetchFromGitHub
@ -17,7 +16,6 @@ buildDotnetModule rec {
hash = "sha512-aUjjT5Qf64wrKRn1vkwJadMOBWMkvsXUjtZ7S3/ZWAh1CCDkQNO84mSbtbVc9ny0fKeJEqaDX2tJNwq7pYqAbA==";
};
nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
buildInputs = [ stdenv.cc.cc.lib ];
projectFile = "inklecate/inklecate.csproj";

View File

@ -1,5 +1,4 @@
{ autoPatchelfHook
, autoSignDarwinBinariesHook
{ autoSignDarwinBinariesHook
, buildDotnetModule
, dotnetCorePackages
, fetchFromGitHub
@ -114,8 +113,6 @@ buildDotnetModule rec {
nativeBuildInputs = [
which
git
] ++ lib.optionals stdenv.isLinux [
autoPatchelfHook
] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
autoSignDarwinBinariesHook
];

View File

@ -3,7 +3,6 @@
stdenv,
buildDotnetModule,
fetchFromGitHub,
autoPatchelfHook,
wrapGAppsHook,
dotnetCorePackages,
fontconfig,
@ -40,7 +39,6 @@ buildDotnetModule rec {
];
nativeBuildInputs = [
autoPatchelfHook
wrapGAppsHook
];
@ -64,12 +62,6 @@ buildDotnetModule rec {
libXi
]);
# Attempts to patchelf unneeded SOs
autoPatchelfIgnoreMissingDeps = [
"libc.musl-x86_64.so.1"
"libintl.so.8"
];
meta = with lib; {
description = "A tracking application for A Link to the Past Randomizer";
homepage = "https://github.com/trippsc2/OpenTracker";

View File

@ -4,7 +4,6 @@
, dotnet-runtime_8
, buildDotnetModule
, fetchFromGitHub
, autoPatchelfHook
, fontconfig
, xorg
, libglvnd
@ -12,9 +11,6 @@
, copyDesktopItems
}:
# NOTES:
# 1. we need autoPatchelfHook for quite a number of things in $out/lib
buildDotnetModule rec {
pname = "mqttmultimeter";
version = "1.8.2.272";
@ -35,13 +31,11 @@ buildDotnetModule rec {
executables = [ "mqttMultimeter" ];
nativeBuildInputs = [
autoPatchelfHook
copyDesktopItems
];
buildInputs = [ stdenv.cc.cc.lib fontconfig ];
# don't care about musl and windows versions, as they fail autoPatchelfHook
postInstall = ''
rm -rf $out/lib/${lib.toLower pname}/runtimes/{*musl*,win*}
'';