Ejemplo n.º 1
0
        public static void GenerateDependencies2(string strippedAssemblyDir, bool doStripping, out HashSet <UnityType> nativeClasses,
                                                 out HashSet <string> nativeModules)
        {
            var dataFromLinker = AssemblyStripper.ReadLinkerToEditorData(strippedAssemblyDir);

            nativeClasses = doStripping ? new HashSet <UnityType>() : null;
            nativeModules = new HashSet <string>();
            foreach (var module in dataFromLinker.report.modules)
            {
                nativeModules.Add(module.name);

                if (doStripping)
                {
                    foreach (var dependency in module.dependencies)
                    {
                        var unityType = UnityType.FindTypeByName(dependency.name);

                        if (unityType != null)
                        {
                            nativeClasses.Add(unityType);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    private bool StripAssembly(ITaskItem assemblyItem)
    {
        string assemblyFile = assemblyItem.ItemSpec;
        var    outputPath   = assemblyItem.GetMetadata("OutputPath");

        if (String.IsNullOrWhiteSpace(outputPath))
        {
            outputPath = assemblyFile;
            Log.LogMessage(MessageImportance.Low, $"[ILStrip] {assemblyFile}");
        }
        else
        {
            Log.LogMessage(MessageImportance.Low, $"[ILStrip] {assemblyFile} to {outputPath}");
        }

        try
        {
            AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyFile);
            AssemblyStripper.StripAssembly(assembly, outputPath);
        }
        catch (Exception ex)
        {
            Log.LogMessage(MessageImportance.Low, ex.ToString());
            Log.LogError($"ILStrip failed for {assemblyFile}: {ex.Message}");
            return(false);
        }

        return(true);
    }
Ejemplo n.º 3
0
    private void SetupStagingArea(BuildPostProcessArgs args, HashSet <string> filesToNotOverwrite)
    {
        List <string> cppPlugins;

        if (GetCreateSolution(args) && (args.target == BuildTarget.StandaloneWindows || args.target == BuildTarget.StandaloneWindows64))
        {
            // For Windows Standalone player solution build, we want to copy plugins for all architectures as
            // the ultimate CPU architecture choice can be made from Visual Studio
            CopyNativePlugins(args, BuildTarget.StandaloneWindows, out cppPlugins);
            CopyNativePlugins(args, BuildTarget.StandaloneWindows64, out cppPlugins);
        }
        else
        {
            CopyNativePlugins(args, args.target, out cppPlugins);
        }

        CreateApplicationData(args);

        PostprocessBuildPlayer.InstallStreamingAssets(args.stagingAreaData, args.report);

        if (GetInstallingIntoBuildsFolder(args))
        {
            CopyDataForBuildsFolder(args);
        }
        else
        {
            CopyVariationFolderIntoStagingArea(args, filesToNotOverwrite);

            if (UseIl2Cpp)
            {
                var il2cppPlatformProvider = GetPlatformProvider(args);
                IL2CPPUtils.RunIl2Cpp(args.stagingAreaData, il2cppPlatformProvider, (cppOutputDir) => CopyCppPlugins(args, cppOutputDir, cppPlugins), args.usedClassRegistry);

                if (GetCreateSolution(args))
                {
                    ProcessIl2CppOutputForSolution(args, il2cppPlatformProvider, cppPlugins);
                }
                else
                {
                    ProcessIl2CppOutputForBinary(args);
                }
            }
            else
            {
                var buildTargetGroup      = BuildPipeline.GetBuildTargetGroup(args.target);
                var managedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(buildTargetGroup);
                AssemblyStripper.StripForMonoBackend(args.target, args.usedClassRegistry, managedStrippingLevel, args.report);
            }

            RenameFilesInStagingArea(args);
        }
    }
Ejemplo n.º 4
0
    private void SetupStagingArea(BuildPostProcessArgs args, HashSet <string> filesToNotOverwrite)
    {
        List <string> cppPlugins;

        CopyNativePlugins(args, out cppPlugins);

        CreateApplicationData(args);

        PostprocessBuildPlayer.InstallStreamingAssets(args.stagingAreaData, args.report);

        if (GetInstallingIntoBuildsFolder(args))
        {
            CopyDataForBuildsFolder(args);
        }
        else
        {
            CopyVariationFolderIntoStagingArea(args);

            if (GetCreateSolution(args))
            {
                CopyPlayerSolutionIntoStagingArea(args, filesToNotOverwrite);
            }

            if (UseIl2Cpp)
            {
                var il2cppPlatformProvider = GetPlatformProvider(args);
                IL2CPPUtils.RunIl2Cpp(args.stagingAreaData, il2cppPlatformProvider, (cppOutputDir) => CopyCppPlugins(args, cppOutputDir, cppPlugins), args.usedClassRegistry);

                if (GetCreateSolution(args))
                {
                    ProcessIl2CppOutputForSolution(args, il2cppPlatformProvider, cppPlugins);
                }
                else
                {
                    ProcessIl2CppOutputForBinary(args);
                }
            }
            else
            {
                var buildTargetGroup      = BuildPipeline.GetBuildTargetGroup(args.target);
                var managedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(buildTargetGroup);
                AssemblyStripper.StripForMonoBackend(args.target, args.usedClassRegistry, managedStrippingLevel, args.report);
            }

            RenameFilesInStagingArea(args);
        }
    }
Ejemplo n.º 5
0
        LinkerConfig LinkerConfigFor(BuildPostProcessArgs args)
        {
            var namedBuildTarget = GetNamedBuildTarget(args);
            var strippingLevel   = PlayerSettings.GetManagedStrippingLevel(namedBuildTarget);

            // 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 (GetUseIl2Cpp(args) && strippingLevel == ManagedStrippingLevel.Disabled)
            {
                strippingLevel = ManagedStrippingLevel.Minimal;
            }

            if (strippingLevel > ManagedStrippingLevel.Disabled)
            {
                var rcr = args.usedClassRegistry;

                var additionalArgs = new List <string>();

                var diagArgs = Debug.GetDiagnosticSwitch("VMUnityLinkerAdditionalArgs").value as string;
                if (!string.IsNullOrEmpty(diagArgs))
                {
                    additionalArgs.Add(diagArgs.Trim('\''));
                }

                var engineStrippingFlags = new List <string>();

                if (UnityEngine.Connect.UnityConnectSettings.enabled)
                {
                    engineStrippingFlags.Add("EnableUnityConnect");
                }
                if (UnityEngine.Analytics.PerformanceReporting.enabled)
                {
                    engineStrippingFlags.Add("EnablePerformanceReporting");
                }
                if (UnityEngine.Analytics.Analytics.enabled)
                {
                    engineStrippingFlags.Add("EnableAnalytics");
                }
                if (UnityEditor.CrashReporting.CrashReportingSettings.enabled)
                {
                    engineStrippingFlags.Add("EnableCrashReporting");
                }

                NPath managedAssemblyFolderPath = $"{args.stagingAreaData}/Managed";
                var   linkerRunInformation      = new UnityLinkerRunInformation(managedAssemblyFolderPath.MakeAbsolute().ToString(), null, args.target,
                                                                                rcr, strippingLevel, null, args.report);
                AssemblyStripper.WriteEditorData(linkerRunInformation);

                return(new LinkerConfig
                {
                    LinkXmlFiles = AssemblyStripper.GetLinkXmlFiles(linkerRunInformation).ToArray(),
                    EditorToLinkerData = linkerRunInformation.EditorToLinkerDataPath.ToNPath().MakeAbsolute().ToString(),
                    AssembliesToProcess = rcr.GetUserAssemblies()
                                          .Where(s => rcr.IsDLLUsed(s))
                                          .ToArray(),
                    Runtime = GetUseIl2Cpp(args) ? "il2cpp" : "mono",
                    Profile = IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(
                        PlayerSettings.GetApiCompatibilityLevel(namedBuildTarget), args.target),
                    Ruleset = strippingLevel switch
                    {
                        ManagedStrippingLevel.Minimal => "Minimal",
                        ManagedStrippingLevel.Low => "Conservative",
                        ManagedStrippingLevel.Medium => "Aggressive",
                        ManagedStrippingLevel.High => "Experimental",
                        _ => throw new ArgumentException($"Unhandled {nameof(ManagedStrippingLevel)} value")
                    },