summary refs log tree commit diff
path: root/pkgs/build-support/dotnet
diff options
context:
space:
mode:
authorIvar Scholten <ivar.scholten@protonmail.com>2022-02-11 16:42:07 +0100
committerIvar Scholten <ivar.scholten@protonmail.com>2022-02-11 16:42:07 +0100
commitb2b54c980a6d0fe1df731e24fc2fc17aeb755efe (patch)
tree6a3f8221c1ce825542de13109c39f91ec18ba8c5 /pkgs/build-support/dotnet
parent1878b7b1b2fd3186e48511ba3a0ea8e3574664fc (diff)
downloadnixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.tar
nixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.tar.gz
nixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.tar.bz2
nixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.tar.lz
nixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.tar.xz
nixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.tar.zst
nixpkgs-b2b54c980a6d0fe1df731e24fc2fc17aeb755efe.zip
dotnetbuildhelpers: move to pkgs/build-support/dotnet
Diffstat (limited to 'pkgs/build-support/dotnet')
-rw-r--r--pkgs/build-support/dotnet/dotnetbuildhelpers/create-pkg-config-for-dll.sh23
-rw-r--r--pkgs/build-support/dotnet/dotnetbuildhelpers/default.nix18
-rwxr-xr-xpkgs/build-support/dotnet/dotnetbuildhelpers/patch-fsharp-targets.sh20
-rw-r--r--pkgs/build-support/dotnet/dotnetbuildhelpers/placate-nuget.sh7
-rw-r--r--pkgs/build-support/dotnet/dotnetbuildhelpers/placate-paket.sh7
-rw-r--r--pkgs/build-support/dotnet/dotnetbuildhelpers/remove-duplicated-dlls.sh22
6 files changed, 97 insertions, 0 deletions
diff --git a/pkgs/build-support/dotnet/dotnetbuildhelpers/create-pkg-config-for-dll.sh b/pkgs/build-support/dotnet/dotnetbuildhelpers/create-pkg-config-for-dll.sh
new file mode 100644
index 00000000000..37914170452
--- /dev/null
+++ b/pkgs/build-support/dotnet/dotnetbuildhelpers/create-pkg-config-for-dll.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+targetDir="$1"
+dllFullPath="$2"
+
+dllVersion="$(monodis --assembly "$dllFullPath" | grep ^Version: | cut -f 2 -d : | xargs)"
+[ -z "$dllVersion" ] && echo "Defaulting dllVersion to 0.0.0" && dllVersion="0.0.0"
+dllFileName="$(basename $dllFullPath)"
+dllRootName="$(basename -s .dll $dllFileName)"
+targetPcFile="$targetDir"/"$dllRootName".pc
+
+mkdir -p "$targetDir"
+
+cat > $targetPcFile << EOF
+Libraries=$dllFullPath
+
+Name: $dllRootName
+Description: $dllRootName
+Version: $dllVersion
+Libs: -r:$dllFileName
+EOF
+
+echo "Created $targetPcFile"
diff --git a/pkgs/build-support/dotnet/dotnetbuildhelpers/default.nix b/pkgs/build-support/dotnet/dotnetbuildhelpers/default.nix
new file mode 100644
index 00000000000..4348832ac04
--- /dev/null
+++ b/pkgs/build-support/dotnet/dotnetbuildhelpers/default.nix
@@ -0,0 +1,18 @@
+{ runCommand, mono, pkg-config }:
+  runCommand
+    "dotnetbuildhelpers"
+    { preferLocalBuild = true; }
+    ''
+      target="$out/bin"
+      mkdir -p "$target"
+
+      for script in ${./create-pkg-config-for-dll.sh} ${./patch-fsharp-targets.sh} ${./remove-duplicated-dlls.sh} ${./placate-nuget.sh} ${./placate-paket.sh}
+      do
+        scriptName="$(basename "$script" | cut -f 2- -d -)"
+        cp -v "$script" "$target"/"$scriptName"
+        chmod 755 "$target"/"$scriptName"
+        patchShebangs "$target"/"$scriptName"
+        substituteInPlace "$target"/"$scriptName" --replace pkg-config ${pkg-config}/bin/${pkg-config.targetPrefix}pkg-config
+        substituteInPlace "$target"/"$scriptName" --replace monodis ${mono}/bin/monodis
+      done
+    ''
diff --git a/pkgs/build-support/dotnet/dotnetbuildhelpers/patch-fsharp-targets.sh b/pkgs/build-support/dotnet/dotnetbuildhelpers/patch-fsharp-targets.sh
new file mode 100755
index 00000000000..3f81cc73e80
--- /dev/null
+++ b/pkgs/build-support/dotnet/dotnetbuildhelpers/patch-fsharp-targets.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Some project files look for F# targets in $(FSharpTargetsPath)
+# so it's a good idea to add something like this to your ~/.bash_profile:
+
+# export FSharpTargetsPath=$(dirname $(which fsharpc))/../lib/mono/4.0/Microsoft.FSharp.Targets
+
+# In build scripts, you would add somehting like this:
+
+# export FSharpTargetsPath="${fsharp}/lib/mono/4.0/Microsoft.FSharp.Targets"
+
+# However, some project files look for F# targets in the main Mono directory. When that happens
+# patch the project files using this script so they will look in $(FSharpTargetsPath) instead.
+
+echo "Patching F# targets in fsproj files..."
+
+find -iname \*.fsproj -print -exec \
+  sed --in-place=.bak \
+    -e 's,<FSharpTargetsPath>\([^<]*\)</FSharpTargetsPath>,<FSharpTargetsPath Condition="Exists('\'\\1\'')">\1</FSharpTargetsPath>,'g \
+    {} \;
diff --git a/pkgs/build-support/dotnet/dotnetbuildhelpers/placate-nuget.sh b/pkgs/build-support/dotnet/dotnetbuildhelpers/placate-nuget.sh
new file mode 100644
index 00000000000..8a7f36522a3
--- /dev/null
+++ b/pkgs/build-support/dotnet/dotnetbuildhelpers/placate-nuget.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+echo Placating Nuget in nuget.targets
+find -iname nuget.targets -print -exec sed --in-place=bak -e 's,mono --runtime[^<]*,true NUGET PLACATED BY buildDotnetPackage,g' {} \;
+
+echo Just to be sure, replacing Nuget executables by empty files.
+find . -iname nuget.exe \! -size 0 -exec mv -v {} {}.bak \; -exec touch {} \;
diff --git a/pkgs/build-support/dotnet/dotnetbuildhelpers/placate-paket.sh b/pkgs/build-support/dotnet/dotnetbuildhelpers/placate-paket.sh
new file mode 100644
index 00000000000..0dbf1eecbad
--- /dev/null
+++ b/pkgs/build-support/dotnet/dotnetbuildhelpers/placate-paket.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+echo Placating Paket in paket.targets
+find -iname paket.targets -print -exec sed --in-place=bak -e 's,mono --runtime[^<]*,true PAKET PLACATED BY buildDotnetPackage,g' {} \;
+
+echo Just to be sure, replacing Paket executables by empty files.
+find . -iname paket\*.exe \! -size 0 -exec mv -v {} {}.bak \; -exec touch {} \;
diff --git a/pkgs/build-support/dotnet/dotnetbuildhelpers/remove-duplicated-dlls.sh b/pkgs/build-support/dotnet/dotnetbuildhelpers/remove-duplicated-dlls.sh
new file mode 100644
index 00000000000..d8d29912c8f
--- /dev/null
+++ b/pkgs/build-support/dotnet/dotnetbuildhelpers/remove-duplicated-dlls.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+IFS="
+"
+
+for dll in $(find -iname \*.dll)
+do
+    baseName="$(basename "$dll" | sed "s/.dll$//i")"
+    if pkg-config "$baseName"
+    then
+        candidateDll="$(pkg-config "$baseName" --variable=Libraries)"
+
+        if diff "$dll" "$candidateDll" >/dev/null
+        then
+            echo "$dll is identical to $candidateDll. Substituting..."
+            rm -vf "$dll"
+            ln -sv "$candidateDll" "$dll"
+        else
+            echo "$dll and $candidateDll share the same name but have different contents, leaving alone."
+        fi
+    fi
+done