()
| 145 | } |
| 146 | |
| 147 | internal static void RunAOT() |
| 148 | { |
| 149 | var platform = Configuration.BuildPlatforms[0]; |
| 150 | var arch = Configuration.BuildArchitectures[0]; |
| 151 | var configuration = Configuration.BuildConfigurations[0]; |
| 152 | if (!DotNetSdk.Instance.GetHostRuntime(platform, arch, out var hostRuntime)) |
| 153 | throw new Exception("Missing host runtime"); |
| 154 | var buildPlatform = Platform.GetPlatform(platform); |
| 155 | var buildToolchain = buildPlatform.GetToolchain(arch); |
| 156 | var dotnetAotDebug = Configuration.CustomDefines.Contains("DOTNET_AOT_DEBUG") || Environment.GetEnvironmentVariable("DOTNET_AOT_DEBUG") == "1"; |
| 157 | var aotMode = Configuration.AOTMode; |
| 158 | var outputPath = Configuration.BinariesFolder; // Provided by PrecompileAssembliesStep |
| 159 | var aotAssembliesPath = Configuration.IntermediateFolder; // Provided by PrecompileAssembliesStep |
| 160 | if (!Directory.Exists(outputPath)) |
| 161 | throw new Exception("Missing AOT output folder " + outputPath); |
| 162 | if (!Directory.Exists(aotAssembliesPath)) |
| 163 | throw new Exception("Missing AOT assemblies folder " + aotAssembliesPath); |
| 164 | var dotnetOutputPath = Path.Combine(outputPath, "Dotnet"); |
| 165 | if (!Directory.Exists(dotnetOutputPath)) |
| 166 | Directory.CreateDirectory(dotnetOutputPath); |
| 167 | |
| 168 | // Find input files |
| 169 | var inputFiles = Directory.GetFiles(aotAssembliesPath, "*.dll", SearchOption.TopDirectoryOnly).ToList(); |
| 170 | inputFiles.RemoveAll(FilterAssembly); |
| 171 | for (int i = 0; i < inputFiles.Count; i++) |
| 172 | inputFiles[i] = Utilities.NormalizePath(inputFiles[i]); |
| 173 | inputFiles.Sort(); |
| 174 | |
| 175 | // Useful references about AOT: |
| 176 | // .NET Native IL Compiler (shorten as ILC) is used to convert IL into native platform binary |
| 177 | // https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/README.md |
| 178 | // https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/nativeaot.md |
| 179 | // https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary |
| 180 | // http://www.mono-project.com/docs/advanced/runtime/docs/aot/ |
| 181 | // http://www.mono-project.com/docs/advanced/aot/ |
| 182 | |
| 183 | if (aotMode == DotNetAOTModes.ILC) |
| 184 | { |
| 185 | var runtimeIdentifier = DotNetSdk.GetHostRuntimeIdentifier(platform, arch); |
| 186 | var runtimeIdentifierParts = runtimeIdentifier.Split('-'); |
| 187 | var enableReflection = true; |
| 188 | var enableReflectionScan = true; |
| 189 | var enableStackTrace = true; |
| 190 | |
| 191 | var aotOutputPath = Path.Combine(aotAssembliesPath, "Output"); |
| 192 | if (!Directory.Exists(aotOutputPath)) |
| 193 | Directory.CreateDirectory(aotOutputPath); |
| 194 | |
| 195 | // TODO: run dotnet nuget installation to get 'runtime.<runtimeIdentifier>.Microsoft.DotNet.ILCompiler' package |
| 196 | //var ilcRoot = Path.Combine(DotNetSdk.Instance.RootPath, "sdk\\7.0.202\\Sdks\\Microsoft.DotNet.ILCompiler"); |
| 197 | var ilcRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), $".nuget\\packages\\runtime.{runtimeIdentifier}.microsoft.dotnet.ilcompiler\\7.0.4"); |
| 198 | |
| 199 | // Build ILC args list |
| 200 | var ilcArgs = new StringBuilder(); |
| 201 | ilcArgs.AppendLine("--resilient"); // Ignore unresolved types, methods, and assemblies. Defaults to false |
| 202 | ilcArgs.AppendLine("--nativelib"); // Compile as static or shared library |
| 203 | if (configuration != TargetConfiguration.Debug) |
| 204 | ilcArgs.AppendLine("-O"); // Enable optimizations |
no test coverage detected