Пример #1
0
        public NativeProgram NativeProgramForIL2CPPOutputFor(string nativeProgramName, IL2CPPPlatformBeeSupport platformSupport, NPath[] il2cppOutputFiles)
        {
            var nativeProgramForIl2CppOutput = NativeProgramForIL2CPPOutput(nativeProgramName, il2cppOutputFiles, platformSupport);

            return(nativeProgramForIl2CppOutput);
        }
Пример #2
0
        private NativeProgram NativeProgramForIL2CPPOutput(string nativeProgramName, NPath[] il2cppOutputFiles, IL2CPPPlatformBeeSupport platformSupport, bool managedDebuggingEnabled = true, bool libil2cpptiny = false)
        {
            var il2cppPlayerPackageDirectory = _incrementalClassicSharedData.PlayerPackageDirectory.Combine("il2cpp");
            var nativeProgram = new NativeProgram(nativeProgramName)
            {
                Sources            = { il2cppOutputFiles },
                Exceptions         = { true },
                IncludeDirectories =
                {
                    il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine("libil2cpp/include") : Distribution.Path.Combine("libil2cpp"),
                    il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine("external/baselib/include") : Distribution.Path.Combine("external/baselib/include"),
                    c => il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include") : Distribution.Path.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include")
                },
                Defines = { "BASELIB_INLINE_NAMESPACE=il2cpp_baselib", "RUNTIME_IL2CPP=1" }
            };

            nativeProgram.Libraries.Add(c => CreateLibIl2CppProgram(!libil2cpptiny, platformSupport, managedDebuggingEnabled, libil2cpptiny ? "libil2cpptiny" : "libil2cpp"));

            nativeProgram.Libraries.Add(c => c.ToolChain.Platform is WindowsPlatform &&
                                        _incrementalClassicSharedData.VariationDirectory.Combine("baselib.dll.lib").Exists(),
                                        new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("baselib.dll.lib")));
            nativeProgram.Libraries.Add(c => c.ToolChain.Platform is AndroidPlatform && c.ToolChain.Architecture is Arm64Architecture &&
                                        _incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/arm64-v8a/baselib.a").Exists(),
                                        new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/arm64-v8a/baselib.a")));
            nativeProgram.Libraries.Add(c => c.ToolChain.Platform is AndroidPlatform && c.ToolChain.Architecture is ARMv7Architecture &&
                                        _incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/armeabi-v7a/baselib.a").Exists(),
                                        new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/armeabi-v7a/baselib.a")));
            nativeProgram.Libraries.Add(c => c.ToolChain.Platform is MacOSXPlatform &&
                                        _incrementalClassicSharedData.VariationDirectory.Combine("baselib.a").Exists(),
                                        new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("baselib.a")));
            nativeProgram.Libraries.Add(c => c.ToolChain.Platform is IosPlatform &&
                                        _incrementalClassicSharedData.PlayerPackageDirectory.Combine("Trampoline/Libraries/baselib-dev.a").Exists(),
                                        new StaticLibrary(_incrementalClassicSharedData.PlayerPackageDirectory.Combine("Trampoline", "Libraries", "baselib-dev.a")));

            if (il2cppPlayerPackageDirectory.Combine("libil2cpp/include/pch").Exists() || Distribution.Path.Combine("libil2cpp/pch").Exists())
            {
                var libil2cppDir     = il2cppPlayerPackageDirectory.Combine("libil2cpp/include").Exists() ? il2cppPlayerPackageDirectory.Combine("libil2cpp/include") : Distribution.Path.Combine("libil2cpp");
                var libil2cpptinyDir = il2cppPlayerPackageDirectory.Combine("libil2cpptiny/include").Exists() ? il2cppPlayerPackageDirectory.Combine("libil2cpptiny/include") : Distribution.Path.Combine("libil2cpptiny");

                if (libil2cpptiny)
                {
                    nativeProgram.Defines.Add("IL2CPP_TINY");
                    if (managedDebuggingEnabled)
                    {
                        nativeProgram.IncludeDirectories.Add(libil2cppDir.Combine("pch"));

                        nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-cpp.hpp"),
                                                      nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".cpp")));
                        nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-c.h"),
                                                      nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".c")));
                    }
                    else
                    {
                        // Tiny needs to be able to find its include directory before libil2cpp
                        nativeProgram.IncludeDirectories.AddFront(libil2cpptinyDir);
                        nativeProgram.IncludeDirectories.AddFront(libil2cpptinyDir.Combine("pch"));

                        nativeProgram.PerFilePchs.Add(libil2cpptinyDir.Combine("pch/pch-cpp.hpp"),
                                                      nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".cpp")));
                    }
                }
                else
                {
                    nativeProgram.IncludeDirectories.Add(libil2cppDir.Combine("pch"));

                    nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-cpp.hpp"),
                                                  nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".cpp")));
                    nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-c.h"),
                                                  nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".c")));
                }
            }

            nativeProgram.CompilerSettings().Add(s => s.WithCppLanguageVersion(CppLanguageVersion.Cpp11));
            nativeProgram.CompilerSettingsForMsvc()
            .Add(c => c.WithCustomFlags(new[] { "/EHs" }));
            nativeProgram.CompilerSettingsForMsvc()
            .Add(c => c.WithWarningPolicies(new[] { new WarningAndPolicy("4102", WarningPolicy.Silent) }));
            // nativeProgram.CompilerSettingsForMsvc()
            //     .Add(c => c.WithPDB(_incrementalClassicSharedData.BeeProjectRoot.Combine("libil2cpp.pdb")));
            nativeProgram.CompilerSettingsForClang().Add(c => c.WithWarningPolicies(new[] { new WarningAndPolicy("pragma-once-outside-header", WarningPolicy.Silent) }));
            if (platformSupport != null)
            {
                platformSupport.ProvideNativeProgramSettings(nativeProgram);
            }

            nativeProgram.NonLumpableFiles.Add(nativeProgram.Sources.ForAny());

            return(nativeProgram);
        }
Пример #3
0
        private NativeProgramAsLibrary CreateLibIl2CppProgram(bool useExceptions, IL2CPPPlatformBeeSupport platformSupport, bool managedDebuggingEnabled = true, string libil2cppname = "libil2cpp")
        {
            NPath[] fileList;
            if (libil2cppname == "libil2cpptiny" && managedDebuggingEnabled)
            {
                fileList = Distribution.GetFileList("libil2cpp").ToArray();
            }
            else
            {
                fileList = Distribution.GetFileList(libil2cppname).ToArray();
            }
            var nPaths = fileList.Where(f => f.Parent.FileName != "pch" && f.HasExtension("cpp")).ToArray();

            var il2cppPlayerPackageDirectory = _incrementalClassicSharedData.PlayerPackageDirectory.Combine("il2cpp");

            var program = new NativeProgram(libil2cppname)
            {
                Sources    = { nPaths },
                Exceptions = { useExceptions },
                PublicIncludeDirectories =
                {
                    Distribution.Path.Combine("libil2cpp")
                },
                IncludeDirectories =
                {
                    il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine("external/baselib/include") : Distribution.Path.Combine("external/baselib/include"),
                    c => il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include") : Distribution.Path.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include"),
                    Distribution.Path.Combine("external/mono/mono/eglib"),
                    Distribution.Path.Combine("external/mono/mono"),
                    Distribution.Path.Combine("external/mono/"),
                    Distribution.Path.Combine("external/mono/mono/sgen"),
                    Distribution.Path.Combine("external/mono/mono/utils"),
                    Distribution.Path.Combine("external/mono/mono/metadata"),
                    Distribution.Path.Combine("external/mono/mono/metadata/private"),
                    Distribution.Path.Combine("libmono/config"),
                    Distribution.Path.Combine("libil2cpp/os/c-api"),
                    Distribution.Path.Combine("libil2cpp/debugger")
                },
                PublicDefines =
                {
                    "NET_4_0",
                    "GC_NOT_DLL",
                    "RUNTIME_IL2CPP",
                    "LIBIL2CPP_IS_IN_EXECUTABLE=0",
                    { c => c.ToolChain is VisualStudioToolchain,"NOMINMAX",               "WIN32_THREADS", "IL2CPP_TARGET_WINDOWS=1" },
                    { c => c.CodeGen == CodeGen.Debug,"DEBUG",                  "IL2CPP_DEBUG=1" },
                    { c => !(c.Platform is WebGLPlatform),"GC_THREADS=1",           "USE_MMAP=1",    "USE_MUNMAP=1"            },
                },
                Defines =
                {
                    "BASELIB_INLINE_NAMESPACE=il2cpp_baselib"
                },
                Libraries =
                {
                    {
                        c => c.Platform is WindowsPlatform,
                        new[]
                        {
                            "user32.lib", "advapi32.lib", "ole32.lib", "oleaut32.lib", "Shell32.lib", "Crypt32.lib",
                            "psapi.lib", "version.lib", "MsWSock.lib", "ws2_32.lib", "Iphlpapi.lib", "Dbghelp.lib"
                        }.Select(s => new SystemLibrary(s))
                    },
                    { c => c.Platform is MacOSXPlatform || c.Platform is IosPlatform, new ILibrary[] { new SystemFramework("CoreFoundation") } },
                    { c => c.Platform is LinuxPlatform,                           new SystemLibrary("dl") },
                    { c => c.Platform is AndroidPlatform,                         new ILibrary[] { new SystemLibrary("log")              } },
                }
            };

            program.RTTI.Set(c => useExceptions && c.ToolChain.EnablingExceptionsRequiresRTTI);

            if (libil2cppname == "libil2cpptiny")
            {
                program.Defines.Add("IL2CPP_TINY");

                if (!managedDebuggingEnabled)
                {
                    // Tiny needs to be able to find its include directory before libil2cpp
                    program.IncludeDirectories.AddFront(Distribution.Path.Combine("libil2cpptiny"));

                    program.Sources.Add(Distribution.GetFileList("libil2cpp/os"));
                    program.Sources.Add(Distribution.GetFileList("libil2cpp/gc"));
                    program.Sources.Add(Distribution.GetFileList("libil2cpp/utils"));
                    program.Sources.Add(Distribution.GetFileList("libil2cpp/vm-utils"));
                }
            }

            if (managedDebuggingEnabled)
            {
                program.Defines.Add("IL2CPP_MONO_DEBUGGER=1",
                                    "IL2CPP_DEBUGGER_PORT=56000",
                                    "PLATFORM_UNITY",
                                    "UNITY_USE_PLATFORM_STUBS",
                                    "ENABLE_OVERRIDABLE_ALLOCATORS",
                                    "IL2CPP_ON_MONO=1",
                                    "DISABLE_JIT=1",
                                    "DISABLE_REMOTING=1",
                                    "HAVE_CONFIG_H",
                                    "MONO_DLL_EXPORT=1");
                program.Defines.Add(c => c.ToolChain.Platform is WebGLPlatform, "HOST_WASM=1");

                program.CompilerSettingsForMsvc().Add(c => c.WithCustomFlags(new[] { "/EHcs" }));
                program.CompilerSettingsForClang().Add(c => c.WithRTTI(true));
                program.CompilerSettingsForClang().Add(c => c.WithExceptions(true));
            }
            else
            {
                program.Defines.Add("IL2CPP_MONO_DEBUGGER_DISABLED");
            }

            program.PublicDefines.Add(c => c.ToolChain.Platform is AndroidPlatform,
                                      "LINUX",
                                      "ANDROID",
                                      "PLATFORM_ANDROID",
                                      "__linux__",
                                      "__STDC_FORMAT_MACROS"
                                      );
            program.PublicDefines.Add(c => c.ToolChain.Platform is AndroidPlatform && c.ToolChain.Architecture is Arm64Architecture, "TARGET_ARM64");

            var MonoSourceDir = Distribution.Path.Combine("external/mono");

            program.Sources.Add(c => MonoSourcesFor(c, MonoSourceDir, managedDebuggingEnabled));
            program.NonLumpableFiles.Add(c => MonoSourcesFor(c, MonoSourceDir, managedDebuggingEnabled));

            if (libil2cppname != "libil2cpptiny")
            {
                program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external/zlib"));
                var zlibSources = Distribution.GetFileList("external/zlib").Where(f => f.Extension.Equals("c")).ToArray();
                program.NonLumpableFiles.Add(zlibSources);
                program.Sources.Add(zlibSources);
            }
            else
            {
                program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external/xxHash"));
                program.Sources.Add(Distribution.Path.Combine("external/xxHash/xxhash.c"));
            }

            var boehmGcRoot = Distribution.Path.Combine("external/bdwgc");

            program.Sources.Add(boehmGcRoot.Combine("extra/gc.c"));
            program.PublicIncludeDirectories.Add(boehmGcRoot.Combine("include"));
            program.IncludeDirectories.Add(boehmGcRoot.Combine("libatomic_ops/src"));
            program.Defines.Add(
                "ALL_INTERIOR_POINTERS=1",
                "GC_GCJ_SUPPORT=1",
                "JAVA_FINALIZATION=1",
                "NO_EXECUTE_PERMISSION=1",
                "GC_NO_THREADS_DISCOVERY=1",
                "IGNORE_DYNAMIC_LOADING=1",
                "GC_DONT_REGISTER_MAIN_STATIC_DATA=1",
                "NO_DEBUGGING=1",
                "GC_VERSION_MAJOR=7",
                "GC_VERSION_MINOR=7",
                "GC_VERSION_MICRO=0",
                "HAVE_BDWGC_GC",
                "HAVE_BOEHM_GC",
                "DEFAULT_GC_NAME=\"BDWGC\"",
                "NO_CRT=1",
                "DONT_USE_ATEXIT=1",
                "NO_GETENV=1");

            program.Defines.Add(c => !(c.Platform is WebGLPlatform), "GC_THREADS=1", "USE_MMAP=1", "USE_MUNMAP=1");
            program.Defines.Add(c => c.ToolChain is VisualStudioToolchain, "NOMINMAX", "WIN32_THREADS");
            program.CompilerSettings().Add(s => s.WithCppLanguageVersion(CppLanguageVersion.Cpp11));
            if (platformSupport != null)
            {
                platformSupport.ProvideLibIl2CppProgramSettings(program);
            }

            return(program);
        }