public void RunCompileAndLink() { Il2CppNativeCodeBuilder il2CppNativeCodeBuilder = this.m_PlatformProvider.CreateIl2CppNativeCodeBuilder(); if (il2CppNativeCodeBuilder != null) { Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder); BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(this.m_PlatformProvider.target); bool debugBuild = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup) == Il2CppCompilerConfiguration.Debug; List <string> list = Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, this.OutputFileRelativePath(), this.m_PlatformProvider.includePaths, debugBuild).ToList <string>(); list.Add(string.Format("--map-file-parser=\"{0}\"", IL2CPPBuilder.GetMapFileParserPath())); list.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(this.GetCppOutputDirectoryInStagingArea()))); if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6) { list.Add("--dotnetprofile=\"net45\""); } if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_Standard_2_0) { list.Add("--dotnetprofile=\"unityaot\""); } Action <ProcessStartInfo> setupStartInfo = new Action <ProcessStartInfo>(il2CppNativeCodeBuilder.SetupStartInfo); string fullPath = Path.GetFullPath(Path.Combine(this.m_StagingAreaData, "Managed")); this.RunIl2CppWithArguments(list, setupStartInfo, fullPath); } }
public void RunCompileAndLink() { var il2CppNativeCodeBuilder = m_PlatformProvider.CreateIl2CppNativeCodeBuilder(); if (il2CppNativeCodeBuilder != null) { Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder); var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target); var useDebugBuild = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup) == Il2CppCompilerConfiguration.Debug; var arguments = Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, OutputFileRelativePath(), m_PlatformProvider.includePaths, useDebugBuild).ToList(); arguments.Add(string.Format("--map-file-parser=\"{0}\"", GetMapFileParserPath())); arguments.Add(string.Format("--generatedcppdir=\"{0}\"", Path.GetFullPath(GetCppOutputDirectoryInStagingArea()))); 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\""); } Action <ProcessStartInfo> setupStartInfo = il2CppNativeCodeBuilder.SetupStartInfo; var managedDir = Path.GetFullPath(Path.Combine(m_StagingAreaData, "Managed")); RunIl2CppWithArguments(arguments, setupStartInfo, managedDir); } }
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(); var additionalArgs = IL2CPPUtils.GetAdditionalArguments(); if (!string.IsNullOrEmpty(additionalArgs)) { arguments.Add(additionalArgs); } arguments.Add($"--map-file-parser={CommandLineFormatter.PrepareFileName(GetMapFileParserPath())}"); arguments.Add($"--generatedcppdir={CommandLineFormatter.PrepareFileName(GetShortPathName(Path.GetFullPath(GetCppOutputDirectoryInStagingArea())))}"); arguments.Add(string.Format("--dotnetprofile=\"{0}\"", IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup)))); arguments.AddRange(IL2CPPUtils.GetDebuggerIL2CPPArguments(m_PlatformProvider, buildTargetGroup)); Action <ProcessStartInfo> setupStartInfo = il2CppNativeCodeBuilder.SetupStartInfo; var managedDir = Path.GetFullPath(Path.Combine(m_StagingAreaData, "Managed")); RunIl2CppWithArguments(arguments, setupStartInfo, managedDir); } }
// Note: We haven't exposed ScriptingDefineSymbols, ApiCompatibilityLevel, AllowUnsafeCode. Because those affect scripting compilation pipeline, this raises few questions: // - Editor will not reflect the same set compilation result as building to player, which is not very good. // - We need to either decide to have somekind of global project settings (used both in Editor and while building to player) or have // "active build settings" property which would be used as information what kind of enviromnent to simulate, in this it may make sense to but 'ScriptingDefineSymbols, ApiCompatibilityLevel, AllowUnsafeCode' here public void Initialize(BuildConfiguration.ReadOnly config) { var group = config.GetBuildTargetGroup(); if (group == BuildTargetGroup.Unknown) { return; } ScriptingBackend = PlayerSettings.GetScriptingBackend(group); Il2CppCompilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(group); }
// Note: We haven't exposed ScriptingDefineSymbols, ApiCompatibilityLevel, AllowUnsafeCode. Because those affect scripting compilation pipeline, this raises few questions: // - Editor will not reflect the same set compilation result as building to player, which is not very good. // - We need to either decide to have somekind of global project settings (used both in Editor and while building to player) or have // "active build settings" property which would be used as information what kind of enviromnent to simulate, in this it may make sense to but 'ScriptingDefineSymbols, ApiCompatibilityLevel, AllowUnsafeCode' here void ICustomBuildComponentConstructor.Construct(BuildConfiguration.ReadOnly config) { var group = config.GetBuildTargetGroup(); if (group == BuildTargetGroup.Unknown) { return; } ScriptingBackend = PlayerSettings.GetScriptingBackend(group); Il2CppCompilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(group); }
/// <summary> /// 读取相关参数 /// </summary> private static void Load2Android() { companyName = Application.companyName; prodectName = Application.productName; qualityLevel = QualitySettings.GetQualityLevel(); targetPatch = PlayerPrefs.GetString("Editor_targetPatch", "../../" + @"\Android\AESafety\"); packName = PlayerSettings.GetApplicationIdentifier(buildTargetGroup); script = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android); targetSdkVersion = PlayerSettings.Android.targetSdkVersion; minSdkVersion = PlayerSettings.Android.minSdkVersion; scriptingRuntimeVersion = PlayerSettings.scriptingRuntimeVersion; scriptingBackend = PlayerSettings.GetScriptingBackend(buildTargetGroup); il2CppCompilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup); }
public void RunCompileAndLink(string il2cppBuildCacheSource) { if (string.Equals(Path.GetFullPath(il2cppBuildCacheSource), Path.GetFullPath(m_PlatformProvider.il2cppBuildCacheDirectory), StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("IIl2CppPlatformProvider.il2cppBuildCacheDirectory cannot be the same as il2cppBuildCacheDirectory. You probably forgot to override il2cppBuildCacheDirectory on your IIl2CppPlatformProvider."); } var il2CppNativeCodeBuilder = m_PlatformProvider.CreateIl2CppNativeCodeBuilder(); if (il2CppNativeCodeBuilder != null) { Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder); var buildCacheDirectory = m_PlatformProvider.il2cppBuildCacheDirectory; Directory.CreateDirectory(buildCacheDirectory); var buildCacheNativeOutputFile = Path.Combine(GetNativeOutputRelativeDirectory(buildCacheDirectory), m_PlatformProvider.nativeLibraryFileName); var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target); var compilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup); var arguments = Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, buildCacheNativeOutputFile, m_PlatformProvider.includePaths, m_PlatformProvider.libraryPaths, compilerConfiguration).ToList(); var additionalArgs = IL2CPPUtils.GetAdditionalArguments(); if (!string.IsNullOrEmpty(additionalArgs)) { arguments.Add(additionalArgs); } foreach (var buildingArgument in IL2CPPUtils.GetBuildingIL2CPPArguments(m_PlatformProvider, buildTargetGroup)) { if (!arguments.Contains(buildingArgument)) { arguments.Add(buildingArgument); } } arguments.Add($"--generatedcppdir={CommandLineFormatter.PrepareFileName(GetCppOutputDirectory(il2cppBuildCacheSource))}"); arguments.Add($"--dotnetprofile=\"{IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup), m_PlatformProvider.target)}\""); arguments.AddRange(IL2CPPUtils.GetDebuggerIL2CPPArguments(m_PlatformProvider, buildTargetGroup)); Action <ProcessStartInfo> setupStartInfo = il2CppNativeCodeBuilder.SetupStartInfo; RunIl2CppWithArguments(arguments, setupStartInfo); } }
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); }
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); }
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 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); }
private static void DoBuildAndroidInternal(Il2CppCompilerConfiguration compilerConfiguration) { Debug.Log("Building Android..."); CurrentGroup = BuildTargetGroup.Android; var prevCompilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(BuildTargetGroup.Android); var prevScriptingDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android); var isDebug = !(compilerConfiguration == Il2CppCompilerConfiguration.Master); using var revertSettings = new Disposable(() => { CurrentGroup = null; PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, prevCompilerConfiguration); if (!Application.isBatchMode) { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, prevScriptingDefines); } }); PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, compilerConfiguration); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, ProcessDefines(prevScriptingDefines, isDebug)); string exportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../android/UnityExport")); string buildPath = androidBuildPath; if (Directory.Exists(buildPath)) { Directory.Delete(buildPath, true); } EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle; EditorUserBuildSettings.exportAsGoogleAndroidProject = true; try { var options = (compilerConfiguration == Il2CppCompilerConfiguration.Debug ? BuildOptions.AllowDebugging : BuildOptions.None); var report = BuildPipeline.BuildPlayer( GetEnabledScenes(), buildPath, BuildTarget.Android, options); if (report.summary.result != BuildResult.Succeeded) { throw new Exception("Build failed"); } // Modify build.gradle { Debug.Log("Patch launcher/build.gradle"); var launcher_build_file = Path.Combine(buildPath, "launcher/build.gradle"); var launcher_build_text = File.ReadAllText(launcher_build_file); Debug.Log("Patch unityLibrary/build.gradle"); var build_file = Path.Combine(buildPath, "unityLibrary/build.gradle"); var build_text = File.ReadAllText(build_file); build_text = build_text.Replace("com.android.application", "com.android.library"); build_text = Regex.Replace(build_text, @"\n.*applicationId '.+'.*\n", "\n"); build_text = Regex.Replace(build_text, @":unityLibrary", ":UnityExport"); build_text = Regex.Replace(build_text, @"dependencies\s+\{[^\}]+\}", d => { var value = d.Value; value = Regex.Replace(value, @"(\s+)(implementation project)([^\n]+)'([^\n]+)('[^\n]+)", m => m.Groups[1].Value + "api project(':" + m.Groups[4].Value + m.Groups[5].Value); value = Regex.Replace(value, @"(\s+)(compile)([^\n]+\n)", m => m.Groups[1].Value + "api" + m.Groups[3].Value); value = Regex.Replace(value, @"(\s+)(implementation)([^\n]+\n)", m => m.Groups[1].Value + "api" + m.Groups[3].Value); value = Regex.Replace(value, @"(\s+)api.+appcenter-release.+", m => m.Groups[1].Value + "api 'com.microsoft.appcenter:appcenter:+'"); value = Regex.Replace(value, @"(\s+)api.+appcenter-analytics-release.+", m => m.Groups[1].Value + "api 'com.microsoft.appcenter:appcenter-analytics:+'"); value = Regex.Replace(value, @"(\s+)api.+appcenter-crashes-release.+", m => m.Groups[1].Value + "api 'com.microsoft.appcenter:appcenter-crashes:+'"); return(value); }); build_text = Regex.Replace(build_text, @"\s*def BuildIl2Cpp\([^\(\)\{\}]*\)\s*\{", d => { var builder = new StringBuilder(); builder.AppendLine(); builder.AppendLine("def getUnityDir() {"); builder.AppendLine(" Properties local = new Properties()"); builder.AppendLine(" local.load(new FileInputStream(\"${rootDir}/local.properties\"))"); builder.AppendLine(" return local.getProperty('unity.dir')"); builder.AppendLine("}"); builder.AppendLine(d.Groups[0].Value); builder.AppendLine(" String il2cppPath = getUnityDir();"); builder.AppendLine(" if (!il2cppPath) {"); builder.AppendLine(" il2cppPath = workingDir + \"/src/main/Il2CppOutputProject\""); builder.AppendLine(" }"); return(builder.ToString()); }); build_text = Regex.Replace( build_text, "commandLine\\(workingDir\\s*\\+\\s*\"/src/main/Il2CppOutputProject/IL2CPP/build/deploy/netcoreapp3\\.1/il2cpp\\.exe\",", "commandLine(il2cppPath + \"/IL2CPP/build/deploy/netcoreapp3.1/il2cpp\","); build_text = CopyGradleBlock( launcher_build_text, build_text, @"(\s+aaptOptions\s+\{[^\}]+\})", @"(android\s+\{)(([^\}]+)+)", overwrite: false); build_text = CopyGradleBlock( launcher_build_text, build_text, @"(\s+buildTypes\s+\{([^\{\}]+\{[^\{\}]+\}[^\{\}]+)+\})", @"(android\s+\{)(([^\}]+)+)", overwrite: false); File.WriteAllText(build_file, build_text); } // Modify AndroidManifest.xml Debug.Log("Patch AndroidManifest.xml"); var manifest_file = Path.Combine(buildPath, "unityLibrary/src/main/AndroidManifest.xml"); var manifest_text = File.ReadAllText(manifest_file); manifest_text = Regex.Replace(manifest_text, @"\s*<uses-sdk[^>]*/>", ""); manifest_text = Regex.Replace(manifest_text, @"<application .*>", "<application>"); Regex regex = new Regex(@"<activity.*>(\s|\S)+?</activity>", RegexOptions.Multiline); manifest_text = regex.Replace(manifest_text, ""); File.WriteAllText(manifest_file, manifest_text); // Clear UnityExport DeleteFolderContent(exportPath); // Copy build output to UnityExport Debug.Log("Copy to UnityExport"); CopyDirectory( buildPath, exportPath, mergeDirectories: false, overwriteFiles: true); // Copy local.properties Debug.Log("Copy local.properties"); CopyFile( Path.Combine(exportPath, "local.properties"), Path.Combine(exportPath, "../local.properties"), overwriteFiles: true); // Copy gradle.properties Debug.Log("Copy gradle.properties"); CopyFile( Path.Combine(exportPath, "gradle.properties"), Path.Combine(exportPath, "unityLibrary/gradle.properties"), overwriteFiles: true); // Copy some files from 'launcher' project Debug.Log("Copy resources"); CopyDirectory( Path.Combine(exportPath, "launcher/src/main/res"), Path.Combine(exportPath, "unityLibrary/src/main/res"), mergeDirectories: true, overwriteFiles: true); } catch (Exception e) { Debug.Log("Export failed!"); if (Application.isBatchMode) { Debug.LogError(e); EditorApplication.Exit(-1); } else { throw; } } finally { Debug.Log("Export completed!"); if (Application.isBatchMode) { EditorApplication.Exit(0); } } }
private static void DoBuildIOSInternal(iOSBuildType buildType, iOSSdkVersion sdkVersion) { Debug.Log("Building iOS..."); CurrentGroup = BuildTargetGroup.iOS; var xrGeneralSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.iOS); var prevCompilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(BuildTargetGroup.iOS); var prevScriptingDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS); var prev_sdkVersion = PlayerSettings.iOS.sdkVersion; var isDebug = !(buildType == iOSBuildType.Debug); var disabledARKit = false; using var revertSettings = new Disposable(() => { CurrentGroup = null; PlayerSettings.iOS.sdkVersion = prev_sdkVersion; PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, prevCompilerConfiguration); if (!Application.isBatchMode) { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, prevScriptingDefines); } if (disabledARKit) { XRPackageMetadataStore.AssignLoader( xrGeneralSettings.AssignedSettings, typeof(UnityEngine.XR.ARKit.ARKitLoader).FullName, BuildTargetGroup.iOS); } }); var compilerConfiguration = isDebug ? Il2CppCompilerConfiguration.Debug : Il2CppCompilerConfiguration.Master; PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, compilerConfiguration); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, ProcessDefines(prevScriptingDefines, isDebug)); PlayerSettings.iOS.sdkVersion = sdkVersion; if (sdkVersion == iOSSdkVersion.SimulatorSDK && xrGeneralSettings.AssignedSettings.activeLoaders.Any(m => m.GetType() == typeof(UnityEngine.XR.ARKit.ARKitLoader))) { // ARKit is not supported on iOS Simulator - disable it temporairly XRPackageMetadataStore.RemoveLoader( xrGeneralSettings.AssignedSettings, typeof(UnityEngine.XR.ARKit.ARKitLoader).FullName, BuildTargetGroup.iOS); disabledARKit = true; } string exportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../ios/UnityExport")); string buildPath = iosBuildPath; if (Directory.Exists(buildPath)) { Directory.Delete(buildPath, true); } EditorUserBuildSettings.iOSBuildConfigType = buildType; try { var options = (buildType == iOSBuildType.Debug ? BuildOptions.AllowDebugging : BuildOptions.None); var report = BuildPipeline.BuildPlayer( GetEnabledScenes(), buildPath, BuildTarget.iOS, options ); if (report.summary.result != BuildResult.Succeeded) { throw new Exception("Build failed"); } // Clear UnityExport DeleteFolderContent(exportPath); // Copy build output to UnityExport Debug.Log("Copy to UnityExport"); CopyDirectory( buildPath, exportPath, mergeDirectories: false, overwriteFiles: true); } catch (Exception e) { Debug.Log("Export failed!"); if (Application.isBatchMode) { Debug.LogError(e); EditorApplication.Exit(-1); } else { throw; } } finally { Debug.Log("Export completed!"); if (Application.isBatchMode) { EditorApplication.Exit(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"); } if (this.m_BuildForMonoRuntime) { list.Add("--mono-runtime"); } BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(this.m_PlatformProvider.target); if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6) { list.Add("--dotnetprofile=\"net45\""); } if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_Standard_2_0) { list.Add("--dotnetprofile=\"unityaot\""); } Il2CppNativeCodeBuilder il2CppNativeCodeBuilder = this.m_PlatformProvider.CreateIl2CppNativeCodeBuilder(); if (il2CppNativeCodeBuilder != null) { bool debugBuild = PlayerSettings.GetIl2CppCompilerConfiguration(buildTargetGroup) == Il2CppCompilerConfiguration.Debug; Il2CppNativeCodeBuilderUtils.ClearAndPrepareCacheDirectory(il2CppNativeCodeBuilder); list.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, this.OutputFileRelativePath(), this.m_PlatformProvider.includePaths, 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); } }
/// <summary> /// 実行する時に呼び出されます /// </summary> protected override BuildCommandResult DoRun() { m_oldConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(m_targetGroup); PlayerSettings.SetIl2CppCompilerConfiguration(m_targetGroup, m_configuration); return(Success(m_configuration.ToString())); }