From 051f3f948f7261dd6472a45c2a1ee17e42f2a4e2 Mon Sep 17 00:00:00 2001 From: Ivar Scholten Date: Thu, 19 May 2022 03:41:08 +0200 Subject: [PATCH 1/2] dotnet: fix cross compilation --- .../compilers/dotnet/build-dotnet.nix | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/pkgs/development/compilers/dotnet/build-dotnet.nix b/pkgs/development/compilers/dotnet/build-dotnet.nix index e16049e8594b..11150ec7ca16 100644 --- a/pkgs/development/compilers/dotnet/build-dotnet.nix +++ b/pkgs/development/compilers/dotnet/build-dotnet.nix @@ -4,12 +4,14 @@ , icu #passing icu as an argument, because dotnet 3.1 has troubles with icu71 }: -assert builtins.elem type [ "aspnetcore" "runtime" "sdk"]; +assert builtins.elem type [ "aspnetcore" "runtime" "sdk" ]; { lib , stdenv , fetchurl , writeText +, autoPatchelfHook +, makeWrapper , libunwind , openssl , libuuid @@ -19,19 +21,21 @@ assert builtins.elem type [ "aspnetcore" "runtime" "sdk"]; }: let - pname = if type == "aspnetcore" then - "aspnetcore-runtime" - else if type == "runtime" then - "dotnet-runtime" - else - "dotnet-sdk"; + pname = + if type == "aspnetcore" then + "aspnetcore-runtime" + else if type == "runtime" then + "dotnet-runtime" + else + "dotnet-sdk"; descriptions = { aspnetcore = "ASP.NET Core Runtime ${version}"; runtime = ".NET Runtime ${version}"; sdk = ".NET SDK ${version}"; }; -in stdenv.mkDerivation rec { +in +stdenv.mkDerivation rec { inherit pname version; # Some of these dependencies are `dlopen()`ed. @@ -47,8 +51,19 @@ in stdenv.mkDerivation rec { lttng-ust_2_12 ]); - src = fetchurl (srcs."${stdenv.hostPlatform.system}" or (throw - "Missing source (url and hash) for host system: ${stdenv.hostPlatform.system}")); + nativeBuildInputs = [ + autoPatchelfHook + makeWrapper + ]; + + buildInputs = [ + stdenv.cc.cc + ]; + + src = fetchurl ( + srcs."${stdenv.hostPlatform.system}" or (throw + "Missing source (url and hash) for host system: ${stdenv.hostPlatform.system}") + ); sourceRoot = "."; @@ -68,10 +83,16 @@ in stdenv.mkDerivation rec { patchelf --set-rpath "${rpath}" $out/dotnet find $out -type f -name "*.so" -exec patchelf --set-rpath '$ORIGIN:${rpath}' {} \; find $out -type f \( -name "apphost" -or -name "createdump" \) -exec patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" --set-rpath '$ORIGIN:${rpath}' {} \; + + wrapProgram $out/bin/dotnet \ + --prefix LD_LIBRARY_PATH : ${icu}/lib ''; doInstallCheck = true; installCheckPhase = '' + # Fixes cross + export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 + $out/bin/dotnet --info ''; @@ -85,6 +106,10 @@ in stdenv.mkDerivation rec { export DOTNET_CLI_TELEMETRY_OPTOUT=1 ''; + passthru = { + inherit icu; + }; + meta = with lib; { description = builtins.getAttr type descriptions; homepage = "https://dotnet.github.io/"; From 0d8b21b3c840510191c539175be6a60f2a6a6c77 Mon Sep 17 00:00:00 2001 From: Ivar Scholten Date: Sat, 21 May 2022 15:33:02 +0200 Subject: [PATCH 2/2] buildDotnetModule: fix cross compilation --- pkgs/build-support/dotnet/build-dotnet-module/default.nix | 6 +++++- .../dotnet/build-dotnet-module/hooks/default.nix | 2 +- .../build-dotnet-module/hooks/dotnet-configure-hook.sh | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix index fa987237a75c..7e99e455017a 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix @@ -94,9 +94,13 @@ in stdenvNoCC.mkDerivation (args // { dotnetInstallHook dotnetFixupHook - dotnet-sdk cacert makeWrapper + dotnet-sdk + ]; + + makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [ + "--prefix LD_LIBRARY_PATH : ${dotnet-sdk.icu}/lib" ]; # Stripping breaks the executable 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 76f7eea5bfec..e1b05c032a09 100644 --- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix +++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix @@ -53,7 +53,7 @@ dotnetFixupHook = callPackage ({ }: makeSetupHook { name = "dotnet-fixup-hook"; - deps = [ dotnet-runtime makeWrapper ]; + deps = [ dotnet-runtime ]; substitutions = { dotnetRuntime = dotnet-runtime; runtimeDeps = lib.makeLibraryPath runtimeDeps; 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 1686c15d2693..3e8c14189500 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 @@ -1,6 +1,6 @@ declare -a projectFile testProjectFile -# inherit arguments from derivation +# Inherit arguments from derivation dotnetFlags=( ${dotnetFlags[@]-} ) dotnetRestoreFlags=( ${dotnetRestoreFlags[@]-} )