about summary refs log tree commit diff
path: root/pkgs/build-support/dotnet/build-dotnet-module
diff options
context:
space:
mode:
authorDavid McFarland <corngood@gmail.com>2022-09-26 14:35:14 -0300
committerDavid McFarland <corngood@gmail.com>2022-12-19 15:36:25 -0400
commit824d40aa0400e547c07c054ed7eddcf42b68955e (patch)
tree27a8d2b43ad4eb455b0b21b85684ebb265106bb2 /pkgs/build-support/dotnet/build-dotnet-module
parent13861970f4ae8d029d6609ece5c31200233d49f4 (diff)
build-dotnet-module: restore for current runtime by default
Diffstat (limited to 'pkgs/build-support/dotnet/build-dotnet-module')
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix22
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix7
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh2
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh1
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh3
5 files changed, 20 insertions, 15 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index 17a82677c1485..7f05a3a4eecc6 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -59,6 +59,9 @@
   # Libraries that need to be available at runtime should be passed through this.
   # These get wrapped into `LD_LIBRARY_PATH`.
 , runtimeDeps ? [ ]
+  # The dotnet runtime ID. If null, fetch-deps will gather dependencies for all
+  # platforms in meta.platforms which are supported by the sdk.
+, runtimeId ? null
 
   # Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
   # See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
@@ -90,6 +93,10 @@ let
 
   inherit (callPackage ./hooks {
     inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
+    runtimeId =
+      if runtimeId != null
+      then runtimeId
+      else dotnetCorePackages.systemToDotnetRid stdenvNoCC.targetPlatform.system;
   }) dotnetConfigureHook dotnetBuildHook dotnetCheckHook dotnetInstallHook dotnetFixupHook;
 
   localDeps =
@@ -156,16 +163,11 @@ stdenvNoCC.mkDerivation (args // {
 
     fetch-deps =
       let
-        # Derivations may set flags such as `--runtime <rid>` based on the host platform to avoid restoring/building nuget dependencies they dont have or dont need.
-        # This introduces an issue; In this script we loop over all platforms from `meta` and add the RID flag for it, as to fetch all required dependencies.
-        # The script would inherit the RID flag from the derivation based on the platform building the script, and set the flag for any iteration we do over the RIDs.
-        # That causes conflicts. To circumvent it we remove all occurances of the flag.
-        flags =
-          let
-            isRuntime = flag: lib.hasPrefix "--runtime" flag;
-          in
-            builtins.filter (flag: !(isRuntime flag)) (dotnetFlags ++ dotnetRestoreFlags);
-        runtimeIds = map (system: dotnetCorePackages.systemToDotnetRid system) platforms;
+        flags = dotnetFlags ++ dotnetRestoreFlags;
+        runtimeIds =
+          if runtimeId != null
+          then [ runtimeId ]
+          else map (system: dotnetCorePackages.systemToDotnetRid system) platforms;
       in
       writeShellScript "fetch-${pname}-deps" ''
         set -euo pipefail
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 1cc88602ff4c2..2309ae6240d24 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
@@ -9,7 +9,9 @@
 , dotnet-runtime
 , runtimeDeps
 , buildType
+, runtimeId
 }:
+assert (builtins.isString runtimeId);
 
 let
   libraryPath = lib.makeLibraryPath runtimeDeps;
@@ -21,6 +23,7 @@ in
       deps = [ dotnet-sdk nuget-source ];
       substitutions = {
         nugetSource = nuget-source;
+        inherit runtimeId;
       };
     } ./dotnet-configure-hook.sh) { };
 
@@ -29,7 +32,7 @@ in
       name = "dotnet-build-hook";
       deps = [ dotnet-sdk ];
       substitutions = {
-        inherit buildType;
+        inherit buildType runtimeId;
       };
     } ./dotnet-build-hook.sh) { };
 
@@ -49,7 +52,7 @@ in
       name = "dotnet-install-hook";
       deps = [ dotnet-sdk ];
       substitutions = {
-        inherit buildType;
+        inherit buildType runtimeId;
       };
     } ./dotnet-install-hook.sh) { };
 
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 782c170b0bb14..8f7f773393571 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+=("-p:SelfContained=true")
+        dotnetBuildFlags+=(--runtime "@runtimeId@" "-p:SelfContained=true")
     else
         dotnetBuildFlags+=("-p:SelfContained=false")
     fi
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 3479f58bb38c5..1e33ebbaef714 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
@@ -18,6 +18,7 @@ dotnetConfigureHook() {
         env dotnet restore ${project-} \
             -p:ContinuousIntegrationBuild=true \
             -p:Deterministic=true \
+            --runtime "@runtimeId@" \
             --source "@nugetSource@/lib" \
             ${parallelFlag-} \
             ${dotnetRestoreFlags[@]} \
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 196d2ca1af7aa..831059f941ca5 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,7 +7,7 @@ dotnetInstallHook() {
     runHook preInstall
 
     if [ "${selfContainedBuild-}" ]; then
-        dotnetInstallFlags+=("--self-contained")
+        dotnetInstallFlags+=(--runtime "@runtimeId@" "--self-contained")
     else
         dotnetInstallFlags+=("--no-self-contained")
     fi
@@ -21,7 +21,6 @@ dotnetInstallHook() {
         env dotnet publish ${project-} \
             -p:ContinuousIntegrationBuild=true \
             -p:Deterministic=true \
-            -p:UseAppHost=true \
             --output "$out/lib/${pname}" \
             --configuration "@buildType@" \
             --no-build \