public TypeResources(NPath typeDbOutputDirectory)
        {
            TypeDBOutputDirectory = typeDbOutputDirectory;
            var typeResources = new DotNetAssembly($"{EditorApplication.applicationContentsPath}/Tools/TypeGenerator/TypeGenerator.exe", Framework.Framework471);

            _typeGeneratorExecutable = new DotNetRunnableProgram(typeResources, DotNetRuntime.FindFor(typeResources));
        }
        private NPath[] SetupIL2CPPConversion(NPath[] linkerOutputFiles, NPath il2cppdata_destinationdir)
        {
            var il2cpp =
                new DotNetAssembly(
                    string.IsNullOrEmpty(CustomIL2CPPLocation) ?
                    $"{EditorApplication.applicationContentsPath}/il2cpp/build/deploy/net471/il2cpp.exe" :
                    $"{CustomIL2CPPLocation}/build/deploy/net471/il2cpp.exe",
                    Framework.Framework471);
            var netCoreRunRuntime = DotNetRuntime.FindFor(il2cpp); //NetCoreRunRuntime.FromSteve;
            var il2cppProgram     = new DotNetRunnableProgram(il2cpp, netCoreRunRuntime);

            var extraTypes = new HashSet <string>();

            foreach (var extraType in PlayerBuildInterface.ExtraTypesProvider?.Invoke() ?? Array.Empty <string>())
            {
                extraTypes.Add(extraType);
            }

            NPath extraTypesFile = Configuration.RootArtifactsPath.Combine("extra-types.txt").MakeAbsolute().WriteAllLines(extraTypes.ToArray());

            NPath il2cppOutputDir = Configuration.RootArtifactsPath.Combine("il2cpp");

            Backend.Current.AddAction("IL2CPP", Array.Empty <NPath>(),
                                      linkerOutputFiles
                                      .Concat(il2cpp.Path.Parent.Files()).Concat(netCoreRunRuntime.Inputs)
                                      .Concat(new[] { extraTypesFile })
                                      .ToArray(),
                                      il2cppProgram.InvocationString,
                                      new[]
            {
                "--convert-to-cpp",
                "--emit-null-checks",
                "--enable-array-bounds-check",
                "--dotnetprofile=\"unityaot\"",
                "--libil2cpp-static",
                $"--extra-types-file={extraTypesFile.InQuotes()}",
                "--profiler-report",
                $"--generatedcppdir={il2cppOutputDir.InQuotes(SlashMode.Native)}",
                $"--directory={linkerOutputFiles.First().Parent.InQuotes(SlashMode.Native)}",
            }, targetDirectories: new[] { il2cppOutputDir }, allowUnwrittenOutputFiles: true);

            var il2cppOutputFiles = GuessTargetDirectoryContentsFor(il2cppOutputDir, "dummy.cpp");

            var dataDir = il2cppOutputDir.Combine("Data");

            foreach (var il2cppdatafile in dataDir.FilesIfExists(recurse: true))
            {
                CopyTool.Instance().Setup(il2cppdata_destinationdir.Combine(il2cppdatafile.RelativeTo(dataDir)),
                                          il2cppdatafile);
            }

            return(il2cppOutputFiles);
        }
        public BurstCompiler(string burstTarget, string burstPlatform, NPath outputDirectory)
        {
            BurstTarget     = burstTarget;
            BurstPlatform   = burstPlatform;
            OutputDirectory = outputDirectory;

            // On macOS the PlatformName is set as OSX in bee but it needs to be macOS for bcl.
            if (burstPlatform == "OSX")
            {
                BurstPlatform = "macOS";
            }

            if (burstPlatform == "IOS" && burstTarget == "ARMV8A_AARCH64")
            {
                BurstPlatform = "iOS";
            }

            NPath burstDir   = Path.GetFullPath("Packages/com.unity.burst/.Runtime");
            var   burstFiles = burstDir.Files(recurse: true);

            bool IsManagedBurstLibrary(NPath f)
            {
                if (!f.HasExtension(".dll"))
                {
                    return(false);
                }

                if (f.FileName.StartsWith("burst-llvm-"))
                {
                    return(false);
                }

                // These two libraries are not crossgen-compatible.
                if (f.FileName == "Unity.Cecil.Rocks.dll" || f.FileName == "Newtonsoft.Json.dll")
                {
                    return(false);
                }

                return(true);
            }

            var bclAssembly = new DotNetAssembly(burstDir.Combine("bcl.exe"), Framework.Framework471)
                              .WithRuntimeDependencies(burstFiles
                                                       .Where(IsManagedBurstLibrary)
                                                       .Select(f => new DotNetAssembly(f, Framework.Framework471))
                                                       .ToArray());

#if BURST_NETCORE
            //todo: turn this to true.  we cannot right now because NetCoreRuntime.SteveDore is implemented through a static field,
            //which is incompatible with our "create graph in editor, and maybe we will create two graphs during the same domain".  the creation
            //of the steve artifact happens only once,  but it needs to be registered in each backend. the fact that it doesn't means you can get into
            //ugly situations where on second builds the dependencies to netcorerun are not properly setup.
            bool useNetCore = false;

            if (useNetCore)
            {
                var runtime = NetCoreRunRuntime.FromSteve;
                _dotnetRuntime = runtime;

                var useCrossGen = false;
                if (useCrossGen)
                {
                    bclAssembly = runtime.SetupAheadOfTimeCompilation(bclAssembly, "artifacts/bcl-crossgen");

                    bclAssembly = bclAssembly.WithPath(bclAssembly.Path.MakeAbsolute(BeeProjectRoot));
                    foreach (var file in burstFiles.Where(x => !IsManagedBurstLibrary(x)))
                    {
                        var relative = file.RelativeTo(burstDir);

                        var temp = CopyTool.Instance().Setup(bclAssembly.Path.Parent.Combine(relative), file);
                        Backend.Current.AddDependency(temp, bclAssembly.Path);
                    }
                }
            }
            else
#else
            {
                _dotnetRuntime = DotNetRuntime.FindFor(bclAssembly);
            }
#endif

            { _burstRunnableProgram = new DotNetRunnableProgram(bclAssembly, _dotnetRuntime); }
            _burstCompilerInputFiles = burstFiles;

            var burstPackageInfo =
                UnityEditor.PackageManager.PackageInfo.FindForAssetPath("Packages/com.unity.burst/somefile");
            var burstPackageRawVersion = burstPackageInfo.version;

            // Remove everything after '-' if this is a preview package.
            var parts = burstPackageRawVersion.Split('-');
            if (parts.Length > 1)
            {
                burstPackageRawVersion = parts[0];
            }

            // Get the preview version number.
            // Default to max int to signal a very high preview number on release.
            var previewNumber = int.MaxValue;
            if (parts.Length > 1)
            {
                previewNumber = int.Parse(parts[1].Split('.')[1]);
            }

            var burstVersion = Version.Parse(burstPackageRawVersion);
            var burstVersionWithIncludeRootAssemblyReferencesFeature = new Version(1, 3);
            _installedBurstSupportsIncludeRootAssemblyReferencesFeature = burstVersion >= burstVersionWithIncludeRootAssemblyReferencesFeature;
            if (!_installedBurstSupportsIncludeRootAssemblyReferencesFeature)
            {
                Debug.Log($"Using burst 1.3 instead of {burstVersion.ToString()} will give much better build times. At the time of this writing it is only available by building manually on your machine.");
            }

            _installedBurstSupportsCaching =
                (burstVersion >= new Version(1, 3) && previewNumber > 7) ||
                burstVersion >= new Version(1, 4);
            if (!_installedBurstSupportsCaching)
            {
                Debug.Log($"Using burst 1.3 preview 8 or above instead of {burstVersion.ToString()} will give much better build times. At the time of this writing it is only available by building manually on your machine.");
            }

            _installedBurstIs1_3Preview10OrLater =
                (burstVersion >= new Version(1, 3) && previewNumber >= 10) ||
                burstVersion >= new Version(1, 4);
        }
 private static Exception BadRuntime(DotNetRuntime runtime) =>
 new DotNetCoreInstallerException($"Unhandled value for DotNetDistributionParameters.Runtime: {runtime}");