core/pkgs/build-support/dotnet/build-dotnet-package/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
3 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{
stdenv,
lib,
makeWrapper,
pkg-config,
mono,
dotnetbuildhelpers,
}:
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
attrsOrig@{
pname,
version,
nativeBuildInputs ? [ ],
xBuildFiles ? [ ],
xBuildFlags ? [ "/p:Configuration=Release" ],
outputFiles ? [ "bin/Release/*" ],
dllFiles ? [ "*.dll" ],
exeFiles ? [ "*.exe" ],
# Additional arguments to pass to the makeWrapper function, which wraps
# generated binaries.
makeWrapperArgs ? [ ],
...
}:
let
arrayToShell = (a: toString (map (lib.escape (lib.stringToCharacters "\\ ';$`()|<>\t")) a));
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
attrs = {
inherit pname version;
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
nativeBuildInputs = [
pkg-config
makeWrapper
dotnetbuildhelpers
mono
] ++ nativeBuildInputs;
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
configurePhase = ''
runHook preConfigure
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
[ -z "''${dontPlacateNuget-}" ] && placate-nuget.sh
[ -z "''${dontPlacatePaket-}" ] && placate-paket.sh
[ -z "''${dontPatchFSharpTargets-}" ] && patch-fsharp-targets.sh
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
runHook postConfigure
2024-06-30 08:12:46 +00:00
'';
2024-05-02 00:46:19 +00:00
buildPhase = ''
runHook preBuild
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
echo Building dotNET packages...
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
# Probably needs to be moved to fsharp
if pkg-config FSharp.Core
2024-06-30 08:12:46 +00:00
then
2024-05-02 00:46:19 +00:00
export FSharpTargetsPath="$(dirname $(pkg-config FSharp.Core --variable=Libraries))/Microsoft.FSharp.Targets"
2024-06-30 08:12:46 +00:00
fi
ran=""
2024-05-02 00:46:19 +00:00
for xBuildFile in ${arrayToShell xBuildFiles} ''${xBuildFilesExtra}
2024-06-30 08:12:46 +00:00
do
2024-05-02 00:46:19 +00:00
ran="yes"
xbuild ${arrayToShell xBuildFlags} ''${xBuildFlagsArray} $xBuildFile
2024-06-30 08:12:46 +00:00
done
2024-05-02 00:46:19 +00:00
[ -z "$ran" ] && xbuild ${arrayToShell xBuildFlags} ''${xBuildFlagsArray}
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
runHook postBuild
2024-06-30 08:12:46 +00:00
'';
2024-05-02 00:46:19 +00:00
dontStrip = true;
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
installPhase = ''
runHook preInstall
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
target="$out/lib/dotnet/${pname}"
mkdir -p "$target"
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
cp -rv ${arrayToShell outputFiles} "''${outputFilesArray[@]}" "$target"
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
if [ -z "''${dontRemoveDuplicatedDlls-}" ]
then
pushd "$out"
remove-duplicated-dlls.sh
popd
fi
2024-06-30 08:12:46 +00:00
2024-05-02 00:46:19 +00:00
set -f
for dllPattern in ${arrayToShell dllFiles} ''${dllFilesArray[@]}
2024-06-30 08:12:46 +00:00
do
set +f
2024-05-02 00:46:19 +00:00
for dll in "$target"/$dllPattern
do
[ -f "$dll" ] || continue
if pkg-config $(basename -s .dll "$dll")
then
echo "$dll already exported by a buildInputs, not re-exporting"
else
create-pkg-config-for-dll.sh "$out/lib/pkgconfig" "$dll"
2024-06-30 08:12:46 +00:00
fi
2024-05-02 00:46:19 +00:00
done
2024-06-30 08:12:46 +00:00
done
2024-05-02 00:46:19 +00:00
set -f
for exePattern in ${arrayToShell exeFiles} ''${exeFilesArray[@]}
do
set +f
for exe in "$target"/$exePattern
do
[ -f "$exe" ] || continue
mkdir -p "$out"/bin
commandName="$(basename -s .exe "$(echo "$exe" | tr "[A-Z]" "[a-z]")")"
makeWrapper \
"${mono}/bin/mono" \
"$out"/bin/"$commandName" \
--add-flags "\"$exe\"" \
''${makeWrapperArgs}
done
2024-06-30 08:12:46 +00:00
done
2024-05-02 00:46:19 +00:00
runHook postInstall
'';
};
in
stdenv.mkDerivation (attrs // (builtins.removeAttrs attrsOrig [ "nativeBuildInputs" ]))