python312Packages.lightning-utilities: 0.11.9 -> 0.12.0 (#378243)
[NixPkgs.git] / pkgs / build-support / dotnet / build-dotnet-package / default.nix
blob64bf19addb274daee7a86ec364f1b32277844171
2   stdenv,
3   lib,
4   makeWrapper,
5   pkg-config,
6   mono,
7   dotnetbuildhelpers,
8 }:
10 attrsOrig@{
11   pname,
12   version,
13   nativeBuildInputs ? [ ],
14   xBuildFiles ? [ ],
15   xBuildFlags ? [ "/p:Configuration=Release" ],
16   outputFiles ? [ "bin/Release/*" ],
17   dllFiles ? [ "*.dll" ],
18   exeFiles ? [ "*.exe" ],
19   # Additional arguments to pass to the makeWrapper function, which wraps
20   # generated binaries.
21   makeWrapperArgs ? [ ],
22   ...
24 let
25   arrayToShell = (a: toString (map (lib.escape (lib.stringToCharacters "\\ ';$`()|<>\t")) a));
27   attrs = {
28     inherit pname version;
30     nativeBuildInputs = [
31       pkg-config
32       makeWrapper
33       dotnetbuildhelpers
34       mono
35     ] ++ nativeBuildInputs;
37     configurePhase = ''
38       runHook preConfigure
40       [ -z "''${dontPlacateNuget-}" ] && placate-nuget.sh
41       [ -z "''${dontPlacatePaket-}" ] && placate-paket.sh
42       [ -z "''${dontPatchFSharpTargets-}" ] && patch-fsharp-targets.sh
44       runHook postConfigure
45     '';
47     buildPhase = ''
48       runHook preBuild
50       echo Building dotNET packages...
52       # Probably needs to be moved to fsharp
53       if pkg-config FSharp.Core
54       then
55         export FSharpTargetsPath="$(dirname $(pkg-config FSharp.Core --variable=Libraries))/Microsoft.FSharp.Targets"
56       fi
58       ran=""
59       for xBuildFile in ${arrayToShell xBuildFiles} ''${xBuildFilesExtra}
60       do
61         ran="yes"
62         xbuild ${arrayToShell xBuildFlags} ''${xBuildFlagsArray} $xBuildFile
63       done
65       [ -z "$ran" ] && xbuild ${arrayToShell xBuildFlags} ''${xBuildFlagsArray}
67       runHook postBuild
68     '';
70     dontStrip = true;
72     installPhase = ''
73       runHook preInstall
75       target="$out/lib/dotnet/${pname}"
76       mkdir -p "$target"
78       cp -rv ${arrayToShell outputFiles} "''${outputFilesArray[@]}" "$target"
80       if [ -z "''${dontRemoveDuplicatedDlls-}" ]
81       then
82         pushd "$out"
83         remove-duplicated-dlls.sh
84         popd
85       fi
87       set -f
88       for dllPattern in ${arrayToShell dllFiles} ''${dllFilesArray[@]}
89       do
90         set +f
91         for dll in "$target"/$dllPattern
92         do
93           [ -f "$dll" ] || continue
94           if pkg-config $(basename -s .dll "$dll")
95           then
96             echo "$dll already exported by a buildInputs, not re-exporting"
97           else
98             create-pkg-config-for-dll.sh "$out/lib/pkgconfig" "$dll"
99           fi
100         done
101       done
103       set -f
104       for exePattern in ${arrayToShell exeFiles} ''${exeFilesArray[@]}
105       do
106         set +f
107         for exe in "$target"/$exePattern
108         do
109           [ -f "$exe" ] || continue
110           mkdir -p "$out"/bin
111           commandName="$(basename -s .exe "$(echo "$exe" | tr "[A-Z]" "[a-z]")")"
112           makeWrapper \
113             "${mono}/bin/mono" \
114             "$out"/bin/"$commandName" \
115             --add-flags "\"$exe\"" \
116             ''${makeWrapperArgs}
117         done
118       done
120       runHook postInstall
121     '';
122   };
124 stdenv.mkDerivation (attrs // (builtins.removeAttrs attrsOrig [ "nativeBuildInputs" ]))