Ejemplo n.º 1
0
        public void OnBeforeConvertRun(
            BuildReport report,
            Il2CppBuildPipelineData data)
        {
            if (data.target != UnityEditor.BuildTarget.WebGL)
            {
                return;
            }

            using (var assembly = AssemblyDefinition.ReadAssembly(Path.Combine(data.inputDirectory, "mscorlib.dll"), new ReaderParameters(ReadingMode.Immediate)
            {
                ReadWrite = true
            }))
            {
                var mainModule = assembly.MainModule;
                if (!TryGetTypes(mainModule, out var threadPool, out var synchronizationContext, out var postCallback, out var waitCallback, out var taskExecutionItem, out var timeScheduler))
                {
                    return;
                }

                PatchThreadPool(mainModule, threadPool, synchronizationContext, postCallback, waitCallback, taskExecutionItem);

                PatchTimerScheduler(mainModule, timeScheduler, threadPool, waitCallback);
                assembly.Write();
            }
        }
 public void OnBeforeConvertRun(BuildReport report, Il2CppBuildPipelineData data)
 {
     foreach (var path in Directory.GetFiles(data.inputDirectory)
              .Where(p => p.EndsWith(".dll") || p.EndsWith(".exe")))
     {
         ModifiAssembly(path);
     }
 }
Ejemplo n.º 3
0
        public void Run()
        {
            var outputDirectory = GetCppOutputDirectoryInStagingArea();
            var managedDir      = Path.GetFullPath(Path.Combine(m_StagingAreaData, "Managed"));

            // Make all assemblies in Staging/Managed writable for stripping.
            foreach (var file in Directory.GetFiles(managedDir))
            {
                var fileInfo = new FileInfo(file);
                fileInfo.IsReadOnly = false;
            }

            var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);

            var managedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(buildTargetGroup);

            // IL2CPP does not support a managed stripping level of disabled. If the player settings
            // do try this (which should not be possible from the editor), use Low instead.
            if (managedStrippingLevel == ManagedStrippingLevel.Disabled)
            {
                managedStrippingLevel = ManagedStrippingLevel.Low;
            }
            AssemblyStripper.StripAssemblies(managedDir, m_PlatformProvider.CreateUnityLinkerPlatformProvider(), m_PlatformProvider, m_RuntimeClassRegistry, managedStrippingLevel);

            // The IL2CPP editor integration here is responsible to give il2cpp.exe an empty directory to use.
            FileUtil.CreateOrCleanDirectory(outputDirectory);

            if (m_ModifyOutputBeforeCompile != null)
            {
                m_ModifyOutputBeforeCompile(outputDirectory);
            }

            var pipelineData = new Il2CppBuildPipelineData(m_PlatformProvider.target, managedDir);

            ConvertPlayerDlltoCpp(pipelineData, outputDirectory, managedDir, m_PlatformProvider.supportsManagedDebugging);

            var compiler = m_PlatformProvider.CreateNativeCompiler();

            if (compiler != null && m_PlatformProvider.CreateIl2CppNativeCodeBuilder() == null)
            {
                var nativeLibPath = OutputFileRelativePath();

                var includePaths = new List <string>(m_PlatformProvider.includePaths);
                includePaths.Add(outputDirectory);

                m_PlatformProvider.CreateNativeCompiler().CompileDynamicLibrary(
                    nativeLibPath,
                    NativeCompiler.AllSourceFilesIn(outputDirectory),
                    includePaths,
                    m_PlatformProvider.libraryPaths,
                    new string[0]);
            }
        }
Ejemplo n.º 4
0
        static void ProcessBuildPipelineOnBeforeConvertRun(BuildReport report, Il2CppBuildPipelineData data)
        {
            var processors = BuildPipelineInterfaces.processors.il2cppProcessors;

            if (processors == null)
            {
                return;
            }

            foreach (var processor in processors)
            {
                processor.OnBeforeConvertRun(report, data);
            }
        }
Ejemplo n.º 5
0
        public void Run()
        {
            var generatedCppDir             = GetCppOutputDirectory(m_PlatformProvider.il2cppBuildCacheDirectory);
            var additionalCppFilesDirectory = GetAdditionalCppFilesDirectory(m_PlatformProvider.il2cppBuildCacheDirectory);
            var managedDir = Path.GetFullPath(Path.Combine(m_StagingAreaData, "Managed"));

            // Make all assemblies in Staging/Managed writable for stripping.
            ClearReadOnlyFlagOnAllFilesNonRecursively(managedDir);

            var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);

            var managedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(buildTargetGroup);

            // IL2CPP does not support a managed stripping level of disabled. If the player settings
            // do try this (which should not be possible from the editor), use Low instead.
            if (managedStrippingLevel == ManagedStrippingLevel.Disabled)
            {
                managedStrippingLevel = ManagedStrippingLevel.Minimal;
            }
            AssemblyStripper.StripAssemblies(managedDir, m_PlatformProvider.CreateUnityLinkerPlatformProvider(), m_PlatformProvider, m_RuntimeClassRegistry, managedStrippingLevel);

            Directory.CreateDirectory(m_TempFolder);
            Directory.CreateDirectory(generatedCppDir);
            ClearReadOnlyFlagOnAllFilesNonRecursively(generatedCppDir);

            // Need to clean out the AdditionalCppFiles directory because a platform could do pretty much anything
            // in a "modifyOutputBeforeCompile" callback method, and so we need to provide a fresh directory. Bee will
            // still check the hash of these files before doing a build, so writing them again won't cause a recompile.
            if (Directory.Exists(additionalCppFilesDirectory))
            {
                ClearReadOnlyFlagOnAllFilesNonRecursively(additionalCppFilesDirectory);
                Directory.Delete(additionalCppFilesDirectory, true);
            }

            Directory.CreateDirectory(additionalCppFilesDirectory);

            if (m_ModifyOutputBeforeCompile != null)
            {
                m_ModifyOutputBeforeCompile(additionalCppFilesDirectory);
            }

            var pipelineData = new Il2CppBuildPipelineData(m_PlatformProvider.target, managedDir);

            ConvertPlayerDlltoCpp(pipelineData);
        }
Ejemplo n.º 6
0
        private void ConvertPlayerDlltoCpp(Il2CppBuildPipelineData data, string outputDirectory, string workingDirectory, bool platformSupportsManagedDebugging)
        {
            ProcessBuildPipelineOnBeforeConvertRun(m_PlatformProvider.buildReport, data);

            var arguments = new List <string>();

            arguments.Add("--convert-to-cpp");

            if (m_PlatformProvider.emitNullChecks)
            {
                arguments.Add("--emit-null-checks");
            }

            if (m_PlatformProvider.enableStackTraces)
            {
                arguments.Add("--enable-stacktrace");
            }

            if (m_PlatformProvider.enableArrayBoundsCheck)
            {
                arguments.Add("--enable-array-bounds-check");
            }

            if (m_PlatformProvider.enableDivideByZeroCheck)
            {
                arguments.Add("--enable-divide-by-zero-check");
            }

            if (m_PlatformProvider.development && m_PlatformProvider.enableDeepProfilingSupport)
            {
                arguments.Add("--enable-deep-profiler");
            }

            if (m_BuildForMonoRuntime)
            {
                arguments.Add("--mono-runtime");
            }

            var buildTargetGroup      = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);
            var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);

            arguments.Add(string.Format("--dotnetprofile=\"{0}\"", IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(apiCompatibilityLevel)));


            var il2CppNativeCodeBuilder = m_PlatformProvider.CreateIl2CppNativeCodeBuilder();

            if (il2CppNativeCodeBuilder != null)
            {
                var compilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup);
                Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder);
                arguments.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, OutputFileRelativePath(), m_PlatformProvider.includePaths, m_PlatformProvider.libraryPaths, compilerConfiguration));
            }

            arguments.AddRange(IL2CPPUtils.GetDebuggerIL2CPPArguments(m_PlatformProvider, buildTargetGroup));
            arguments.AddRange(IL2CPPUtils.GetBuildingIL2CPPArguments(m_PlatformProvider, buildTargetGroup));
            arguments.Add($"--map-file-parser={CommandLineFormatter.PrepareFileName(GetMapFileParserPath())}");

            var additionalArgs = IL2CPPUtils.GetAdditionalArguments();

            if (!string.IsNullOrEmpty(additionalArgs))
            {
                arguments.Add(additionalArgs);
            }

            arguments.Add($"--directory={CommandLineFormatter.PrepareFileName(Path.GetFullPath(data.inputDirectory))}");

            arguments.Add($"--generatedcppdir={CommandLineFormatter.PrepareFileName(Path.GetFullPath(outputDirectory))}");

            // NOTE: any arguments added here that affect how generated code is built need
            // to also be added to PlatformDependent\Win\Extensions\Managed\VisualStudioProjectHelpers.cs
            // as that file generated project files that invoke back into IL2CPP in order to build
            // generated code

            string progressMessage = "Converting managed assemblies to C++";

            if (il2CppNativeCodeBuilder != null)
            {
                progressMessage = "Building native binary with IL2CPP...";
            }

            if (EditorUtility.DisplayCancelableProgressBar("Building Player", progressMessage, 0.3f))
            {
                throw new OperationCanceledException();
            }

            Action <ProcessStartInfo> setupStartInfo = null;

            if (il2CppNativeCodeBuilder != null)
            {
                setupStartInfo = il2CppNativeCodeBuilder.SetupStartInfo;
            }

            if (PlayerBuildInterface.ExtraTypesProvider != null)
            {
                var extraTypes = new HashSet <string>();
                foreach (var extraType in PlayerBuildInterface.ExtraTypesProvider())
                {
                    extraTypes.Add(extraType);
                }

                var tempFile = Path.GetFullPath(Path.Combine(m_TempFolder, "extra-types.txt"));
                File.WriteAllLines(tempFile, extraTypes.ToArray());
                arguments.Add($"--extra-types-file={CommandLineFormatter.PrepareFileName(tempFile)}");
            }

            RunIl2CppWithArguments(arguments, setupStartInfo, workingDirectory);
        }
Ejemplo n.º 7
0
        private void ConvertPlayerDlltoCpp(Il2CppBuildPipelineData data)
        {
            var arguments = new List <string>();

            arguments.Add("--convert-to-cpp");

            if (m_PlatformProvider.emitNullChecks)
            {
                arguments.Add("--emit-null-checks");
            }

            if (m_PlatformProvider.enableStackTraces)
            {
                arguments.Add("--enable-stacktrace");
            }

            if (m_PlatformProvider.enableArrayBoundsCheck)
            {
                arguments.Add("--enable-array-bounds-check");
            }

            if (m_PlatformProvider.enableDivideByZeroCheck)
            {
                arguments.Add("--enable-divide-by-zero-check");
            }

            if (m_PlatformProvider.development && m_PlatformProvider.enableDeepProfilingSupport)
            {
                arguments.Add("--enable-deep-profiler");
            }

            if (m_BuildForMonoRuntime)
            {
                arguments.Add("--mono-runtime");
            }

            var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(m_PlatformProvider.namedBuildTarget);

            arguments.Add(string.Format("--dotnetprofile=\"{0}\"", IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(apiCompatibilityLevel, m_PlatformProvider.target)));

            var il2cppCodeGeneration = PlayerSettings.GetIl2CppCodeGeneration(m_PlatformProvider.namedBuildTarget);

            if (il2cppCodeGeneration == Il2CppCodeGeneration.OptimizeSize)
            {
                arguments.Add("--generics-option=EnableFullSharing");
            }

            var il2CppNativeCodeBuilder = m_PlatformProvider.CreateIl2CppNativeCodeBuilder();

            if (il2CppNativeCodeBuilder != null)
            {
                var buildCacheNativeOutputFile = Path.Combine(GetNativeOutputRelativeDirectory(m_PlatformProvider.il2cppBuildCacheDirectory), m_PlatformProvider.nativeLibraryFileName);
                var compilerConfiguration      = PlayerSettings.GetIl2CppCompilerConfiguration(m_PlatformProvider.namedBuildTarget);
                Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder);
                arguments.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, buildCacheNativeOutputFile, m_PlatformProvider.includePaths, m_PlatformProvider.libraryPaths, compilerConfiguration));
            }
            else
            {
                arguments.Add($"--cachedirectory={CommandLineFormatter.PrepareFileName(GetShortPathName(Path.GetFullPath(m_PlatformProvider.il2cppBuildCacheDirectory)))}");
            }

            // Additional files can take any form, depending on platform, so pass anything in the additional files directory
            foreach (var additionalCppFile in Directory.GetFiles(GetAdditionalCppFilesDirectory(m_PlatformProvider.il2cppBuildCacheDirectory)))
            {
                arguments.Add($"--additional-cpp={CommandLineFormatter.PrepareFileName(GetShortPathName(Path.GetFullPath(additionalCppFile)))}");
            }

            arguments.AddRange(IL2CPPUtils.GetDebuggerIL2CPPArguments(m_PlatformProvider));
            foreach (var buildingArgument in IL2CPPUtils.GetBuildingIL2CPPArguments(m_PlatformProvider))
            {
                if (!arguments.Contains(buildingArgument))
                {
                    arguments.Add(buildingArgument);
                }
            }

            if (CrashReportingSettings.enabled)
            {
                arguments.Add($"--emit-source-mapping");
            }

            var additionalArgs = IL2CPPUtils.GetAdditionalArguments();

            if (!string.IsNullOrEmpty(additionalArgs))
            {
                arguments.Add(additionalArgs);
            }

            arguments.Add($"--directory={CommandLineFormatter.PrepareFileName(GetShortPathName(Path.GetFullPath(data.inputDirectory)))}");
            arguments.Add($"--generatedcppdir={CommandLineFormatter.PrepareFileName(GetCppOutputDirectory(m_PlatformProvider.il2cppBuildCacheDirectory))}");

            // NOTE: any arguments added here that affect how generated code is built need
            // to also be added to PlatformDependent\Win\Extensions\Managed\VisualStudioProjectHelpers.cs
            // as that file generated project files that invoke back into IL2CPP in order to build
            // generated code

            string progressMessage = "Converting managed assemblies to C++";

            if (il2CppNativeCodeBuilder != null)
            {
                progressMessage = "Building native binary with IL2CPP...";
            }

            if (EditorUtility.DisplayCancelableProgressBar("Building Player", progressMessage, 0.3f))
            {
                throw new OperationCanceledException();
            }

            Action <ProcessStartInfo> setupStartInfo = null;

            if (il2CppNativeCodeBuilder != null)
            {
                setupStartInfo = il2CppNativeCodeBuilder.SetupStartInfo;
            }

            if (PlayerBuildInterface.ExtraTypesProvider != null)
            {
                var extraTypes = new HashSet <string>();
                foreach (var extraType in PlayerBuildInterface.ExtraTypesProvider())
                {
                    extraTypes.Add(extraType);
                }

                var tempFile = Path.GetFullPath(Path.Combine(m_TempFolder, "extra-types.txt"));
                File.WriteAllLines(tempFile, extraTypes.ToArray());
                arguments.Add($"--extra-types-file={CommandLineFormatter.PrepareFileName(tempFile)}");
            }

            RunIl2CppWithArguments(arguments, setupStartInfo);
        }
Ejemplo n.º 8
0
        public void OnBeforeConvertRun(BuildReport report, Il2CppBuildPipelineData data)
        {
            Debug.LogWarning("[Frame Rate Booster] Using FRB on IL2CPP can make builds slower. More details at this link: https://forum.curvyeditor.com/thread-861.html");

            OptimizeBuild(report.summary.platform, data.inputDirectory);
        }