-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make use of nativeaot static linking feature #9503
Comments
It should be optional, as it works only with native AOT.
|
no need for another static linking configuration in the csproj. |
@maxkatz6 are there any static library files |
you will need to look for them here, possibly compile Skia manually |
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. |
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. |
yes, i know, meant for NativeAOT.
it's not works. |
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 |
@ivanjx static lib, Where did you get them? So you successfully create a single AOT file? |
@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. |
here is my compiled required libs for avalonia on windows x64 platform if anyone is interested. |
you can build skia for other platforms if you look inside the 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 |
@ivanjx <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?
|
@Cubody |
@ivanjx I'm also using Rider and can not download Visual Studio due to stupid region restriction :/ |
i believe avalonia version is not the problem here as i am using nightly. |
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 |
SDK 7.0 didn't help me =( |
in general this is what you have to do at first:
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 with harfbuzzsharp it is actually a lot easier. just need to open the 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. |
so here is the full command that i use for compiling skiasharp
the first 2 commands are run inside the note: if you encounter issues when running |
@ivanjx Thanks a lot! I'll try it. |
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. |
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. 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. |
If I understand correctly A is the problem. |
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> |
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. |
@danielmayost do you have any issues compiling the native libraries by yourself? please try follow this #9503 (comment) |
If you see |
@MichalStrehovsky if it works on compile time with wont crash on runtime correct? thank you for the info. |
@ivanjx I finally succeeded to compile |
@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: |
updated build steps for windows requirements:
note:
|
I have created two github actions to build these static libs. libSkiaSharp and libHarfBuzzSharp ANGLE static |
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 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. |
Btw have you made Avalonia single file native aot to work with this? I already built but it doesn't help. |
Emm, what is the |
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 |
I have linked all missing symbols. It is working now. |
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. |
https://github.com/2ndlab/ANGLE.Static/releases/tag/v1.1.0 Everything works well now. |
Good |
@ivanjx sorry to piggyback off this. I've download all 3 .libs: Any idea what I am doing wrong? Cheers |
If libs were successfully statically linked into your executable, you can safely delete remaining dll files. |
@peaceshi I'm assuming that all ibs must be compiled at the specific platform to have the same outcome. Can you add Linux/macOS versions of those libs? |
From #8130 (reply in thread). |
you can patch it manually by yourself just be like vcpkg done. |
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
andlibSkiaSharp.dll
.Describe the solution you'd like
include the static library files of those 2 dlls instead and use
DirectPInvoke
andNativeLibrary
.Additional context
https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/docs/using-nativeaot/interop.md#linking
The text was updated successfully, but these errors were encountered: