Exemplo n.º 1
0
        public void RunCompileAndLink()
        {
            var il2CppNativeCodeBuilder = m_PlatformProvider.CreateIl2CppNativeCodeBuilder();

            if (il2CppNativeCodeBuilder != null)
            {
                Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder);

                var buildTargetGroup      = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);
                var compilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup);
                var arguments             = Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, OutputFileRelativePath(), m_PlatformProvider.includePaths, m_PlatformProvider.libraryPaths, compilerConfiguration).ToList();

                arguments.Add(string.Format("--map-file-parser=\"{0}\"", GetMapFileParserPath()));
                arguments.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(GetCppOutputDirectoryInStagingArea())));
                arguments.Add(string.Format("--dotnetprofile=\"{0}\"", IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup))));
                Action <ProcessStartInfo> setupStartInfo = il2CppNativeCodeBuilder.SetupStartInfo;
                var managedDir = Path.GetFullPath(Path.Combine(m_StagingAreaData, "Managed"));

                RunIl2CppWithArguments(arguments, setupStartInfo, managedDir);
            }
        }
        public static IEnumerable <string> AddBuilderArguments(Il2CppNativeCodeBuilder builder, string outputRelativePath, IEnumerable <string> includeRelativePaths, bool debugBuild)
        {
            List <string> list = new List <string>();

            list.Add("--compile-cpp");
            list.Add("--libil2cpp-static");
            list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("platform", builder.CompilerPlatform));
            list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("architecture", builder.CompilerArchitecture));
            if (debugBuild)
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("configuration", "Debug"));
            }
            else
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("configuration", "Release"));
            }
            list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("outputpath", builder.ConvertOutputFileToFullPath(outputRelativePath)));
            if (!string.IsNullOrEmpty(builder.CacheDirectory))
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("cachedirectory", Il2CppNativeCodeBuilderUtils.CacheDirectoryPathFor(builder.CacheDirectory)));
            }
            if (!string.IsNullOrEmpty(builder.CompilerFlags))
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("compiler-flags", builder.CompilerFlags));
            }
            if (!string.IsNullOrEmpty(builder.LinkerFlags))
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("linker-flags", builder.LinkerFlags));
            }
            if (!string.IsNullOrEmpty(builder.PluginPath))
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("plugin", builder.PluginPath));
            }
            foreach (string current in builder.ConvertIncludesToFullPaths(includeRelativePaths))
            {
                list.Add(Il2CppNativeCodeBuilderUtils.FormatArgument("additional-include-directories", current));
            }
            list.AddRange(builder.AdditionalIl2CPPArguments);
            return(list);
        }
Exemplo n.º 3
0
        private void ConvertPlayerDlltoCpp(string inputDirectory, string outputDirectory, string workingDirectory, bool platformSupportsManagedDebugging)
        {
            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_BuildForMonoRuntime)
            {
                arguments.Add("--mono-runtime");
            }

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

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

            if (IL2CPPUtils.EnableIL2CPPDebugger(m_PlatformProvider, buildTargetGroup) && platformSupportsManagedDebugging)
            {
                arguments.Add("--enable-debugger");
            }

            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.Add(string.Format("--map-file-parser=\"{0}\"", GetMapFileParserPath()));

            var additionalArgs = IL2CPPUtils.GetAdditionalArguments();

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

            arguments.Add("--directory=\"" + Path.GetFullPath(inputDirectory) + "\"");

            arguments.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(outputDirectory)));

            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(string.Format("--extra-types-file=\"{0}\"", tempFile));
            }

            RunIl2CppWithArguments(arguments, setupStartInfo, workingDirectory);
        }
Exemplo n.º 4
0
        private void ConvertPlayerDlltoCpp(ICollection <string> userAssemblies, string outputDirectory, string workingDirectory, bool platformSupportsManagedDebugging)
        {
            if (userAssemblies.Count == 0)
            {
                return;
            }

            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.developmentMode)
            {
                arguments.Add("--development-mode");
            }

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

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

            if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6)
            {
                arguments.Add("--dotnetprofile=\"unityjit\"");
            }

            if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_Standard_2_0)
            {
                arguments.Add("--dotnetprofile=\"unityaot\"");
            }

            if (EditorUserBuildSettings.allowDebugging && platformSupportsManagedDebugging && EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest)
            {
                arguments.Add("--enable-debugger");
            }

            var il2CppNativeCodeBuilder = m_PlatformProvider.CreateIl2CppNativeCodeBuilder();

            if (il2CppNativeCodeBuilder != null)
            {
                var useDebugBuild = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup) == Il2CppCompilerConfiguration.Debug;

                Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder);
                arguments.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, OutputFileRelativePath(), m_PlatformProvider.includePaths, useDebugBuild));
            }

            arguments.Add(string.Format("--map-file-parser=\"{0}\"", GetMapFileParserPath()));

            var additionalArgs = PlayerSettings.GetAdditionalIl2CppArgs();

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

            additionalArgs = System.Environment.GetEnvironmentVariable("IL2CPP_ADDITIONAL_ARGS");
            if (!string.IsNullOrEmpty(additionalArgs))
            {
                arguments.Add(additionalArgs);
            }

            var pathArguments = new List <string>(userAssemblies);

            arguments.AddRange(pathArguments.Select(arg => "--assembly=\"" + Path.GetFullPath(arg) + "\""));

            arguments.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(outputDirectory)));

            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(string.Format("--extra-types-file=\"{0}\"", tempFile));
            }

            RunIl2CppWithArguments(arguments, setupStartInfo, workingDirectory);
        }
Exemplo n.º 5
0
 private void ConvertPlayerDlltoCpp(ICollection <string> userAssemblies, string outputDirectory, string workingDirectory)
 {
     if (userAssemblies.Count != 0)
     {
         List <string> list = new List <string>();
         list.Add("--convert-to-cpp");
         if (this.m_PlatformProvider.emitNullChecks)
         {
             list.Add("--emit-null-checks");
         }
         if (this.m_PlatformProvider.enableStackTraces)
         {
             list.Add("--enable-stacktrace");
         }
         if (this.m_PlatformProvider.enableArrayBoundsCheck)
         {
             list.Add("--enable-array-bounds-check");
         }
         if (this.m_PlatformProvider.enableDivideByZeroCheck)
         {
             list.Add("--enable-divide-by-zero-check");
         }
         if (this.m_PlatformProvider.developmentMode)
         {
             list.Add("--development-mode");
         }
         BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(this.m_PlatformProvider.target);
         if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6)
         {
             list.Add("--dotnetprofile=\"net45\"");
         }
         Il2CppNativeCodeBuilder il2CppNativeCodeBuilder = this.m_PlatformProvider.CreateIl2CppNativeCodeBuilder();
         if (il2CppNativeCodeBuilder != null)
         {
             Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder);
             list.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, this.OutputFileRelativePath(), this.m_PlatformProvider.includePaths, this.m_DebugBuild));
         }
         list.Add(string.Format("--map-file-parser=\"{0}\"", IL2CPPBuilder.GetMapFileParserPath()));
         string text = PlayerSettings.GetAdditionalIl2CppArgs();
         if (!string.IsNullOrEmpty(text))
         {
             list.Add(text);
         }
         text = Environment.GetEnvironmentVariable("IL2CPP_ADDITIONAL_ARGS");
         if (!string.IsNullOrEmpty(text))
         {
             list.Add(text);
         }
         List <string> source = new List <string>(userAssemblies);
         list.AddRange(from arg in source
                       select "--assembly=\"" + Path.GetFullPath(arg) + "\"");
         list.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(outputDirectory)));
         string info = "Converting managed assemblies to C++";
         if (il2CppNativeCodeBuilder != null)
         {
             info = "Building native binary with IL2CPP...";
         }
         if (EditorUtility.DisplayCancelableProgressBar("Building Player", info, 0.3f))
         {
             throw new OperationCanceledException();
         }
         Action <ProcessStartInfo> setupStartInfo = null;
         if (il2CppNativeCodeBuilder != null)
         {
             setupStartInfo = new Action <ProcessStartInfo>(il2CppNativeCodeBuilder.SetupStartInfo);
         }
         this.RunIl2CppWithArguments(list, setupStartInfo, workingDirectory);
     }
 }
Exemplo 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);
        }
 private static string FormatArgument(string name, string value)
 {
     return(string.Format("--{0}=\"{1}\"", name, Il2CppNativeCodeBuilderUtils.EscapeEmbeddedQuotes(value)));
 }
 public static string ObjectFilePathInCacheDirectoryFor(string builderCacheDirectory)
 {
     return(Il2CppNativeCodeBuilderUtils.CacheDirectoryPathFor(builderCacheDirectory));
 }
Exemplo n.º 9
0
        private void ConvertPlayerDlltoCpp(ICollection <string> userAssemblies, string outputDirectory, string workingDirectory)
        {
            if (userAssemblies.Count == 0)
            {
                return;
            }
            string[] array = (from s in Directory.GetFiles("Assets", "il2cpp_extra_types.txt", SearchOption.AllDirectories)
                              select Path.Combine(Directory.GetCurrentDirectory(), s)).ToArray <string>();
            string        il2CppExe = this.GetIl2CppExe();
            List <string> list      = new List <string>();

            list.Add("--convert-to-cpp");
            if (this.m_PlatformProvider.emitNullChecks)
            {
                list.Add("--emit-null-checks");
            }
            if (this.m_PlatformProvider.enableStackTraces)
            {
                list.Add("--enable-stacktrace");
            }
            if (this.m_PlatformProvider.enableArrayBoundsCheck)
            {
                list.Add("--enable-array-bounds-check");
            }
            if (this.m_PlatformProvider.enableDivideByZeroCheck)
            {
                list.Add("--enable-divide-by-zero-check");
            }
            if (this.m_PlatformProvider.loadSymbols)
            {
                list.Add("--enable-symbol-loading");
            }
            if (this.m_PlatformProvider.developmentMode)
            {
                list.Add("--development-mode");
            }
            Il2CppNativeCodeBuilder il2CppNativeCodeBuilder = this.m_PlatformProvider.CreateIl2CppNativeCodeBuilder();

            if (il2CppNativeCodeBuilder != null)
            {
                string fullUnityVersion = InternalEditorUtility.GetFullUnityVersion();
                Il2CppNativeCodeBuilderUtils.ClearCacheIfEditorVersionDiffers(il2CppNativeCodeBuilder, fullUnityVersion);
                Il2CppNativeCodeBuilderUtils.PrepareCacheDirectory(il2CppNativeCodeBuilder, fullUnityVersion);
                list.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, this.OutputFileRelativePath(), this.m_PlatformProvider.includePaths));
            }
            if (array.Length > 0)
            {
                string[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    string arg2 = array2[i];
                    list.Add(string.Format("--extra-types.file=\"{0}\"", arg2));
                }
            }
            string text = Path.Combine(this.m_PlatformProvider.il2CppFolder, "il2cpp_default_extra_types.txt");

            if (File.Exists(text))
            {
                list.Add(string.Format("--extra-types.file=\"{0}\"", text));
            }
            string text2 = string.Empty;

            if (PlayerSettings.GetPropertyOptionalString("additionalIl2CppArgs", ref text2))
            {
                list.Add(text2);
            }
            text2 = Environment.GetEnvironmentVariable("IL2CPP_ADDITIONAL_ARGS");
            if (!string.IsNullOrEmpty(text2))
            {
                list.Add(text2);
            }
            List <string> source = new List <string>(userAssemblies);

            list.AddRange(from arg in source
                          select "--assembly=\"" + Path.GetFullPath(arg) + "\"");
            list.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(outputDirectory)));
            string text3 = list.Aggregate(string.Empty, (string current, string arg) => current + arg + " ");

            Console.WriteLine("Invoking il2cpp with arguments: " + text3);
            if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Converting managed assemblies to C++", 0.3f))
            {
                throw new OperationCanceledException();
            }
            Action <ProcessStartInfo> setupStartInfo = null;

            if (il2CppNativeCodeBuilder != null)
            {
                setupStartInfo = new Action <ProcessStartInfo>(il2CppNativeCodeBuilder.SetupStartInfo);
            }
            Runner.RunManagedProgram(il2CppExe, text3, workingDirectory, new Il2CppOutputParser(), setupStartInfo);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 private void ConvertPlayerDlltoCpp(ICollection <string> userAssemblies, string outputDirectory, string workingDirectory)
 {
     if (userAssemblies.Count != 0)
     {
         string[] array = (from s in Directory.GetFiles("Assets", "il2cpp_extra_types.txt", SearchOption.AllDirectories)
                           select Path.Combine(Directory.GetCurrentDirectory(), s)).ToArray <string>();
         List <string> list = new List <string>();
         list.Add("--convert-to-cpp");
         if (this.m_PlatformProvider.emitNullChecks)
         {
             list.Add("--emit-null-checks");
         }
         if (this.m_PlatformProvider.enableStackTraces)
         {
             list.Add("--enable-stacktrace");
         }
         if (this.m_PlatformProvider.enableArrayBoundsCheck)
         {
             list.Add("--enable-array-bounds-check");
         }
         if (this.m_PlatformProvider.enableDivideByZeroCheck)
         {
             list.Add("--enable-divide-by-zero-check");
         }
         if (this.m_PlatformProvider.loadSymbols)
         {
             list.Add("--enable-symbol-loading");
         }
         if (this.m_PlatformProvider.developmentMode)
         {
             list.Add("--development-mode");
         }
         Il2CppNativeCodeBuilder il2CppNativeCodeBuilder = this.m_PlatformProvider.CreateIl2CppNativeCodeBuilder();
         if (il2CppNativeCodeBuilder != null)
         {
             Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder);
             list.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, this.OutputFileRelativePath(), this.m_PlatformProvider.includePaths, this.m_DebugBuild));
         }
         list.Add(string.Format("--map-file-parser=\"{0}\"", IL2CPPBuilder.GetMapFileParserPath()));
         if (array.Length > 0)
         {
             string[] array2 = array;
             for (int i = 0; i < array2.Length; i++)
             {
                 string arg2 = array2[i];
                 list.Add(string.Format("--extra-types.file=\"{0}\"", arg2));
             }
         }
         string text = Path.Combine(this.m_PlatformProvider.il2CppFolder, "il2cpp_default_extra_types.txt");
         if (File.Exists(text))
         {
             list.Add(string.Format("--extra-types.file=\"{0}\"", text));
         }
         string text2 = PlayerSettings.GetAdditionalIl2CppArgs();
         if (!string.IsNullOrEmpty(text2))
         {
             list.Add(text2);
         }
         text2 = Environment.GetEnvironmentVariable("IL2CPP_ADDITIONAL_ARGS");
         if (!string.IsNullOrEmpty(text2))
         {
             list.Add(text2);
         }
         List <string> source = new List <string>(userAssemblies);
         list.AddRange(from arg in source
                       select "--assembly=\"" + Path.GetFullPath(arg) + "\"");
         list.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(outputDirectory)));
         if (EditorUtility.DisplayCancelableProgressBar("Building Player", "Converting managed assemblies to C++", 0.3f))
         {
             throw new OperationCanceledException();
         }
         Action <ProcessStartInfo> setupStartInfo = null;
         if (il2CppNativeCodeBuilder != null)
         {
             setupStartInfo = new Action <ProcessStartInfo>(il2CppNativeCodeBuilder.SetupStartInfo);
         }
         this.RunIl2CppWithArguments(list, setupStartInfo, workingDirectory);
     }
 }