-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Add support for NativeAOT #1047
Comments
The current dll loader implementation is not compatible with NativeAOT. peachpie/src/Peachpie.Runtime/Context.cs Line 105 in 8041b35
|
thanks; do you know how to fix that? Is there an attribute we should add to functions and classes so it won't be removed by AOT compilation? |
As a workaround, you may add some never reached code to call PhpExtension Registrator constructors in the extension static constructor to make sure they won't be trimmed. Taking peachpie/src/Peachpie.Library/zlib.cs Line 21 in 8041b35
You can add a static constructor to Zlib public static class Zlib
{
static Zlib()
{
if (DateTime.Now.Day == 33) // should not be compile-time evaluatable so the branch won't be removed
{
new Registrator();
}
}
} Another take is to use ILLinker attributes such as See https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming#dynamicallyaccessedmembers, and https://github.com/dotnet/linker/blob/main/docs/data-formats.md#descriptor-format. I would like to tag @MichalStrehovsky for some help. |
@hez2010 |
@hez2010 seems we can just embed |
ILLink.Descriptors.xml are not yet implemented in NativeAOT. Only That said, ILLink.Descriptors.xml are a subpar solution in general. The trimming process analyzes the reflection patterns within the app. If it can reason about them statically, it makes sure not to remove things that would break the reflection pattern found in the app. If the reflection cannot be reasoned about statically, trimming generates a warning that the user can see. If you use ILLink.Descriptors.xml, there will still be a warning at the use site that you need to suppress - otherwise the library will be reported as trimming-unfriendly. The suppression means that you're now responsible to make sure the code and ILLink.Descriptors match (i.e. you're not reflecting on more stuff without updating ILLink.Descriptors, etc.). Trimming is very hard to unit test because the act of embedding the code in a unit test framework changes the things that can be trimmed. Suppressing trimming warnings is a potential maintenance and reliability nightmare. ILLink.Descriptors also root things unconditionally - even if the code that uses the thing you rooted in Descriptors got trimmed away, the thing rooted in descriptors will stay (trimming doesn't know what code the Descriptors entry is associated with). They limit how well the app can be trimmed. If you're using custom attributes for discovery, could you use custom attributes to encode the reachable types? E.g.: public sealed class TypeConverterAttribute : Attribute
{
public TypeConverterAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.DefaultConstructor)] Type type)
{
ConverterType = type;
}
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.DefaultConstructor)]
public Type ConverterType { get; }
} The Whenever trimming sees this attribute, it will make sure to keep the constructor on the When you access the One can use DynamicallyAccessedMembers to annotate various System.Type instances reflected on at runtime this way. |
I try dontet 8.0 with PeachPie in Macos ARM, same errors occured. |
Add support for NativeAOT as NativeAOT will be present as part of .NET 7.0.
The NativeAOT ahead-of-time (AOT) toolchain can compile .NET application into a native (architecture specific) single-file executable. It can also produce standalone dynamic or static libraries that can be consumed by applications written in other programming languages.
In I intend to use libraries made with C# in Flutter/dart/ffi/rust projects
https://github.com/dotnet/runtimelab/tree/feature/NativeAOT
The text was updated successfully, but these errors were encountered: