-
Notifications
You must be signed in to change notification settings - Fork 60
Description
When building an executable the native AOT compiler, Yubico.NativeShims.dll is output next to the executable instead of being trimmed away. There are also no compiler warnings about dependencies having trimming issues, which is odd. But I suspect it has to do with native shims being pre-built/native or shared vs static, it's not IL. It probably needs to be IL or static, or maybe static with a p/invoke wrapper class, in order for trimming to work (not sure haven't done one of these myself before).
Expected output
single executable with no libraries around it
What's actually happening
Yubico.NativeShims.dll in the output dir.
Steps to reproduce
dotnet new consoledotnet add package Yubico.YubiKey- Add
<PublishAot>true</PublishAot>to the project file dotnet publish -o ./out
Sample with expected output
Instead of adding the YubiKey reference add one to Newtonsoft.Json
You should get a ton of warnings about trimming, but the output is as expected absent of any Newtonsoft libs.
Why do I want this?
if you take a peek at my latest builds: https://github.com/SheepReaper/yk-csr-generator/releases/tag/v1.0.0 I'm building 80MB assemblies because of the runtime bits included. Granted, if I didn't do single file, it would be way smaller, but then the user needs to have a runtime installed. I just want to build a single executable with no external dependencies, so I'm fine with the bloat.
However, in testing AOT builds, I was able to achieve a 1.5KB binary plus the Shim lib next to it with almost 3KB. Which is super nice, but we're back at the original problem of external dependencies.
Additional references
- native static library: https://github.com/dotnet/samples/blob/main/core/nativeaot/NativeLibrary/README.md
- aot compatible library limitations: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/aot/native-aot-tutorial?view=aspnetcore-8.0&tabs=netcore-cli#libraries-and-native-aot
- declaring your libs to be aot compatible enables the aot-compatibility analyzers (compiler warnings): https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/?tabs=net8plus%2Cwindows#aot-compatibility-analyzers
- preparing libs for AOT: https://aka.ms/dotnet-illink/libraries
I don't know enough about the Shims lib to determine what about it is preventing AOT from working nicely, but worst case it's hitting one of the many limitations of AOT compatibility, which might be too much work to overcome. In which case, I'll be sticking to my thicc binaries...