AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.22k stars 2.18k forks source link

make use of nativeaot static linking feature #9503

Open ivanjx opened 1 year ago

ivanjx commented 1 year ago

Is your feature request related to a problem? Please describe. it is now possible to static link native libraries inside the main binary so it should be possible to do that to the 2 native dlls from avalonia's native aot output, namely libHarfBuzzSharp.dll and libSkiaSharp.dll.

Describe the solution you'd like include the static library files of those 2 dlls instead and use DirectPInvoke and NativeLibrary.

Additional context https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/interop.md#linking

maxkatz6 commented 1 year ago

It should be optional, as it works only with native AOT. I suppose ideal plan would be something like:

ivanjx commented 1 year ago

no need for another static linking configuration in the csproj. DirectPInvoke and NativeLibrary is smart enough to ignore themselves if it is not being published. native aot will only kick in dotnet publish command.

ivanjx commented 1 year ago

@maxkatz6 are there any static library files .lib for those 2 dlls? if there arent how to create one? thanks

maxkatz6 commented 1 year ago

you will need to look for them here, possibly compile Skia manually https://github.com/mono/SkiaSharp

danielmayost commented 1 year ago

Is there a workaround to achieve this?

My software is distributed as singlefile, it is quite impractical to use AOT when 3 more dlls are added on the side.

maxkatz6 commented 1 year ago

For the SingleFile deployment it's possible to include native dependencies: https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli#include-native-libraries

I don't think it's applicable for the NativeAOT, that's more a question to the .NET runtime team.

danielmayost commented 1 year ago

For the SingleFile deployment it's possible to include native dependencies: https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli#include-native-libraries

yes, i know, meant for NativeAOT.

I don't think it's applicable for the NativeAOT, that's more a question to the .NET runtime team.

it's not works.

ivanjx commented 1 year ago

deploying native aot avalonia apps is possible with single exe as long as you have the static libs mentioned above. i have compiled those and works fine

danielmayost commented 1 year ago

@ivanjx static lib, Where did you get them? So you successfully create a single AOT file?

ivanjx commented 1 year ago

@danielmayost yes. you need to compile skia and harfbuzz urself. my hands are full right now so cant explain the details but u can search on how to do those.

ivanjx commented 1 year ago

here is my compiled required libs for avalonia on windows x64 platform if anyone is interested. https://mega.nz/file/z34V3bSZ#boItQx_nLBRGu-biDL3PbKSSG_Ti87JL7KNY7qz2Li8

ivanjx commented 1 year ago

you can build skia for other platforms if you look inside the cake files. here is the ones for windows that i use as reference: https://github.com/mono/SkiaSharp/blob/main/native/windows/build.cake

for harfbuzz you can use this and open in visual studio. there is some settings to change to enable static build but i forgot which: https://github.com/mono/SkiaSharp/tree/main/native/windows/libHarfBuzzSharp

reference about the build commands: https://github.com/mono/SkiaSharp/wiki/Building-on-Linux

Cubody commented 1 year ago

@ivanjx I downloaded your x64 win native libs and wrote static linking in .csproj:

    <ItemGroup>
        <DirectPInvoke Include="libHarfBuzzSharp" />
        <NativeLibrary Include="native\libHarfBuzzSharp.lib" Condition="$(RuntimeIdentifier.StartsWith('win'))" />
        <DirectPInvoke Include="libSkiaSharp" />
        <NativeLibrary Include="native\libSkiaSharp.lib" Condition="$(RuntimeIdentifier.StartsWith('win'))" />
    </ItemGroup>

But I'm getting strange errors that I can't understand. Can you help me?

libHarfBuzzSharp.lib(hb-face.obj) : found .netmodule MSIL or a module compiled with the /GL parameter; the layout is restarted with the /LTCG parameter; add /LTCG to the command line of the layout to improve the performance of the linker
EXEC : fatal error C1900: IL mismatch between "P1", version "20220715" and "P2", version "20220421"
LINK : fatal error LNK1257: failed to generate code
C:\Users\green\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.0-preview.1.23110.8\build\Microsoft.NETCore.Native.targets(354,5): error MSB3073: exiting the "" commandC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\
MSVC\14.33.31629\bin\Hostx64\x64\link.exe " @"obj\Release\net8.0\win-x64\native\link.rsp"" with code 1257.
ivanjx commented 1 year ago

@Cubody i only tested this with net 7.0. maybe try to use that. or you can try to build the static libs with your current visual studio installation.

Cubody commented 1 year ago

@ivanjx I also tried with .NET 7.0, but SDK is 8.0. I will be very grateful if you can enlighten a little more in compiling native libraries, because I have never met with this before. The feeling is that the error says that the nuget package(both Skia and second) is a different version instead of that's natives. I am using Avalonia 11 preview 5.

I'm also using Rider and can not download Visual Studio due to stupid region restriction :/

ivanjx commented 1 year ago

i believe avalonia version is not the problem here as i am using nightly. try the 7.0 sdk

ivanjx commented 1 year ago

for compiling without visual studio i dont think it is possible as the compilers came from the visual studio installation. maybe you can install the compilers manually but idk how

Cubody commented 1 year ago

SDK 7.0 didn't help me =( I will try to install VS, but how to compile natives? Can you provide full instruction for these two libraries if it's not hard for you? I think I can deal with .cake if I'll read docs but it's not clear about HarfBuzzSharp.

ivanjx commented 1 year ago

in general this is what you have to do at first:

  1. install LLVM
  2. clone https://github.com/mono/SkiaSharp
  3. git submodule update --init --recursive
  4. cd externals\skia
  5. python .\tools\git-sync-deps

with skiasharp, you can follow these commands with a few adjustments (it has been a while but it is very similar). for the args required it is all mentioned in the .cake file for windows.

with harfbuzzsharp it is actually a lot easier. just need to open the .sln file inside the folder, re-target to latest if prompted, change the configuration type to static library, then build with Release configuration.

image

in your case @Cubody, i think the problem is only with the harfbuzz static library. so hopefully you can just build that yourself without rebuilding the skiasharp.

ivanjx commented 1 year ago

so here is the full command that i use for compiling skiasharp

  1. ..\depot_tools\gn gen 'out/windows/x64' --args='target_os=\"win\" target_cpu=\"x64\" is_static_skiasharp=true skia_enable_fontmgr_win_gdi=false skia_use_dng_sdk=true skia_use_icu=false skia_use_piex=true skia_use_sfntly=false skia_use_system_expat=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false skia_enable_skottie=true skia_use_vulkan=true skia_enable_gpu=true clang_win=\"C:\Program Files\LLVM\" extra_cflags=[ \"-DSKIA_C_DLL\", \"/MT\", \"/EHsc\", \"/Z7\", \"-D_HAS_AUTO_PTR_ETC=1\" ]'
  2. ..\depot_tools\ninja 'SkiaSharp' -C 'out/windows/x64'
  3. open developer powershell for vs 2022. change directory to externals\skia\out\windows\x64
  4. lib.exe /OUT:libSkiaSharp.lib *.lib

the first 2 commands are run inside the externals\skia folder. beware that the 2nd command will use a lot of your cpu!

note: if you encounter issues when running gn, go inside your python installation path, copy python.exe into python3.exe

Cubody commented 1 year ago

@ivanjx Thanks a lot! I'll try it.

Cubody commented 1 year ago

I just tried one more time with your libs and it works as expected! I deleted all .NET packages and installed just .NET 8 preview. Now it's fine.

KieranDevvs commented 1 year ago

Its not clear to me where the issue lies, which one(s) of the following is making this occour?

A) SkiaSharp & HarfBuzzSharp don't package static libraries in their NuGet packages so there's nothing to statically link. B) The NativeAOT compilation process in .NET doesn't support automatically statically linking 3rd party libs. C) Both A & B are false and something else is blocking it from building a true published single executable

While its nice that there's a work around of building your own static libraries and configuring your project to use it, I don't consider that to be a fix for the problem. The goal should be that it works out of the box.

danielmayost commented 1 year ago

If I understand correctly A is the problem. It's really frustrating not being able to publish a single AOT file, try as I might, I couldn't build SkiaSharp by myself.

ivanjx commented 1 year ago

i think including the static lib in the nuget wont be ideal for skiasharp as it is very big even for a single platform. imagine adding other platforms as well.

KieranDevvs commented 1 year ago

i think including the static lib in the nuget wont be ideal for skiasharp as it is very big even for a single platform. imagine adding other platforms as well.

It doesn't have to be in the same NuGet package, they can split it out into:

And then end users can configure their projects to include the relevant packages for specific builds i.e

<ItemGroup>
    <PackageReference Include="SkiaSharp.x64Linux.Static" Condition="$(TargetPlatform) = '...'" />
</ItemGroup>
danielmayost commented 1 year ago

Maybe someone would be so kind as to share the static libraries they managed to create (av_libglesv2 and libSkiaSharp) for the benefit of those who haven't managed to do it yet.

ivanjx commented 1 year ago

@danielmayost do you have any issues compiling the native libraries by yourself? please try follow this https://github.com/AvaloniaUI/Avalonia/issues/9503#issuecomment-1474233516

danielmayost commented 1 year ago

I have a problem with the command:

python .\tools\git-sync-deps

probably because of a censored internet problem I'm having.

ivanjx commented 1 year ago

@danielmayost have you tried this https://github.com/AvaloniaUI/Avalonia/issues/9503#issuecomment-1435511465

danielmayost commented 1 year ago

Unfortunately that doesn't work for me either. Links from GitHub itself work.

Edit: thank, i downloaded your libs, and it's works.

MichalStrehovsky commented 1 year ago

If you see found .netmodule MSIL or a module compiled with the /GL parameter; the layout is restarted with the /LTCG parameter that means that something in the LIB was compiled with the /GL parameter passed to the C++ compiler ("Whole program optimization"). Whole program C++ optimizations require that all the LIB files, link.exe, etc. have a matching version. You'd need to match the version of the C++ compiler used to compile the native parts of the .NET runtime. That might work sometimes, but fail other times. The fix is to not pass /GL when building your LIB.

ivanjx commented 1 year ago

@MichalStrehovsky if it works on compile time with wont crash on runtime correct? thank you for the info.

danielmayost commented 1 year ago

@ivanjx I finally succeeded to compile SkiaSharp (according to the commands you wrote), the final file I received is about 1GB and in the files you sent it is about 400MB, do you have any idea?

ivanjx commented 1 year ago

@danielmayost you dont have to worry about the lib size since you dont have to ship it with your application. in my case the output exe is only around 60 MB.

my latest output size of the lib file is also 1 GB. maybe there are some differences between the linker command i used the first time with what i wrote here. forgot what i used the first time.

edit: i got ~400MB size because i use LLVM.

ivanjx commented 10 months ago

updated build steps for windows

requirements:

libSkiaSharp:

  1. git clone https://github.com/mono/SkiaSharp.git
  2. git checkout release/2.88.6 (or pick according the skiasharp version in the nuget list)
  3. git submodule update --init --recursive
  4. cd external/skia
  5. python .\tools\git-sync-deps
  6. python ..\depot_tools\gn.py args .\out\windows\x64\ this is what i put (according to this)
    target_os="win"
    target_cpu="x64"
    is_static_skiasharp=true
    skia_enable_fontmgr_win_gdi=false
    skia_use_dng_sdk=true
    skia_use_icu=false
    skia_use_piex=true
    skia_use_sfntly=false
    skia_use_system_expat=false
    skia_use_system_libjpeg_turbo=false
    skia_use_system_libpng=false
    skia_use_system_libwebp=false
    skia_use_system_zlib=false
    skia_use_vulkan=true
    skia_use_angle=true
    skia_enable_skottie=true
    skia_enable_gpu=true
    clang_win="C:\Program Files\LLVM"    <<=== REMOVE IF YOU DONT HAVE LLVM
    extra_cflags=[ "-DSKIA_C_DLL", "/MT", "/EHsc", "/Z7", "-D_HAS_AUTO_PTR_ETC=1" ]
  7. ..\depot_tools\ninja -C .\out\windows\x64\ SkiaSharp
  8. cd .\out\windows\x64\
  9. lib.exe /OUT:libSkiaSharp.lib *.lib

note:

libHarfBuzzSharp

peaceshi commented 9 months ago

I have created two github actions to build these static libs.

libSkiaSharp and libHarfBuzzSharp https://github.com/2ndlab/SkiaSharp.Static

ANGLE static https://github.com/2ndlab/ANGLE.Static

Cubody commented 9 months ago

@peaceshi

Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering.

I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj

To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash.

Also Avalonia uses it's own fork of ANGLE with some fixes.

peaceshi commented 9 months ago

@peaceshi

Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering.

I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj

To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash.

Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Cubody commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

peaceshi commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

Cubody commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

I mean if I'll build just angle it'll not work because .dll itself uses many functions from other libs that angle bulk builds.

peaceshi commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

I mean if I'll build just angle it'll not work because .dll itself uses many functions from other libs that angle bulk builds.

No. I think it is just a static lib bug of ANGLE.

Cubody commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

I mean if I'll build just angle it'll not work because .dll itself uses many functions from other libs that angle bulk builds.

No. I think it is just a static lib bug of ANGLE.

Here is old thread about static lib https://groups.google.com/g/angleproject/c/xKmUgKZFpgY

peaceshi commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

I mean if I'll build just angle it'll not work because .dll itself uses many functions from other libs that angle bulk builds.

No. I think it is just a static lib bug of ANGLE.

Here is old thread about static lib https://groups.google.com/g/angleproject/c/xKmUgKZFpgY

I have linked all missing symbols. It is working now. Download av_libglesv2.7z from https://github.com/2ndlab/ANGLE.Static/releases

Cubody commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

I mean if I'll build just angle it'll not work because .dll itself uses many functions from other libs that angle bulk builds.

No. I think it is just a static lib bug of ANGLE.

Here is old thread about static lib https://groups.google.com/g/angleproject/c/xKmUgKZFpgY

I have linked all missing symbols. It is working now. Download av_libglesv2.7z from https://github.com/2ndlab/ANGLE.Static/releases

Nice work, appreciate it! Can you add these instructions to pipeline? It'll be easier for Avalonia to make its own Nuget.

Also I want to ask, is here any way to make my application size smaller? (I'm using some compilation flags) Now it's 70mb.

 <PropertyGroup>
        <IlcOptimizationPreference>Size</IlcOptimizationPreference>
        <AutoreleasePoolSupport>false</AutoreleasePoolSupport>
        <EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
        <EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
        <EventSourceSupport>false</EventSourceSupport>
        <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
        <MetadataUpdaterSupport>false</MetadataUpdaterSupport>
        <UseSystemResourceKeys>true</UseSystemResourceKeys>
        <IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
        <IlcTrimMetadata>true</IlcTrimMetadata>
        <!-- <IlcDisableReflection>true</IlcDisableReflection> -->
        <IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
    </PropertyGroup>

    <PropertyGroup>
        <!--These can help when debugging weird exceptions especially when reflection is involved. See https://github.com/dotnet/corert/blob/master/Documentation/using-corert/optimizing-corert.md -->
        <!--RootAllApplicationAssemblies: False -> TrimMode:link See https://github.com/dotnet/runtimelab/issues/597 and https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/optimizing.md -->
        <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
        <IlcDisableUnhandledExceptionExperience>true</IlcDisableUnhandledExceptionExperience>
    </PropertyGroup>
peaceshi commented 9 months ago

@peaceshi Have you made Avalonia single file native aot to work with static ANGLE? It doesn't work for me. I have a black background instead of transparent - the Avalonia UI uses software rendering. I made <NativeLibrary Include="Native\av_libglesv2.lib" /> in csproj To undestand if it works or no you can add options to Build app:

BuildAvaloniaApp()
                .With(new Win32PlatformOptions
                    {RenderingMode = new[] {Win32RenderingMode.AngleEgl}})
                .StartWithClassicDesktopLifetime(args);

If it'll not find ANGLE lib it'll crash. Also Avalonia uses it's own fork of ANGLE with some fixes.

You can try to build this for yourself. https://github.com/AvaloniaUI/angle/tree/avalonia-fork-master

Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. Thats why Katz says that it's main problem to build angle as static library with all needable dependencies.

Emm, what is the all needable dependencies? Can you explain it further?

I mean if I'll build just angle it'll not work because .dll itself uses many functions from other libs that angle bulk builds.

No. I think it is just a static lib bug of ANGLE.

Here is old thread about static lib https://groups.google.com/g/angleproject/c/xKmUgKZFpgY

I have linked all missing symbols. It is working now. Download av_libglesv2.7z from https://github.com/2ndlab/ANGLE.Static/releases

Nice work, appreciate it! Can you add these instructions to pipeline? It'll be easier for Avalonia to make its own Nuget.

Also I want to ask, is here any way to make my application size smaller? (I'm using some compilation flags) Now it's 70mb.

 <PropertyGroup>
        <IlcOptimizationPreference>Size</IlcOptimizationPreference>
        <AutoreleasePoolSupport>false</AutoreleasePoolSupport>
        <EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
        <EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
        <EventSourceSupport>false</EventSourceSupport>
        <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
        <MetadataUpdaterSupport>false</MetadataUpdaterSupport>
        <UseSystemResourceKeys>true</UseSystemResourceKeys>
        <IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
        <IlcTrimMetadata>true</IlcTrimMetadata>
        <!-- <IlcDisableReflection>true</IlcDisableReflection> -->
        <IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
    </PropertyGroup>

    <PropertyGroup>
        <!--These can help when debugging weird exceptions especially when reflection is involved. See https://github.com/dotnet/corert/blob/master/Documentation/using-corert/optimizing-corert.md -->
        <!--RootAllApplicationAssemblies: False -> TrimMode:link See https://github.com/dotnet/runtimelab/issues/597 and https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/optimizing.md -->
        <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
        <IlcDisableUnhandledExceptionExperience>true</IlcDisableUnhandledExceptionExperience>
    </PropertyGroup>

I will add these files to actions later. About the file size, you can use upx or sfx to compress it. But for the build trimming, all we can do is wait for .NET team creating a better trimming or other optimizations.

peaceshi commented 9 months ago

https://github.com/2ndlab/ANGLE.Static/releases/tag/v1.1.0

Everything works well now.

NCLnclNCL commented 9 months ago

Good

amakvana commented 7 months ago

@ivanjx sorry to piggyback off this. I've download all 3 .libs: av_libglesv2.lib, libHarfBuzzSharp.lib and libSkiaSharp.lib. Imported them into my project and referenced them inside the .csproj. However, when Publishing, the 3 .dll files still get copied over.

Any idea what I am doing wrong? Cheers