Ejemplo n.º 1
0
    public static NativeProgram CreateBoehmGcProgram(NPath boehmGcRoot)
    {
        var program = new NativeProgram("boehm-gc");

        program.Sources.Add($"{boehmGcRoot}/extra/gc.c");
        program.PublicIncludeDirectories.Add($"{boehmGcRoot}/include");
        program.IncludeDirectories.Add($"{boehmGcRoot}/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.Platform is WebGLPlatform, "EMSCRIPTEN_TINY=1");
        program.Defines.Add(c => c.ToolChain is VisualStudioToolchain, "NOMINMAX", "WIN32_THREADS");
        program.CompilerSettingsForEmscripten().Add(ManagedDebuggingIsEnabled,
                                                    c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled));
        //program.CompilerSettingsForMsvc().Add(l => l.WithCompilerRuntimeLibrary(CompilerRuntimeLibrary.None));
        return(program);
    }
    public static void SetupDotsRuntimeNativeProgram(string libname, NativeProgram np)
    {
        np.DynamicLinkerSettingsForMac().Add(c => c.WithInstallName(libname + ".dylib"));
        np.DynamicLinkerSettingsForIos()
        .Add(c => c.WithInstallName("@executable_path/Frameworks/" + libname + ".dylib"));
        np.IncludeDirectories.Add(BuildProgram.BeeRootValue.Combine("cppsupport/include"));

        //lets always add a dummy cpp file, in case this np is only used to carry other libraries
        np.Sources.Add(BuildProgram.BeeRootValue.Combine("cppsupport/dummy.cpp").ResolveWithFileSystem());

        np.Defines.Add(c => c.Platform is WebGLPlatform, "UNITY_WEBGL=1");
        np.Defines.Add(c => c.Platform is WindowsPlatform, "UNITY_WINDOWS=1");
        np.Defines.Add(c => c.Platform is MacOSXPlatform, "UNITY_MACOSX=1");
        np.Defines.Add(c => c.Platform is LinuxPlatform, "UNITY_LINUX=1");
        np.Defines.Add(c => c.Platform is IosPlatform, "UNITY_IOS=1");
        np.Defines.Add(c => c.Platform is AndroidPlatform, "UNITY_ANDROID=1");
        np.Defines.Add(c => c.CodeGen == CodeGen.Debug, "DEBUG=1");

        np.Defines.Add("BINDGEM_DOTS=1");
        np.Defines.Add(c =>
                       ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableManagedDebugging &&
                       ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.WaitForManagedDebugger,
                       "UNITY_DOTSRUNTIME_IL2CPP_WAIT_FOR_MANAGED_DEBUGGER");

        np.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableUnityCollectionsChecks, "ENABLE_UNITY_COLLECTIONS_CHECKS");

        // Using ENABLE_PROFILER and not ENABLE_DOTSRUNTIME_PROFILER because native code doesn't call any DOTS Runtime specific API
        np.Defines.Add(c => (c as DotsRuntimeNativeProgramConfiguration)?.CSharpConfig.EnableProfiler == true, "ENABLE_PROFILER");

        //we don't want to do this for c#, because then burst sees different code from the unbursted path and it's very
        //easy and tempting to go insane this way. but for native, it's fine, since burst
        //doesn't see that directly. and also, it enables us to error when we don't find the burst dll when burst is on,
        //and not look for it when it's off.
        np.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.UseBurst, "ENABLE_UNITY_BURST=1");

        np.CompilerSettingsForEmscripten().Add(c =>
                                               ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableManagedDebugging,
                                               c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled));

        np.StaticLinkerSettings()
        .Add(c => c.ToolChain is EmscriptenToolchain && ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableManagedDebugging,
             s => s.WithCustomFlags_workaround(new[] { "-s", "USE_PTHREADS=1" }));

        np.CompilerSettings().Add(c => c.WithWarningsAsErrors(ShouldEnableWarningsAsErrors(libname)));
    }
Ejemplo n.º 3
0
    public BgfxBuild()
    {
        var rendererRoot = AsmDefConfigFile.AsmDefDescriptionFor("Unity.Tiny.Rendering.Native").Directory;

        bool useLocalBgfx = false;

        BgfxArtifact = new StevedoreArtifact("bgfx-source");
        BgfxRoot     = BgfxArtifact.Path.ResolveWithFileSystem();

        //BgfxRoot = @"C:\Users\sebastianm\gits\bgfx-root";
        //useLocalBgfx = true;

        var bx   = BgfxRoot.Combine("bx");
        var bgfx = BgfxRoot.Combine("bgfx");
        var bimg = BgfxRoot.Combine("bimg");

        // Note that these 3 NativePrograms are only linked in as BagOfObjects into the bgfx dll above.
        // They should not have Libraries themselves (e.g. bgfx should not reference the bx or bimg NativePrograms).
        // This means that PublicIncludes won't work, which is why Bimg and Bgfx explicitly add BxLib's PublicIncludes
        // to their own Includes.

        BxLib = new NativeProgram("bx")
        {
            Exceptions = { false },
            RTTI       = { false },
            PublicIncludeDirectories =
            {
                bx.Combine("include"),
                bx.Combine("3rdparty"),
            },
            Sources =
            {
                //bx.Combine("src").Files("*.cpp").Except(new[] {bx.Combine("src/amalgamated.cpp"), bx.Combine("src/crtnone.cpp")})
                bx.Combine("src/amalgamated.cpp")
            },
            Defines = { "__STDC_FORMAT_MACROS" },
        };
        BxLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14));
        BxLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false));
        BxLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false));
        BxLib.Defines.Add(c => c.Platform is WindowsPlatform, "_CRT_SECURE_NO_WARNINGS");
        BxLib.PublicIncludeDirectories.Add(c => c.ToolChain is WindowsToolchain, bx.Combine("include/compat/msvc"));
        BxLib.PublicIncludeDirectories.Add(c => c.Platform is MacOSXPlatform, bx.Combine("include/compat/osx"));
        BxLib.PublicIncludeDirectories.Add(c => c.Platform is IosPlatform, bx.Combine("include/compat/ios"));
        BxLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled,
                                                  c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled));

        BimgLib = new NativeProgram("bimg")
        {
            Exceptions         = { false },
            RTTI               = { false },
            IncludeDirectories =
            {
                bimg.Combine("include"),
                bimg.Combine("3rdparty/astc-codec/include"),
                // comment out next line once BIMG_DECODE_ASTC lands in bimg
                bimg.Combine("3rdparty/astc-codec"),
            },
            Sources =
            {
                bimg.Combine("src/image.cpp"),
                bimg.Combine("src/image_gnf.cpp"),
                // comment out next line once BIMG_DECODE_ASTC lands in bimg
                bimg.Combine("3rdparty/astc-codec/src/decoder").CombineMany(new [] { "astc_file.cc","codec.cc",                                                    "endpoint_codec.cc", "footprint.cc", "integer_sequence_codec.cc", "intermediate_astc_block.cc", "logical_astc_block.cc", "partition.cc", "physical_astc_block.cc", "quantization.cc", "weight_infill.cc" })
            },
            Defines =
            {
                "__STDC_FORMAT_MACROS",
                "BIMG_DECODE_ENABLE=0"
            },
        };
        BimgLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14));
        BimgLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false));
        BimgLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false));
        BimgLib.IncludeDirectories.Add(c => BxLib.PublicIncludeDirectories.For(c));
        BimgLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled,
                                                    c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled));

        BgfxLib = new NativeProgram("bgfx")
        {
            Exceptions         = { false },
            RTTI               = { false },
            IncludeDirectories =
            {
                bimg.Combine("include"),
                bgfx.Combine("include"),
                bgfx.Combine("3rdparty"),
                bgfx.Combine("3rdparty/khronos"),
                rendererRoot.Combine("cpp~/include"),
            },
            Defines =
            {
                "BGFX_SHARED_LIB_BUILD",
                "__STDC_FORMAT_MACROS"
            },
        };
        BgfxLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14));
        BgfxLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false));
        BgfxLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false));
        BgfxLib.IncludeDirectories.Add(c => BxLib.PublicIncludeDirectories.For(c));

        BgfxLib.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.Defines.Contains("RENDERING_ENABLE_TRACE"), "BGFX_CONFIG_DEBUG=1");
        BgfxLib.Defines.Add(c => c.ToolChain is WindowsToolchain, "_CRT_SECURE_NO_WARNINGS");
        //BgfxLib.Defines.Add("BGFX_CONFIG_DEBUG_UNIFORM=0");
        if (!useLocalBgfx)
        {
            // when using bgfx from stevedore, this requires pix3.h which we don't distribute
            BgfxLib.Defines.Add(c => c.Platform is WindowsPlatform, "BGFX_CONFIG_DEBUG_ANNOTATION=0");
        }
        else
        {
            BgfxLib.Defines.Add(c => c.Platform is WindowsPlatform, "BGFX_CONFIG_DEBUG_ANNOTATION=0");
            ///BgfxLib.IncludeDirectories.Add(bgfx.Combine("3rdparty/dxsdk"));
        }

        BgfxLib.Defines.Add("BGFX_CONFIG_MAX_BONES=4");
        BgfxLib.Defines.Add(c => (c as DotsRuntimeNativeProgramConfiguration)?.CSharpConfig.EnableProfiler == true, "BGFX_CONFIG_PROFILER=1");

        // At some point we need to stop using amalgamated, especially for small-size web builds
        BgfxLib.Sources.Add(c => !(c.Platform is MacOSXPlatform || c.Platform is IosPlatform), bgfx.Combine("src/amalgamated.cpp"));
        BgfxLib.Sources.Add(c => (c.Platform is MacOSXPlatform || c.Platform is IosPlatform), bgfx.Combine("src/amalgamated.mm"));

        // This is a hack that the Khronos eglplatform.h header understands in order to define the EGL types as intptr_t,
        // which is what emscripten wants.  Otherwise we fall into a __unix__ path, which includes X11/Xlib.h, and
        // all hell breaks loose.
        BgfxLib.Defines.Add(c => c.Platform is WebGLPlatform, "USE_OZONE");

        BgfxLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled,
                                                    c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled));
    }
Ejemplo n.º 4
0
    static NativeProgram CreateLibIl2CppProgram(bool useExceptions, NativeProgram boehmGcProgram = null, string libil2cppname = "libil2cpptiny")
    {
        var fileList = Distribution.GetFileList(libil2cppname).ResolveWithFileSystem().ToArray();

        var nPaths       = fileList.Where(f => f.HasExtension("cpp")).ToArray();
        var win32Sources = nPaths.Where(p => p.HasDirectory("Win32")).ToArray();
        var posixSources = nPaths.Where(p => p.HasDirectory("Posix")).ToArray();

        nPaths = nPaths.Except(win32Sources).Except(posixSources).ToArray();

        var program = new NativeProgram(libil2cppname)
        {
            Sources =
            {
                nPaths,
                { c => c.Platform.HasPosix,posixSources                      },
                { c => c.Platform is WindowsPlatform,win32Sources                      }
            },
            Exceptions = { useExceptions },
            PublicIncludeDirectories =
            {
                Distribution.Path.Combine(libil2cppname),
                Distribution.Path.Combine("libil2cpp")
            },
            PublicDefines =
            {
                "NET_4_0",
                "GC_NOT_DLL",
                "RUNTIME_IL2CPP",

                "LIBIL2CPP_IS_IN_EXECUTABLE=1",
                { c => c.ToolChain is VisualStudioToolchain,"NOMINMAX",               "WIN32_THREADS", "IL2CPP_TARGET_WINDOWS=1" },
                { c => c.CodeGen == CodeGen.Debug,"DEBUG",                  "IL2CPP_DEBUG" },
                { c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.DotsConfiguration != DotsConfiguration.Release,"IL2CPP_TINY_DEBUG_METADATA" },
            },
            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,  new PrecompiledLibrary[] { new SystemFramework("CoreFoundation") } },
                { c => c.Platform is LinuxPlatform,   new SystemLibrary("dl") },
                { c => c.Platform is AndroidPlatform, new[]                    { new SystemLibrary("log")              } }
            },
            Defines =
            {
                { c => c.Platform is AndroidPlatform && c.ToolChain.Architecture is Arm64Architecture && ManagedDebuggingIsEnabled(c), "TARGET_ARM64" },
            }
        };

        program.Libraries.Add(BoehmGCProgram);

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

        if (libil2cppname == "libil2cpptiny")
        {
            program.Sources.Add(Distribution.GetFileList("libil2cpp/os").ResolveWithFileSystem());
            program.Sources.Add(Distribution.GetFileList("libil2cpp/gc").ResolveWithFileSystem());
            program.Sources.Add(Distribution.GetFileList("libil2cpp/utils").ResolveWithFileSystem());
            program.Sources.Add(Distribution.GetFileList("libil2cpp/vm-utils").ResolveWithFileSystem());
            program.Sources.Add(Distribution.GetFileList("libil2cpp/codegen").ResolveWithFileSystem());
            program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp"));
            program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp", "pch"));
        }
        else
        {
            program.Defines.Add(ManagedDebuggingIsEnabled,
                                "IL2CPP_MONO_DEBUGGER=1",
                                "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.IncludeDirectories.Add(ManagedDebuggingIsEnabled,
                                           new[]
            {
                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/metadata/private"),
                Distribution.Path.Combine("libmono/config"),
                Distribution.Path.Combine("libil2cpp/os/c-api"),
                Distribution.Path.Combine("libil2cpp/pch"),
            }.ResolveWithFileSystem());

            var MonoSourceDir = Distribution.Path.Combine("external/mono").ResolveWithFileSystem();
            program.Sources.Add(ManagedDebuggingIsEnabled,
                                new []
            {
                "mono/eglib/garray.c",
                "mono/eglib/gbytearray.c",
                "mono/eglib/gdate-unity.c",
                "mono/eglib/gdir-unity.c",
                "mono/eglib/gerror.c",
                "mono/eglib/gfile-unity.c",
                "mono/eglib/gfile.c",
                "mono/eglib/ghashtable.c",
                "mono/eglib/giconv.c",
                "mono/eglib/glist.c",
                "mono/eglib/gmarkup.c",
                "mono/eglib/gmem.c",
                "mono/eglib/gmisc-unity.c",
                "mono/eglib/goutput.c",
                "mono/eglib/gpath.c",
                "mono/eglib/gpattern.c",
                "mono/eglib/gptrarray.c",
                "mono/eglib/gqsort.c",
                "mono/eglib/gqueue.c",
                "mono/eglib/gshell.c",
                "mono/eglib/gslist.c",
                "mono/eglib/gspawn.c",
                "mono/eglib/gstr.c",
                "mono/eglib/gstring.c",
                "mono/eglib/gunicode.c",
                "mono/eglib/gutf8.c",
                "mono/metadata/mono-hash.c",
                "mono/metadata/profiler.c",
                "mono/mini/debugger-agent.c",
                "mono/utils/atomic.c",
                "mono/utils/bsearch.c",
                "mono/utils/dlmalloc.c",
                "mono/utils/hazard-pointer.c",
                "mono/utils/json.c",
                "mono/utils/lock-free-alloc.c",
                "mono/utils/lock-free-array-queue.c",
                "mono/utils/lock-free-queue.c",
                "mono/utils/memfuncs.c",
                "mono/utils/mono-codeman.c",
                "mono/utils/mono-conc-hashtable.c",
                "mono/utils/mono-context.c",
                "mono/utils/mono-counters.c",
                "mono/utils/mono-dl.c",
                "mono/utils/mono-error.c",
                "mono/utils/mono-filemap.c",
                "mono/utils/mono-hwcap.c",
                "mono/utils/mono-internal-hash.c",
                "mono/utils/mono-io-portability.c",
                "mono/utils/mono-linked-list-set.c",
                "mono/utils/mono-log-common.c",
                "mono/utils/mono-logger.c",
                "mono/utils/mono-math.c",
                "mono/utils/mono-md5.c",
                "mono/utils/mono-mmap-windows.c",
                "mono/utils/mono-mmap.c",
                "mono/utils/mono-networkinterfaces.c",
                "mono/utils/mono-os-mutex.c",
                "mono/utils/mono-path.c",
                "mono/utils/mono-poll.c",
                "mono/utils/mono-proclib-windows.c",
                "mono/utils/mono-proclib.c",
                "mono/utils/mono-property-hash.c",
                "mono/utils/mono-publib.c",
                "mono/utils/mono-sha1.c",
                "mono/utils/mono-stdlib.c",
                "mono/utils/mono-threads-coop.c",
                "mono/utils/mono-threads-state-machine.c",
                "mono/utils/mono-threads.c",
                "mono/utils/mono-tls.c",
                "mono/utils/mono-uri.c",
                "mono/utils/mono-value-hash.c",
                "mono/utils/monobitset.c",
                "mono/utils/networking-missing.c",
                "mono/utils/networking.c",
                "mono/utils/parse.c",
                "mono/utils/strenc.c",
                "mono/utils/unity-rand.c",
                "mono/utils/unity-time.c",
                "mono/utils/mono-dl-unity.c",
                "mono/utils/mono-log-unity.c",
                "mono/utils/mono-threads-unity.c",
                "mono/utils/networking-unity.c",
                "mono/utils/os-event-unity.c",
                "mono/metadata/console-unity.c",
                "mono/metadata/file-mmap-unity.c",
                "mono/metadata/w32error-unity.c",
                "mono/metadata/w32event-unity.c",
                "mono/metadata/w32file-unity.c",
                "mono/metadata/w32mutex-unity.c",
                "mono/metadata/w32process-unity.c",
                "mono/metadata/w32semaphore-unity.c",
                "mono/metadata/w32socket-unity.c"
            }.Select(path => MonoSourceDir.Combine(path)));

            program.Sources.Add(c => c.ToolChain.Platform is WindowsPlatform && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/eglib/gunicode-win32.c"));
            program.Sources.Add(c => c.ToolChain.Platform is WindowsPlatform && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-os-wait-win32.c"));

            program.Sources.Add(c => c.ToolChain.Platform is WebGLPlatform && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-web.c"));

            program.Sources.Add(c => c.ToolChain.Architecture is IntelArchitecture && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-x86.c"));
            program.Sources.Add(c => c.ToolChain.Architecture is ARMv7Architecture && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-arm.c"));
            program.Sources.Add(c => c.ToolChain.Architecture is Arm64Architecture && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-arm64.c"));

            program.IncludeDirectories.Add(ManagedDebuggingIsEnabled, Distribution.Path.Combine("libil2cpp/debugger"));
        }

        program.PublicDefines.Add("IL2CPP_TINY");
        program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external").Combine("xxHash"));
        program.CompilerSettings().Add(s => s.WithCppLanguageVersion(CppLanguageVersion.Cpp11));

        program.CompilerSettingsForGcc().Add(s => s.WithWarningPolicies(GetGccLikeWarningPolicies()));

        // Use Baselib headers and library code from the NativeJobs library.
        NativeJobsPrebuiltLibrary.AddToNativeProgram(program);

        //program.CompilerSettingsForMsvc().Add(l => l.WithCompilerRuntimeLibrary(CompilerRuntimeLibrary.None));

        program.CompilerSettingsForEmscripten().Add(ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled));
        program.StaticLinkerSettings().Add(c => c.ToolChain is EmscriptenToolchain && ManagedDebuggingIsEnabled(c), s => s.WithCustomFlags_workaround(new[] { "-s", "USE_PTHREADS=1" }));

        return(program);
    }