codesnap: init at 0.8.2 (#364266)
[NixPkgs.git] / pkgs / by-name / av / avalonia / package.nix
blob51b8d41f705b01cacd5a361fe91c00933d7513f7
2   dotnetCorePackages,
3   fetchFromGitHub,
4   fetchNpmDeps,
5   fetchzip,
6   fontconfig,
7   lib,
8   libICE,
9   libSM,
10   libX11,
11   libXcursor,
12   libXext,
13   libXi,
14   libXrandr,
15   liberation_ttf,
16   makeFontsConf,
17   nodejs,
18   npmHooks,
19   runCommand,
20   stdenvNoCC,
23 let
24   inherit (dotnetCorePackages) systemToDotnetRid;
26   dotnet-sdk =
27     with dotnetCorePackages;
28     combinePackages [
29       sdk_7_0_1xx
30       runtime_6_0
31     ];
33   npmDepsFile = ./npm-deps.nix;
36 stdenvNoCC.mkDerivation (
37   finalAttrs:
38   dotnetCorePackages.addNuGetDeps
39     {
40       nugetDeps = ./deps.nix;
41       overrideFetchAttrs = old: rec {
42         runtimeIds = map (system: dotnetCorePackages.systemToDotnetRid system) old.meta.platforms;
43         buildInputs =
44           old.buildInputs
45           ++ lib.concatLists (lib.attrValues (lib.getAttrs runtimeIds dotnet-sdk.targetPackages));
46       };
47     }
48     rec {
49       pname = "Avalonia";
50       version = "11.0.11";
52       src = fetchFromGitHub {
53         owner = "AvaloniaUI";
54         repo = "Avalonia";
55         rev = version;
56         fetchSubmodules = true;
57         hash = "sha256-Du8DEsZKl7rnVH9YZKAWTCpEQ/5HrNlgacgK/46kx/o=";
58       };
60       patches = [
61         # Fix failing tests that use unicode.org
62         ./0001-use-files-for-unicode-character-database.patch
63         # [ERR] Compile: [...]/Microsoft.NET.Sdk.targets(148,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/build/source/src/tools/DevAnalyzers/DevAnalyzers.csproj]
64         # [ERR] Compile: [...]/Microsoft.NET.Sdk.targets(148,5): error MSB4018: System.IO.IOException: The process cannot access the file '/build/source/src/tools/DevAnalyzers/bin/Release/netstandard2.0/DevAnalyzers.deps.json' because it is being used by another process. [/build/source/src/tools/DevAnalyzers/DevAnalyzers.csproj]
65         ./0002-disable-parallel-compile.patch
66       ];
68       # this needs to be match the version being patched above
69       UNICODE_CHARACTER_DATABASE = fetchzip {
70         url = "https://www.unicode.org/Public/15.0.0/ucd/UCD.zip";
71         hash = "sha256-jj6bX46VcnH7vpc9GwM9gArG+hSPbOGL6E4SaVd0s60=";
72         stripRoot = false;
73       };
75       postPatch =
76         ''
77           patchShebangs build.sh
79           substituteInPlace src/Avalonia.X11/ICELib.cs \
80             --replace-fail '"libICE.so.6"' '"${lib.getLib libICE}/lib/libICE.so.6"'
81           substituteInPlace src/Avalonia.X11/SMLib.cs \
82             --replace-fail '"libSM.so.6"' '"${lib.getLib libSM}/lib/libSM.so.6"'
83           substituteInPlace src/Avalonia.X11/XLib.cs \
84             --replace-fail '"libX11.so.6"' '"${lib.getLib libX11}/lib/libX11.so.6"' \
85             --replace-fail '"libXrandr.so.2"' '"${lib.getLib libXrandr}/lib/libXrandr.so.2"' \
86             --replace-fail '"libXext.so.6"' '"${lib.getLib libXext}/lib/libXext.so.6"' \
87             --replace-fail '"libXi.so.6"' '"${lib.getLib libXi}/lib/libXi.so.6"' \
88             --replace-fail '"libXcursor.so.1"' '"${lib.getLib libXcursor}/lib/libXcursor.so.1"'
90           # from RestoreAdditionalProjectSources, which isn't supported by nuget-to-nix
91           dotnet nuget add source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8-transport/nuget/v3/index.json
93           # Tricky way to run npmConfigHook multiple times (borrowed from pagefind)
94           (
95             local postPatchHooks=() # written to by npmConfigHook
96             source ${npmHooks.npmConfigHook}/nix-support/setup-hook
97         ''
98         +
99           # TODO: implement updateScript
100           lib.concatMapStrings (
101             { path, hash }:
102             let
103               deps = fetchNpmDeps {
104                 src = "${src}/${path}";
105                 inherit hash;
106               };
107             in
108             ''
109               npmRoot=${path} npmDeps="${deps}" npmConfigHook
110               rm -rf "$TMPDIR/cache"
111             ''
112           ) (import npmDepsFile)
113         + ''
114           )
115           # Avalonia.Native is normally only packed on darwin.
116           substituteInPlace src/Avalonia.Native/Avalonia.Native.csproj \
117             --replace-fail \
118               '<IsPackable>$(PackAvaloniaNative)</IsPackable>' \
119               '<IsPackable>true</IsPackable>'
120         '';
122       makeCacheWritable = true;
124       # CSC : error CS1566: Error reading resource 'pdbstr.exe' -- 'Could not find a part of the path '/build/.nuget-temp/packages/sourcelink/1.1.0/tools/pdbstr.exe'.' [/build/source/nukebuild/_build.csproj]
125       linkNugetPackages = true;
127       # [WRN] Could not inject value for Build.ApiCompatTool
128       # System.Exception: Missing package reference/download.
129       # Run one of the following commands:
130       #  ---> System.ArgumentException: Could not find package 'Microsoft.DotNet.ApiCompat.Tool' using:
131       #  - Project assets file '/build/source/nukebuild/obj/project.assets.json'
132       #  - NuGet packages config '/build/source/nukebuild/_build.csproj'
133       makeEmptyNupkgInPackages = true;
135       FONTCONFIG_FILE =
136         let
137           fc = makeFontsConf { fontDirectories = [ liberation_ttf ]; };
138         in
139         runCommand "fonts.conf" { } ''
140           substitute ${fc} $out \
141             --replace-fail "/etc/" "${fontconfig.out}/etc/"
142         '';
144       preConfigure = ''
145         # closed source (telemetry?) https://github.com/AvaloniaUI/Avalonia/discussions/16878
146         dotnet remove packages/Avalonia/Avalonia.csproj package Avalonia.BuildServices
147       '';
149       runtimeIds = [ (systemToDotnetRid stdenvNoCC.hostPlatform.system) ];
151       configurePhase = ''
152         runHook preConfigure
153         for project in nukebuild/_build.csproj dirs.proj; do
154           for rid in $runtimeIds; do
155             dotnet restore --runtime "$rid" "$project"
156           done
157         done
158         runHook postConfigure
159       '';
161       nativeBuildInputs = [
162         nodejs
163         dotnet-sdk
164       ];
165       buildInputs = dotnet-sdk.packages;
167       buildTarget = "Package";
169       buildPhase = ''
170         runHook preBuild
171         # ValidateApiDiff requires a network connection
172         ./build.sh --target $buildTarget --verbosity Verbose --skip ValidateApiDiff
173         runHook postBuild
174       '';
176       installPhase = ''
177         runHook preInstall
178         mkdir -p "$out/share/nuget/source"
179         cp artifacts/nuget/* "$out/share/nuget/source"
180         runHook postInstall
181       '';
183       passthru = {
184         updateScript = ./update.bash;
185         inherit npmDepsFile;
186       };
188       meta = {
189         homepage = "https://avaloniaui.net/";
190         license = [ lib.licenses.mit ];
191         maintainers = with lib.maintainers; [ corngood ];
192         description = "A cross-platform UI framework for dotnet";
193         sourceProvenance = with lib.sourceTypes; [
194           fromSource
195           binaryNativeCode # npm dependencies contain binaries
196         ];
197         platforms = dotnet-sdk.meta.platforms;
198         broken = stdenvNoCC.hostPlatform.isDarwin;
199       };
200     }
201     finalAttrs