GenerateDependencies() public static method

public static GenerateDependencies ( string strippedAssemblyDir, RuntimeClassRegistry rcr, HashSet &nativeClasses, HashSet &nativeModules ) : void
strippedAssemblyDir string
rcr RuntimeClassRegistry
nativeClasses HashSet
nativeModules HashSet
return void
Ejemplo n.º 1
0
        public static void WriteModuleAndClassRegistrationFile(string strippedAssemblyDir, string icallsListFile, string outputDir, RuntimeClassRegistry rcr, IEnumerable <string> classesToSkip)
        {
            HashSet <string> nativeClasses;
            HashSet <string> nativeModules;

            CodeStrippingUtils.GenerateDependencies(strippedAssemblyDir, icallsListFile, rcr, out nativeClasses, out nativeModules);
            CodeStrippingUtils.WriteModuleAndClassRegistrationFile(Path.Combine(outputDir, "UnityClassRegistration.cpp"), nativeModules, nativeClasses, new HashSet <string>(classesToSkip));
        }
Ejemplo n.º 2
0
        public static void WriteModuleAndClassRegistrationFile(string strippedAssemblyDir, string icallsListFile, string outputDir, RuntimeClassRegistry rcr, IEnumerable <UnityType> classesToSkip, IIl2CppPlatformProvider platformProvider)
        {
            bool stripEngineCode = PlayerSettings.stripEngineCode;
            HashSet <UnityType> nativeClasses;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(strippedAssemblyDir, icallsListFile, rcr, stripEngineCode, out nativeClasses, out nativeModules, platformProvider);
            string file = Path.Combine(outputDir, "UnityClassRegistration.cpp");

            CodeStrippingUtils.WriteModuleAndClassRegistrationFile(file, nativeModules, nativeClasses, new HashSet <UnityType>(classesToSkip));
        }
        static public void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file,
                                                                            CrossCompileOptions crossCompileOptions,
                                                                            bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry,
                                                                            AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider)
        {
            // generate the Interal Call Summary file
            var icallSummaryPath = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            var dlls             = Directory.GetFiles(stagingAreaDataManaged, "UnityEngine.*Module.dll").Concat(new[] { Path.Combine(stagingAreaDataManaged, "UnityEngine.dll") });
            var exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            var args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"",
                                     dlls.Aggregate((dllArg, next) => dllArg + ";" + next), icallSummaryPath
                                     );

            Runner.RunManagedProgram(exe, args);

            HashSet <UnityType> nativeClasses;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), icallSummaryPath, usedClassRegistry, stripping, out nativeClasses, out nativeModules, platformProvider);

            using (TextWriter w = new StreamWriter(file))
            {
                string[]             fileNames  = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblies = checker.GetAssemblyDefinitions();

                bool fastICall = (crossCompileOptions & CrossCompileOptions.FastICall) != 0;

                ArrayList nativeMethods = BuildNativeMethodList(assemblies);

                if (buildTarget == BuildTarget.iOS)
                {
                    w.WriteLine("#include \"RegisterMonoModules.h\"");
                    w.WriteLine("#include <stdio.h>");
                }

                w.WriteLine("");
                w.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                w.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                w.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
                w.WriteLine("        do {\\");
                w.WriteLine("        if(f != NULL)\\");
                w.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
                w.WriteLine("        else\\");
                w.WriteLine("            ::printf_console(\"Symbol \'%s\' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                w.WriteLine("        }while(0)");
                w.WriteLine("#else");
                w.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                w.WriteLine("    #if !defined(__arm64__)");
                w.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                w.WriteLine("    #else");
                w.WriteLine("        #define REGISTER_USER_FUNC(f)");
                w.WriteLine("    #endif");
                w.WriteLine("#endif");
                w.WriteLine("extern \"C\"\n{");

                w.WriteLine("    typedef void* gpointer;");
                w.WriteLine("    typedef int gboolean;");

                if (buildTarget == BuildTarget.iOS)
                {
                    w.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    w.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");

                    w.WriteLine("#if !defined(__arm64__)");
                    w.WriteLine("    extern int          mono_ficall_flag;");
                    w.WriteLine("#endif");
                }

                w.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");

                w.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                w.WriteLine("#define DLL_EXPORT __declspec(dllexport)"); // ps4 and psp2 need dllexport.
                w.WriteLine("#else");
                w.WriteLine("#define DLL_EXPORT");
                w.WriteLine("#endif");

                w.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                w.WriteLine("    extern gboolean     mono_aot_only;");

                for (int q = 0; q < fileNames.Length; ++q)
                {
                    string fileName     = fileNames[q];
                    string assemblyName = assemblies[q].Name.Name;
                    assemblyName = assemblyName.Replace(".", "_");
                    assemblyName = assemblyName.Replace("-", "_");
                    assemblyName = assemblyName.Replace(" ", "_");

                    w.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", assemblyName, fileName);
                }
                w.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                foreach (string nmethod in nativeMethods)
                {
                    w.WriteLine("    DECL_USER_FUNC({0});", nmethod);
                }
                w.WriteLine("}");

                w.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                w.WriteLine("{");

                w.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                w.WriteLine("    mono_aot_only = true;");

                if (buildTarget == BuildTarget.iOS)
                {
                    w.WriteLine("    mono_ficall_flag = {0};", fastICall ? "true" : "false");
                }

                foreach (AssemblyDefinition definition in assemblies)
                {
                    string assemblyName = definition.Name.Name;
                    assemblyName = assemblyName.Replace(".", "_");
                    assemblyName = assemblyName.Replace("-", "_");
                    assemblyName = assemblyName.Replace(" ", "_");
                    w.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", assemblyName);
                }

                w.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                w.WriteLine("");

                if (buildTarget == BuildTarget.iOS)
                {
                    foreach (string nmethod in nativeMethods)
                    {
                        w.WriteLine("    REGISTER_USER_FUNC({0});", nmethod);
                    }
                }
                w.WriteLine("}");
                w.WriteLine("");


                if (buildTarget == BuildTarget.iOS)
                {
                    var inputAssemblies = new List <AssemblyDefinition>();

                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        if (AssemblyHelper.IsUnityEngineModule(assemblies[i]))
                        {
                            inputAssemblies.Add(assemblies[i]);
                        }
                    }

                    GenerateRegisterInternalCalls(inputAssemblies.ToArray(), w);

                    GenerateRegisterModules(nativeClasses, nativeModules, w, stripping);

                    if (stripping && usedClassRegistry != null)
                    {
                        GenerateRegisterClassesForStripping(nativeClasses, w);
                    }
                    else
                    {
                        GenerateRegisterClasses(nativeClasses, w);
                    }
                }

                w.Close();
            }
        }
Ejemplo n.º 4
0
        public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged)
        {
            HashSet <UnityType> set;
            HashSet <string>    set2;
            string str  = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            string exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            string args = $"-assembly=" { Path.Combine(stagingAreaDataManaged, "UnityEngine.dll") } " -summary=" { str } "";

            Runner.RunManagedProgram(exe, args);
            CodeStrippingUtils.GenerateDependencies(Path.GetFullPath(stagingAreaDataManaged), str, usedClassRegistry, stripping, out set, out set2, null);
            using (TextWriter writer = new StreamWriter(file))
            {
                string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
                bool      flag = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
                ArrayList list = BuildNativeMethodList(assemblyDefinitions);
                if (buildTarget == BuildTarget.iOS)
                {
                    writer.WriteLine("#include \"RegisterMonoModules.h\"");
                    writer.WriteLine("#include <stdio.h>");
                }
                writer.WriteLine("");
                writer.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                writer.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                writer.WriteLine(@"    #define REGISTER_USER_FUNC(f)\");
                writer.WriteLine(@"        do {\");
                writer.WriteLine(@"        if(f != NULL)\");
                writer.WriteLine(@"            mono_dl_register_symbol(#f, (void*)f);\");
                writer.WriteLine(@"        else\");
                writer.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                writer.WriteLine("        }while(0)");
                writer.WriteLine("#else");
                writer.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                writer.WriteLine("    #if !defined(__arm64__)");
                writer.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                writer.WriteLine("    #else");
                writer.WriteLine("        #define REGISTER_USER_FUNC(f)");
                writer.WriteLine("    #endif");
                writer.WriteLine("#endif");
                writer.WriteLine("extern \"C\"\n{");
                writer.WriteLine("    typedef void* gpointer;");
                writer.WriteLine("    typedef int gboolean;");
                if (buildTarget == BuildTarget.iOS)
                {
                    writer.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    writer.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
                    writer.WriteLine("#if !defined(__arm64__)");
                    writer.WriteLine("    extern int          mono_ficall_flag;");
                    writer.WriteLine("#endif");
                }
                writer.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
                writer.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                writer.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
                writer.WriteLine("#else");
                writer.WriteLine("#define DLL_EXPORT");
                writer.WriteLine("#endif");
                writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                writer.WriteLine("    extern gboolean     mono_aot_only;");
                for (int i = 0; i < assemblyFileNames.Length; i++)
                {
                    string str4 = assemblyFileNames[i];
                    string str5 = assemblyDefinitions[i].Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
                    writer.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", str5, str4);
                }
                writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                IEnumerator enumerator = list.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string current = (string)enumerator.Current;
                        writer.WriteLine("    DECL_USER_FUNC({0});", current);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                writer.WriteLine("}");
                writer.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                writer.WriteLine("{");
                writer.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                writer.WriteLine("    mono_aot_only = true;");
                if (buildTarget == BuildTarget.iOS)
                {
                    writer.WriteLine("    mono_ficall_flag = {0};", !flag ? "false" : "true");
                }
                foreach (AssemblyDefinition definition in assemblyDefinitions)
                {
                    string str7 = definition.Name.Name.Replace(".", "_").Replace("-", "_").Replace(" ", "_");
                    writer.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", str7);
                }
                writer.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                writer.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    IEnumerator enumerator2 = list.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string str8 = (string)enumerator2.Current;
                            writer.WriteLine("    REGISTER_USER_FUNC({0});", str8);
                        }
                    }
                    finally
                    {
                        IDisposable disposable2 = enumerator2 as IDisposable;
                        if (disposable2 != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
                writer.WriteLine("}");
                writer.WriteLine("");
                AssemblyDefinition unityEngine = null;
                for (int j = 0; j < assemblyFileNames.Length; j++)
                {
                    if (assemblyFileNames[j] == "UnityEngine.dll")
                    {
                        unityEngine = assemblyDefinitions[j];
                    }
                }
                if (buildTarget == BuildTarget.iOS)
                {
                    AssemblyDefinition[] assemblies = new AssemblyDefinition[] { unityEngine };
                    GenerateRegisterInternalCalls(assemblies, writer);
                    ResolveDefinedNativeClassesFromMono(assemblies, usedClassRegistry);
                    ResolveReferencedUnityEngineClassesFromMono(assemblyDefinitions, unityEngine, usedClassRegistry);
                    GenerateRegisterModules(set, set2, writer, stripping);
                    if (stripping && (usedClassRegistry != null))
                    {
                        GenerateRegisterClassesForStripping(set, writer);
                    }
                    else
                    {
                        GenerateRegisterClasses(set, writer);
                    }
                }
                writer.Close();
            }
        }
Ejemplo n.º 5
0
        public static void WriteCPlusPlusFileForStaticAOTModuleRegistration(BuildTarget buildTarget, string file, CrossCompileOptions crossCompileOptions, bool advancedLic, string targetDevice, bool stripping, RuntimeClassRegistry usedClassRegistry, AssemblyReferenceChecker checker, string stagingAreaDataManaged, IIl2CppPlatformProvider platformProvider)
        {
            string text = Path.Combine(stagingAreaDataManaged, "ICallSummary.txt");
            string exe  = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Tools/InternalCallRegistrationWriter/InternalCallRegistrationWriter.exe");
            string args = string.Format("-assembly=\"{0}\" -summary=\"{1}\"", Path.Combine(stagingAreaDataManaged, "UnityEngine.dll"), text);

            Runner.RunManagedProgram(exe, args);
            HashSet <UnityType> hashSet;
            HashSet <string>    nativeModules;

            CodeStrippingUtils.GenerateDependencies(Path.GetDirectoryName(stagingAreaDataManaged), text, usedClassRegistry, stripping, out hashSet, out nativeModules, platformProvider);
            using (TextWriter textWriter = new StreamWriter(file))
            {
                string[]             assemblyFileNames   = checker.GetAssemblyFileNames();
                AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
                bool      flag      = (crossCompileOptions & CrossCompileOptions.FastICall) != CrossCompileOptions.Dynamic;
                ArrayList arrayList = MonoAOTRegistration.BuildNativeMethodList(assemblyDefinitions);
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("#include \"RegisterMonoModules.h\"");
                    textWriter.WriteLine("#include <stdio.h>");
                }
                textWriter.WriteLine("");
                textWriter.WriteLine("#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() __attribute__((weak_import))");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f)\\");
                textWriter.WriteLine("        do {\\");
                textWriter.WriteLine("        if(f != NULL)\\");
                textWriter.WriteLine("            mono_dl_register_symbol(#f, (void*)f);\\");
                textWriter.WriteLine("        else\\");
                textWriter.WriteLine("            ::printf_console(\"Symbol '%s' not found. Maybe missing implementation for Simulator?\\n\", #f);\\");
                textWriter.WriteLine("        }while(0)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("    #define DECL_USER_FUNC(f) void f() ");
                textWriter.WriteLine("    #if !defined(__arm64__)");
                textWriter.WriteLine("    #define REGISTER_USER_FUNC(f) mono_dl_register_symbol(#f, (void*)&f)");
                textWriter.WriteLine("    #else");
                textWriter.WriteLine("        #define REGISTER_USER_FUNC(f)");
                textWriter.WriteLine("    #endif");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("extern \"C\"\n{");
                textWriter.WriteLine("    typedef void* gpointer;");
                textWriter.WriteLine("    typedef int gboolean;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    const char*         UnityIPhoneRuntimeVersion = \"{0}\";", Application.unityVersion);
                    textWriter.WriteLine("    void                mono_dl_register_symbol (const char* name, void *addr);");
                    textWriter.WriteLine("#if !defined(__arm64__)");
                    textWriter.WriteLine("    extern int          mono_ficall_flag;");
                    textWriter.WriteLine("#endif");
                }
                textWriter.WriteLine("    void                mono_aot_register_module(gpointer *aot_info);");
                textWriter.WriteLine("#if __ORBIS__ || SN_TARGET_PSP2");
                textWriter.WriteLine("#define DLL_EXPORT __declspec(dllexport)");
                textWriter.WriteLine("#else");
                textWriter.WriteLine("#define DLL_EXPORT");
                textWriter.WriteLine("#endif");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR)");
                textWriter.WriteLine("    extern gboolean     mono_aot_only;");
                for (int i = 0; i < assemblyFileNames.Length; i++)
                {
                    string arg   = assemblyFileNames[i];
                    string text2 = assemblyDefinitions[i].Name.Name;
                    text2 = text2.Replace(".", "_");
                    text2 = text2.Replace("-", "_");
                    text2 = text2.Replace(" ", "_");
                    textWriter.WriteLine("    extern gpointer*    mono_aot_module_{0}_info; // {1}", text2, arg);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR)");
                IEnumerator enumerator = arrayList.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        string arg2 = (string)enumerator.Current;
                        textWriter.WriteLine("    DECL_USER_FUNC({0});", arg2);
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("DLL_EXPORT void RegisterMonoModules()");
                textWriter.WriteLine("{");
                textWriter.WriteLine("#if !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("    mono_aot_only = true;");
                if (buildTarget == BuildTarget.iOS)
                {
                    textWriter.WriteLine("    mono_ficall_flag = {0};", (!flag) ? "false" : "true");
                }
                AssemblyDefinition[] array = assemblyDefinitions;
                for (int j = 0; j < array.Length; j++)
                {
                    AssemblyDefinition assemblyDefinition = array[j];
                    string             text3 = assemblyDefinition.Name.Name;
                    text3 = text3.Replace(".", "_");
                    text3 = text3.Replace("-", "_");
                    text3 = text3.Replace(" ", "_");
                    textWriter.WriteLine("    mono_aot_register_module(mono_aot_module_{0}_info);", text3);
                }
                textWriter.WriteLine("#endif // !(TARGET_IPHONE_SIMULATOR) && !defined(__arm64__)");
                textWriter.WriteLine("");
                if (buildTarget == BuildTarget.iOS)
                {
                    IEnumerator enumerator2 = arrayList.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            string arg3 = (string)enumerator2.Current;
                            textWriter.WriteLine("    REGISTER_USER_FUNC({0});", arg3);
                        }
                    }
                    finally
                    {
                        IDisposable disposable2;
                        if ((disposable2 = (enumerator2 as IDisposable)) != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                }
                textWriter.WriteLine("}");
                textWriter.WriteLine("");
                AssemblyDefinition assemblyDefinition2 = null;
                for (int k = 0; k < assemblyFileNames.Length; k++)
                {
                    if (assemblyFileNames[k] == "UnityEngine.dll")
                    {
                        assemblyDefinition2 = assemblyDefinitions[k];
                    }
                }
                if (buildTarget == BuildTarget.iOS)
                {
                    AssemblyDefinition[] assemblies = new AssemblyDefinition[]
                    {
                        assemblyDefinition2
                    };
                    MonoAOTRegistration.GenerateRegisterInternalCalls(assemblies, textWriter);
                    MonoAOTRegistration.GenerateRegisterModules(hashSet, nativeModules, textWriter, stripping);
                    if (stripping && usedClassRegistry != null)
                    {
                        MonoAOTRegistration.GenerateRegisterClassesForStripping(hashSet, textWriter);
                    }
                    else
                    {
                        MonoAOTRegistration.GenerateRegisterClasses(hashSet, textWriter);
                    }
                }
                textWriter.Close();
            }
        }