about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authormdarocha <git@mdarocha.pl>2023-06-21 17:06:26 +0200
committermdarocha <git@mdarocha.pl>2023-06-21 17:06:30 +0200
commitc51141d9972c54a93b4088b95720855754b6a07e (patch)
treef8ad73376caa0cd7faea334183b9cebce3fba57e /pkgs/build-support
parentd6b7d2bac8b90c4713526962fdbf7bb5562072b5 (diff)
buildDotnetModule: pass runtimeId whenever possible and disable trimming when not allowed.
This fixes up some build errors
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix2
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh9
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh6
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh13
4 files changed, 27 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..52044770ec051 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/default.nix
@@ -44,7 +44,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-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[@]}
     }