peachpie
peachpie copied to clipboard
Add support for NativeAOT
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
PS C:\MyCsharpProjects\fsbackup2> dotnet add package Microsoft.DotNet.ILCompiler -v 7.0.0-*
Determinando os projetos a serem restaurados...
Writing C:\Users\isaque\AppData\Local\Temp\tmp22FB.tmp
info : Adicionando PackageReference do pacote 'Microsoft.DotNet.ILCompiler' ao projeto 'C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj'.
info : Restaurando pacotes para C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj...
info : GET https://api.nuget.org/v3-flatcontainer/microsoft.dotnet.ilcompiler/index.json
info : OK https://api.nuget.org/v3-flatcontainer/microsoft.dotnet.ilcompiler/index.json 687 ms
info : O pacote 'Microsoft.DotNet.ILCompiler' é compatível com todas as estruturas especificadas no projeto 'C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj'.
info : PackageReference do pacote 'Microsoft.DotNet.ILCompiler' versão '7.0.0-*' adicionada ao arquivo 'C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj'.
info : Gerando arquivo do MSBuild C:\MyCsharpProjects\fsbackup2\obj\fsbackup2.msbuildproj.nuget.g.props.
info : Gerando arquivo do MSBuild C:\MyCsharpProjects\fsbackup2\obj\fsbackup2.msbuildproj.nuget.g.targets.
info : Gravando o arquivo de ativos no disco. Caminho: C:\MyCsharpProjects\fsbackup2\obj\project.assets.json
log : C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj restaurado (em 1,06 sec).
PS C:\MyCsharpProjects\fsbackup2> dotnet publish -r win-x64 -c Release
Microsoft(R) Build Engine versão 17.2.0-preview-22152-03+719247ede para .NET
Copyright (C) Microsoft Corporation. Todos os direitos reservados.
Determinando os projetos a serem restaurados...
C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj restaurado (em 40,67 sec).
Você está usando uma versão prévia do .NET. Confira: https://aka.ms/dotnet-support-policy
PeachPie PHP Compiler version 1.0.9+fd461dcb004df7d84be53252c300c4d882b81efd
fsbackup2 -> C:\MyCsharpProjects\fsbackup2\bin\Release\net5.0\win-x64\fsbackup2.dll
Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
Generating compatible native code. To optimize for size or speed, visit https://aka.ms/OptimizeCoreRT
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\sdk\System.Private.CoreLib.dll : warning IL3053: Assembly 'System.Private.CoreLib' produced AOT analysis warnings. [C:\MyCsharpProjects\
fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\Microsoft.CSharp.dll : warning IL3053: Assembly 'Microsoft.CSharp' produced AOT analysis warnings. [C:\MyCsharpProjects\fsback
up2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\Microsoft.VisualBasic.Core.dll : warning IL3053: Assembly 'Microsoft.VisualBasic.Core' produced AOT analysis warnings. [C:\MyC
sharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Linq.Queryable.dll : warning IL3053: Assembly 'System.Linq.Queryable' produced AOT analysis warnings. [C:\MyCsharpProje
cts\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Private.DataContractSerialization.dll : warning IL3053: Assembly 'System.Private.DataContractSerialization' produced AO
T analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Reflection.DispatchProxy.dll : warning IL3053: Assembly 'System.Reflection.DispatchProxy' produced AOT analysis warning
s. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Runtime.Serialization.Formatters.dll : warning IL3053: Assembly 'System.Runtime.Serialization.Formatters' produced AOT
analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\htmlagilitypack\1.11.25\lib\netstandard2.0\HtmlAgilityPack.dll : warning IL3053: Assembly 'HtmlAgilityPack' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\microsoft.applicationinsights\2.10.0\lib\netstandard2.0\Microsoft.ApplicationInsights.dll : warning IL3053: Assembly 'Microsoft.ApplicationInsights' produced AOT analysis warnings. [C:\MyCsharpProjects\fs
backup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\mono.posix.netstandard\1.0.0\runtimes\win-x64\lib\netstandard2.0\Mono.Posix.NETStandard.dll : warning IL3053: Assembly 'Mono.Posix.NETStandard' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbacku
p2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\peachpie.library\1.0.9\lib\netstandard2.0\Peachpie.Library.dll : warning IL3053: Assembly 'Peachpie.Library' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Net.Quic.dll : warning IL3053: Assembly 'System.Net.Quic' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup
2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Text.Json.dll : warning IL3053: Assembly 'System.Text.Json' produced AOT analysis warnings. [C:\MyCsharpProjects\fsback
up2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\peachpie.microsoft.codeanalysis\3.7.1\lib\netstandard2.0\Peachpie.Microsoft.CodeAnalysis.dll : warning IL3053: Assembly 'Peachpie.Microsoft.CodeAnalysis' produced AOT analysis warnings. [C:\MyCsharpProjec
ts\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\peachpie.runtime\1.0.9\lib\netstandard2.0\Peachpie.Runtime.dll : warning IL3053: Assembly 'Peachpie.Runtime' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Linq.Expressions.dll : warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings. [C:\MyCsharpP
rojects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\sixlabors.imagesharp\1.0.0\lib\netcoreapp3.1\SixLabors.ImageSharp.dll : warning IL3053: Assembly 'SixLabors.ImageSharp' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj
]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Diagnostics.DiagnosticSource.dll : warning IL3053: Assembly 'System.Diagnostics.DiagnosticSource' produced AOT analysis
warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\system.data.sqlclient\4.6.0\runtimes\win\lib\netcoreapp2.1\System.Data.SqlClient.dll : warning IL3053: Assembly 'System.Data.SqlClient' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbac
kup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Data.Common.dll : warning IL3053: Assembly 'System.Data.Common' produced AOT analysis warnings. [C:\MyCsharpProjects\fs
backup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\system.drawing.common\4.7.0\runtimes\win\lib\netcoreapp3.0\System.Drawing.Common.dll : warning IL3053: Assembly 'System.Drawing.Common' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbac
kup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Formats.Asn1.dll : warning IL3053: Assembly 'System.Formats.Asn1' produced AOT analysis warnings. [C:\MyCsharpProjects\
fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Private.Xml.dll : warning IL3053: Assembly 'System.Private.Xml' produced AOT analysis warnings. [C:\MyCsharpProjects\fs
backup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Collections.Specialized.dll : warning IL3053: Assembly 'System.Collections.Specialized' produced AOT analysis warnings.
[C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.ComponentModel.TypeConverter.dll : warning IL3053: Assembly 'System.ComponentModel.TypeConverter' produced AOT analysis
warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Text.RegularExpressions.dll : warning IL3053: Assembly 'System.Text.RegularExpressions' produced AOT analysis warnings.
[C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
Tentando cancelar a compilação...
C:\Users\isaque\.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\build\Microsoft.NETCore.Native.targets(269,5): warning MSB5021: Encerrando a tarefa executável "cmd" e seus processos filho porque o build foi cancelado
. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
PS C:\MyCsharpProjects\fsbackup2> dotnet publish -r win-x64 -c Release
Microsoft(R) Build Engine versão 17.2.0-preview-22152-03+719247ede para .NET
Copyright (C) Microsoft Corporation. Todos os direitos reservados.
Determinando os projetos a serem restaurados...
Todos os projetos estão atualizados para restauração.
Você está usando uma versão prévia do .NET. Confira: https://aka.ms/dotnet-support-policy
PeachPie PHP Compiler version 1.0.9+fd461dcb004df7d84be53252c300c4d882b81efd
fsbackup2 -> C:\MyCsharpProjects\fsbackup2\bin\Release\net5.0\win-x64\fsbackup2.dll
Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
Generating compatible native code. To optimize for size or speed, visit https://aka.ms/OptimizeCoreRT
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\sdk\System.Private.CoreLib.dll : warning IL3053: Assembly 'System.Private.CoreLib' produced AOT analysis warnings. [C:\MyCsharpProjects\
fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\Microsoft.CSharp.dll : warning IL3053: Assembly 'Microsoft.CSharp' produced AOT analysis warnings. [C:\MyCsharpProjects\fsback
up2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\Microsoft.VisualBasic.Core.dll : warning IL3053: Assembly 'Microsoft.VisualBasic.Core' produced AOT analysis warnings. [C:\MyC
sharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Linq.Queryable.dll : warning IL3053: Assembly 'System.Linq.Queryable' produced AOT analysis warnings. [C:\MyCsharpProje
cts\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Private.DataContractSerialization.dll : warning IL3053: Assembly 'System.Private.DataContractSerialization' produced AO
T analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Reflection.DispatchProxy.dll : warning IL3053: Assembly 'System.Reflection.DispatchProxy' produced AOT analysis warning
s. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Runtime.Serialization.Formatters.dll : warning IL3053: Assembly 'System.Runtime.Serialization.Formatters' produced AOT
analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\htmlagilitypack\1.11.25\lib\netstandard2.0\HtmlAgilityPack.dll : warning IL3053: Assembly 'HtmlAgilityPack' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\microsoft.applicationinsights\2.10.0\lib\netstandard2.0\Microsoft.ApplicationInsights.dll : warning IL3053: Assembly 'Microsoft.ApplicationInsights' produced AOT analysis warnings. [C:\MyCsharpProjects\fs
backup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\mono.posix.netstandard\1.0.0\runtimes\win-x64\lib\netstandard2.0\Mono.Posix.NETStandard.dll : warning IL3053: Assembly 'Mono.Posix.NETStandard' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbacku
p2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\peachpie.library\1.0.9\lib\netstandard2.0\Peachpie.Library.dll : warning IL3053: Assembly 'Peachpie.Library' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Net.Quic.dll : warning IL3053: Assembly 'System.Net.Quic' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup
2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Text.Json.dll : warning IL3053: Assembly 'System.Text.Json' produced AOT analysis warnings. [C:\MyCsharpProjects\fsback
up2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\peachpie.microsoft.codeanalysis\3.7.1\lib\netstandard2.0\Peachpie.Microsoft.CodeAnalysis.dll : warning IL3053: Assembly 'Peachpie.Microsoft.CodeAnalysis' produced AOT analysis warnings. [C:\MyCsharpProjec
ts\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\peachpie.runtime\1.0.9\lib\netstandard2.0\Peachpie.Runtime.dll : warning IL3053: Assembly 'Peachpie.Runtime' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Linq.Expressions.dll : warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings. [C:\MyCsharpP
rojects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\sixlabors.imagesharp\1.0.0\lib\netcoreapp3.1\SixLabors.ImageSharp.dll : warning IL3053: Assembly 'SixLabors.ImageSharp' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj
]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Diagnostics.DiagnosticSource.dll : warning IL3053: Assembly 'System.Diagnostics.DiagnosticSource' produced AOT analysis
warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\system.data.sqlclient\4.6.0\runtimes\win\lib\netcoreapp2.1\System.Data.SqlClient.dll : warning IL3053: Assembly 'System.Data.SqlClient' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbac
kup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Data.Common.dll : warning IL3053: Assembly 'System.Data.Common' produced AOT analysis warnings. [C:\MyCsharpProjects\fs
backup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\system.drawing.common\4.7.0\runtimes\win\lib\netcoreapp3.0\System.Drawing.Common.dll : warning IL3053: Assembly 'System.Drawing.Common' produced AOT analysis warnings. [C:\MyCsharpProjects\fsbackup2\fsbac
kup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Formats.Asn1.dll : warning IL3053: Assembly 'System.Formats.Asn1' produced AOT analysis warnings. [C:\MyCsharpProjects\
fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Private.Xml.dll : warning IL3053: Assembly 'System.Private.Xml' produced AOT analysis warnings. [C:\MyCsharpProjects\fs
backup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Collections.Specialized.dll : warning IL3053: Assembly 'System.Collections.Specialized' produced AOT analysis warnings.
[C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.ComponentModel.TypeConverter.dll : warning IL3053: Assembly 'System.ComponentModel.TypeConverter' produced AOT analysis
warnings. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\framework\System.Text.RegularExpressions.dll : warning IL3053: Assembly 'System.Text.RegularExpressions' produced AOT analysis warnings.
[C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
EXEC : error : Arithmetic operation resulted in an overflow. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
System.OverflowException: Arithmetic operation resulted in an overflow.
at Internal.TypeSystem.LockFreeReaderHashtable`2.Expand(TValue[] oldHashtable)
at Internal.TypeSystem.LockFreeReaderHashtable`2.AddOrGetExistingInner(TValue value, Boolean& addedValue)
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key)
at Internal.TypeSystem.MethodDesc.InstantiateSignature(Instantiation typeInstantiation, Instantiation methodInstantiation)
at ILCompiler.DependencyAnalysis.GVMDependenciesNode.SearchDynamicDependencies(List`1 markedNodes, Int32 firstNode, NodeFactory factory)
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.DynamicDependencyNode.MarkNewDynamicDependencies(DependencyAnalyzer`2 analyzer)
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack()
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes()
at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan()
at ILCompiler.Program.Run(String[] args)
at ILCompiler.Program.Main(String[] args)
C:\Users\isaque\.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-preview.2.22152.2\build\Microsoft.NETCore.Native.targets(269,5): error MSB3073: O comando ""C:\Users\isaque\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.
0.0-preview.2.22152.2\tools\\ilc" @"obj\Release\net5.0\win-x64\native\fsbackup2.ilc.rsp"" foi encerrado com o código 1. [C:\MyCsharpProjects\fsbackup2\fsbackup2.msbuildproj]
PS C:\MyCsharpProjects\fsbackup2>
PS C:\MyCsharpProjects\fsbackup2> C:\MyCsharpProjects\fsbackup2\bin\Release\net7.0\win-x64\native\fsbackup2.exe
Unhandled Exception: System.MissingMethodException: No parameterless constructor defined for this object.
at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0x116
at Pchp.Core.Reflection.ExtensionsTable.VisitAttribute(PhpExtensionAttribute) + 0x6a
at Pchp.Core.Reflection.ExtensionsTable.VisitAssembly(Assembly) + 0x7a
at Pchp.Core.Context.DllLoaderImpl.AddPhpPackageReference(Type) + 0x7f
at Pchp.Core.Context.DllLoaderImpl.AddScriptReference(Assembly) + 0xed
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x39
at fsbackup2!<BaseAddress>+0x3174a2
The current dll loader implementation is not compatible with NativeAOT.
https://github.com/peachpiecompiler/peachpie/blob/8041b35b51c2a0b798b5aac4ae73735379fe7b3a/src/Peachpie.Runtime/Context.cs#L105
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 Zlib as an example:
https://github.com/peachpiecompiler/peachpie/blob/8041b35b51c2a0b798b5aac4ae73735379fe7b3a/src/Peachpie.Library/zlib.cs#L21
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 DynamicallyAccessedMembers, or embed an ILLinker root xml file. But I'm not sure whether these takes work for NativeAOT.
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 What would need to be implemented in NativeAOT for this to work?
@hez2010 seems we can just embed ILLink.Descriptors.xml resource. The compiler should do the same for compiled PHP assemblies since most of the emitted members are accessed dynamically.
ILLink.Descriptors.xml are not yet implemented in NativeAOT. Only PublishTrimmed=true without NativeAOT supports them. We're planning to have them in NativeAOT by .NET 7.
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 DynamicallyAccessedMembers custom attribute annotation tells trimming to make the default constructor available for reflection.
Whenever trimming sees this attribute, it will make sure to keep the constructor on the typeof.
When you access the ConverterType property (notice it's also annotated with DynamicallyAccessedMembers), trimming will know that whatever can come from the property has its constructor kept and won't warn at the use site.
One can use DynamicallyAccessedMembers to annotate various System.Type instances reflected on at runtime this way.