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.ToolChain is VisualStudioToolchain, "NOMINMAX", "WIN32_THREADS");
        //program.CompilerSettingsForMsvc().Add(l => l.WithCompilerRuntimeLibrary(CompilerRuntimeLibrary.None));
        return(program);
    }
Ejemplo n.º 2
0
    static void Main()
    {
        List <BuildCommand> commands = HostPlatform.IsOSX ? MacCommands() : WindowsCommands();

        commands.AddRange(GetAndroidBuildCommands());

        NativeProgram plugin = new NativeProgram("traceeventprofiler")
        {
            Sources = { "src" }
        };

        plugin.CompilerSettingsForIosOrTvos().Add(s => s.WithEmbedBitcode(true));
        plugin.DynamicLinkerSettingsForWindows().Add(s => s.WithDefinitionFile("src/ProfilerPlugin.def"));
        foreach (var command in commands)
        {
            var toolchain = command.ToolChain;
            plugin.OutputName.Set(c => DllNameForPlatform(c.ToolChain.Platform));

            var config       = new NativeProgramConfiguration(CodeGen.Release, toolchain, false);
            var builtProgram = plugin.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat,
                                                                 targetDirectory: $"artifacts_preprocess/{toolchain.LegacyPlatformIdentifier}");
            if (command.PostProcess != null)
            {
                builtProgram = command.PostProcess(builtProgram, toolchain, command.PluginSubFolder);
            }
            Backend.Current.AddAliasDependency(command.Alias, builtProgram);
        }
    }
Ejemplo n.º 3
0
    protected virtual DotNetAssembly SetupNativeProgram(CSharpProgramConfiguration config, DotNetAssembly result)
    {
        var dotsConfig = (DotsRuntimeCSharpProgramConfiguration)config;

        var npc = dotsConfig.NativeProgramConfiguration;

        if (NativeProgram != null && NativeProgram.Sources.ForAny().Any())
        {
            BuiltNativeProgram setupSpecificConfiguration = NativeProgram.SetupSpecificConfiguration(npc,
                                                                                                     npc.ToolChain.DynamicLibraryFormat ?? npc.ToolChain.StaticLibraryFormat);
            result = result.WithDeployables(setupSpecificConfiguration);
        }

        return(result);
    }
Ejemplo n.º 4
0
    private static void ProcessProgram(NativeProgram plugin, string targetDir, List <BuildCommand> commands)
    {
        foreach (var command in commands)
        {
            var toolchain = command.ToolChain;

            var config       = new NativeProgramConfiguration(CodeGen.Release, toolchain, false);
            var builtProgram = plugin.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat);
            var artefact     = builtProgram.Path;
            if (command.PostProcess != null)
            {
                artefact = command.PostProcess(artefact, toolchain, targetDir, command.PluginSubFolder);
            }
            Backend.Current.AddAliasDependency(command.Alias, artefact);
        }
    }
Ejemplo n.º 5
0
    private static void BuildStarterKitPlugin()
    {
        var np = new NativeProgram("MARSXRSubsystem");

        np.Sources.Add("Source");
        np.IncludeDirectories.Add("External/Unity");

        var toolchains = new ToolChain[]
        {
            new WindowsToolchain(new Lazy <WindowsSdk>(() => WindowsSdk.Locatorx64.UserDefaultOrLatest).Value),
            new MacToolchain(new Lazy <MacSdk>(() => MacSdk.Locatorx64.UserDefaultOrLatest).Value),
            //new AndroidNdkToolchain(new Lazy<AndroidNdk>(() => (AndroidNdk) ToolChain.Store.Android().r16b().Arm64().Sdk).Value),
            //new AndroidNdkToolchain(new Lazy<AndroidNdk>(() => (AndroidNdk) ToolChain.Store.Android().r16b().Armv7().Sdk).Value),
            //new IOSToolchain(new Lazy<IOSSdk>(() => IOSSdk.LocatorArm64.UserDefaultOrLatest).Value),
        };

        np.OutputName.Add(s => s.Platform is AndroidPlatform, $"lib{np.Name}");

        foreach (var toolchain in toolchains)
        {
            var name = toolchain.Platform.Name.ToLower();
            if (!toolchain.CanBuild)
            {
                Console.WriteLine($"Can't build {toolchain.ToString()}");
                continue;
            }

            var nativeProgramConfiguration = new NativeProgramConfiguration(CodeGen.Debug, toolchain, lump: false);

            //we want to build the nativeprogram into an executable. each toolchain can provide different ways of "linking" (static, dynamic, executable are default ones)
            var format = toolchain is IOSToolchain ? toolchain.StaticLibraryFormat : toolchain.DynamicLibraryFormat;

            //and here the magic happens, the nativeprogram gets setup for the specific configuration we just made.
            var folder       = name;
            var deployFolder = new NPath("build").Combine(folder).Combine(toolchain.Architecture.DisplayName);
            var output       = np.SetupSpecificConfiguration(nativeProgramConfiguration, format).DeployTo(deployFolder);

            var metaFolder       = new NPath("Meta/").Combine(folder).Combine(toolchain.Architecture.DisplayName);
            var metaFile         = metaFolder.Combine("plugin." + output.Path.Extension + ".meta");
            var deployedMetaFile = deployFolder.Combine(output.Path.FileName + ".meta");
            CopyMetaFileWithNewGUID(metaFile, deployedMetaFile);

            var alias = name;
            Backend.Current.AddAliasDependency(alias, output.Path);
            Backend.Current.AddAliasDependency(alias, deployedMetaFile);
        }
    }
    internal NativeProgram GetOrMakeNativeProgram()
    {
        if (NativeProgram != null)
        {
            return(NativeProgram);
        }

        var libname = "lib_" + new NPath(FileName).FileNameWithoutExtension.ToLower().Replace(".", "_");

        NativeProgram = new NativeProgram(libname);

        SetupDotsRuntimeNativeProgram(libname, NativeProgram);
        // sigh
        NativeProgram.Defines.Add("BUILD_" + MainSourcePath.FileName.ToUpper().Replace(".", "_") + "=1");

        return(NativeProgram);
    }
    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.º 8
0
    static void Main()
    {
        // For Windows plugins
        List <BuildCommand> desktop = new List <BuildCommand>();

        desktop.Add(BuildCommand.Create(new WindowsToolchain(WindowsSdk.Locatorx86.UserDefaultOrLatest), "windows", "x86"));
        desktop.Add(BuildCommand.Create(new WindowsToolchain(WindowsSdk.Locatorx64.UserDefaultOrLatest), "windows", "x86_64"));
        desktop.Add(BuildCommand.Create(new LinuxGccToolchain(WSLGccSdk.Locatorx64.UserDefaultOrLatest), "linux", "x86_64"));

        // For Android plugins
        List <BuildCommand> android = new List <BuildCommand>();

        android.Add(BuildCommand.Create(new AndroidNdkToolchain(AndroidNdk.LocatorArmv7.UserDefaultOrLatest), "android", "Android/armeabi-v7a"));
        android.Add(BuildCommand.Create(new AndroidNdkToolchain(AndroidNdk.LocatorArm64.UserDefaultOrLatest), "android", "Android/arm64-v8a"));
        android.Add(BuildCommand.Create(new AndroidNdkToolchain(AndroidNdk.Locatorx86.UserDefaultOrLatest), "android", "Android/x86"));


        NativeProgram androidStudioPlugin = new NativeProgram("libProfilerPluginGAS");

        androidStudioPlugin.Sources.Add("src/ProfilerPlugin.cpp");
        androidStudioPlugin.Sources.Add("src/AndroidSystrace.cpp");
        androidStudioPlugin.Sources.Add("src/AndroidSystraceProfiler.cpp");
        androidStudioPlugin.PrebuiltLibraries.Add(new SystemLibrary("log"));
        ProcessProgram(androidStudioPlugin, "../com.unity.nativeprofilers.androidsystrace/Plugins", android);

        NativeProgram streamlineAnalyzerPlugin = new NativeProgram("libProfilerPluginASA");

        streamlineAnalyzerPlugin.Sources.Add("src/ProfilerPlugin.cpp");
        streamlineAnalyzerPlugin.Sources.Add("src/StreamlineAnalyzerProfiler.cpp");
        streamlineAnalyzerPlugin.Sources.Add("src/Arm");
        streamlineAnalyzerPlugin.PrebuiltLibraries.Add(new SystemLibrary("log"));
        ProcessProgram(streamlineAnalyzerPlugin, "../com.unity.nativeprofilers.streamlineanalyzer/Plugins", android);

        NativeProgram vtuneAmplifierPlugin = new NativeProgram("ProfilerPluginIVT");

        vtuneAmplifierPlugin.Sources.Add("src/ProfilerPlugin.cpp");
        vtuneAmplifierPlugin.Sources.Add("src/VTuneAmplifierProfiler.cpp");
        vtuneAmplifierPlugin.DynamicLinkerSettingsForWindows().Add(s => s.WithDefinitionFile("src/ProfilerPlugin.def"));
        vtuneAmplifierPlugin.PrebuiltLibraries.Add((program) => { return((program.Platform is WindowsPlatform) && (program.ToolChain.Architecture == Architecture.x86)); }, new StaticLibrary("src/Intel/libittnotify32.lib"));
        vtuneAmplifierPlugin.PrebuiltLibraries.Add((program) => { return((program.Platform is WindowsPlatform) && (program.ToolChain.Architecture == Architecture.x64)); }, new StaticLibrary("src/Intel/libittnotify64.lib"));
        vtuneAmplifierPlugin.PrebuiltLibraries.Add((program) => { return(program.Platform is LinuxPlatform); }, new StaticLibrary("src/Intel/libittnotify64.a"));
        vtuneAmplifierPlugin.PrebuiltLibraries.Add((program) => { return(program.Platform is LinuxPlatform); }, new SystemLibrary("dl"));
        ProcessProgram(vtuneAmplifierPlugin, "../com.unity.nativeprofilers.vtune/Plugins", desktop);
    }
Ejemplo n.º 9
0
    //Run ./bee build-lib-webp to compile the webp library located in Unity.Tiny.Image2D.Native.cpp~/libwebp and copy it to Unity.Tiny.Image2D.Authoring/libwebp
    public override void Customize()
    {
        var           asmdefRoot      = AsmDefConfigFile.AsmDefDescriptionFor("Unity.Tiny.Image2D.Native").Directory;
        var           outputDirectory = AsmDefConfigFile.AsmDefDescriptionFor("Unity.Tiny.Image2D.Authoring").Directory;
        NativeProgram WebPLib         = new NativeProgram("libwebp")
        {
            Sources =
            {
                asmdefRoot.Combine("cpp~/libwebp"),
            },
            IncludeDirectories = { asmdefRoot.Combine("cpp~/libwebp") },
            OutputDirectory    = { outputDirectory.Combine("libwebp") }
        };

        DotsRuntimeNativeProgramConfiguration config = DotsConfigs.HostDotnet.NativeProgramConfiguration;
        var builtWebPLib = WebPLib.SetupSpecificConfiguration(config, config.ToolChain.DynamicLibraryFormat);

        Backend.Current.AddAliasDependency("build-lib-webp", builtWebPLib.Path);
    }
Ejemplo n.º 10
0
 public static void AddLibIl2CppAsLibraryFor(NativeProgram program)
 {
     program.Libraries.Add(c => !ManagedDebuggingIsEnabled(c), LibIL2Cpp);
     program.Libraries.Add(ManagedDebuggingIsEnabled, BigLibIL2Cpp);
 }
Ejemplo n.º 11
0
    static NativeProgram CreateLibIl2CppProgram(bool useExceptions, NativeProgram boehmGcProgram = null, string libil2cppname = "libil2cpptiny")
    {
        var fileList = Distribution.GetFileList(libil2cppname).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("libil2cpp")
        {
            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" }
            },
            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") }
            }
        };

        program.Libraries.Add(BoehmGCProgram);

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

        if (libil2cppname == "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"));
            program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp"));
            program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external").Combine("xxHash"));
            program.PublicDefines.Add("IL2CPP_TINY");
        }

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

        return(program);
    }
Ejemplo n.º 12
0
    public static NativeProgram SetupGLFW()
    {
        var glfwArtifacts = new StevedoreArtifact("glfw");

        Backend.Current.Register(glfwArtifacts);
        var glfwRoot = glfwArtifacts.Path;

        var glfwLib = new NativeProgram("libglfw")
        {
            //RootDirectory = glfwRoot,
            IncludeDirectories =
            {
                glfwRoot.Combine("include"),
                glfwRoot.Combine("src"),
            },
            PublicIncludeDirectories =
            {
                glfwRoot.Combine("include")
            },
            Sources =
            {
            },
        };

        glfwLib.Defines.Add(c => c.CodeGen != CodeGen.Debug, "NDEBUG");

        glfwLib.Sources.Add(glfwRoot.Combine("src").CombineMany(new string[]
        {
            "context.c", "init.c", "input.c", "monitor.c", "vulkan.c", "window.c",
        }));

        //
        // Windows
        //
        glfwLib.Defines.Add(c => c.Platform is WindowsPlatform, "_GLFW_WIN32", "_GLFW_BUILD_DLL");
        glfwLib.Sources.Add(c => c.Platform is WindowsPlatform, glfwRoot.Combine("src").CombineMany(new string[]
        {
            "win32_init.c",
            "win32_joystick.c",
            "win32_monitor.c",
            "win32_time.c",
            "win32_thread.c",
            "win32_window.c",
            "wgl_context.c",
            "egl_context.c",
            "osmesa_context.c"
        }));

        glfwLib.Libraries.Add(c => c.Platform is WindowsPlatform,
                              new List <string>
        {
            "winmm",
            "gdi32",
            "opengl32",
            "user32",
            "winspool",
            "shell32",
            "uuid",
            "comdlg32",
            "advapi32"
        }
                              .ConvertAll(s => new SystemLibrary(s + ".lib"))
                              );

        //
        // Linux
        //
        glfwLib.Defines.Add(c => c.Platform is LinuxPlatform, new string[]
                            { "_GLFW_X11", "IL_NO_UTX" });


        glfwLib.Sources.Add(c => c.Platform is LinuxPlatform, glfwRoot.Combine("src").CombineMany(new string[]
        {
            "input.c",
            "linux_joystick.c",
            "x11_init.c",
            "x11_monitor.c",
            "x11_window.c",
            "xkb_unicode.c",
            "egl_context.c",
            "glx_context.c",
            "osmesa_context.c",
            "posix_thread.c",
            "posix_time.c"
        }));
        glfwLib.Libraries.Add(c => c.Platform is LinuxPlatform,
                              new List <string> {
            "GL", "X11", "udev", "Xrandr", "dl", "rt"
        }
                              .ConvertAll(s => new SystemLibrary(s)));
        //
        // Mac/iOS
        //
        glfwLib.Defines.Add(c => c.Platform is MacOSXPlatform, new string[]
                            { "_GLFW_COCOA" });

        glfwLib.Sources.Add(c => c.Platform is MacOSXPlatform, glfwRoot.Combine("src").CombineMany(new string[]
        {
            "cocoa_init.m", "cocoa_joystick.m", "cocoa_monitor.m",
            "cocoa_window.m", "cocoa_time.c", "posix_thread.c",
            "nsgl_context.m", "egl_context.c", "osmesa_context.c"
        }));

        glfwLib.Libraries.Add(c => c.Platform is MacOSXPlatform,
                              new List <string> {
            "OpenGL", "CoreFoundation", "IOKit", "Cocoa", "CoreData", "CoreVideo"
        }
                              .ConvertAll(s => new SystemFramework(s)));
        return(glfwLib);
    }
Ejemplo n.º 13
0
 public abstract void ProvideNativeProgramSettings(NativeProgram program);
Ejemplo n.º 14
0
 public abstract void ProvideLibIl2CppProgramSettings(NativeProgram program);
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
    private static DotsRuntimeCSharpProgram SetupGame(AsmDefDescription game)
    {
        var gameProgram       = GetOrMakeDotsRuntimeCSharpProgramFor(game);
        var configToSetupGame = new Dictionary <DotsRuntimeCSharpProgramConfiguration, DotNetAssembly>();

        if (!PerConfigBuildSettings.ContainsKey(game.Name))
        {
            return(null);
        }

        var configsToUse = PerConfigBuildSettings[game.Name].Where(config => !CanSkipSetupOf(game.Name, config));

        foreach (var config in configsToUse)
        {
            var   withoutExt     = new NPath(new NPath(gameProgram.FileName).FileNameWithoutExtension).Combine(config.Identifier);
            NPath exportManifest = withoutExt.Combine("export.manifest");
            Backend.Current.RegisterFileInfluencingGraph(exportManifest);
            if (exportManifest.FileExists())
            {
                var dataFiles = exportManifest.MakeAbsolute().ReadAllLines();
                foreach (var dataFile in dataFiles.Select(d => new NPath(d)))
                {
                    gameProgram.SupportFiles.Add(
                        c => c.Equals(config),
                        new DeployableFile(dataFile, GetDeployPathFromExportPath(dataFile)));
                }
            }

            gameProgram.ProjectFile.StartInfo.Add(
                c => c == config,
                StartInfoFor(config, EntryPointExecutableFor(gameProgram, config)));
            gameProgram.ProjectFile.BuildCommand.Add(
                c => c == config,
                new BeeBuildCommand(GameDeployBinaryFor(gameProgram, config).ToString(), false, false).ToExecuteArgs());
        }

        foreach (var config in configsToUse)
        {
            DotNetAssembly setupGame = gameProgram.SetupSpecificConfiguration(config);

            if (config.TargetFramework == TargetFramework.Tiny)
            {
                var tinyStandard = new DotNetAssembly(Il2Cpp.Distribution.Path.Combine("build/profiles/Tiny/Facades/netstandard.dll"), Framework.FrameworkNone);
                setupGame = setupGame.WithDeployables(tinyStandard);
            }

            var postILProcessedGame = ILPostProcessorTool.SetupInvocation(
                setupGame,
                config,
                gameProgram.Defines.For(config).ToArray());

            var postTypeRegGenGame = TypeRegistrationTool.SetupInvocation(postILProcessedGame, config);
            configToSetupGame[config] = postTypeRegGenGame;
        }

        var il2CppOutputProgram = new Il2Cpp.Il2CppOutputProgram(gameProgram.AsmDefDescription.Name);

        var configToSetupGameBursted = new Dictionary <DotsRuntimeCSharpProgramConfiguration, DotNetAssembly>();

        foreach (var kvp in configToSetupGame)
        {
            var config    = kvp.Key;
            var setupGame = kvp.Value;

            if (config.UseBurst)
            {
                BurstCompiler burstCompiler = null;
                if (config.Platform is WindowsPlatform)
                {
                    burstCompiler      = new BurstCompilerForWindows64();
                    burstCompiler.Link = false;
                }
                else if (config.Platform is MacOSXPlatform)
                {
                    burstCompiler      = new BurstCompilerForMac();
                    burstCompiler.Link = false;
                }
                else if (config.Platform is IosPlatform)
                {
                    burstCompiler = new BurstCompilerForiOS();
                    burstCompiler.EnableStaticLinkage = true;
                    burstCompiler.ObjectFileExtension = "a";
                }
                else if (config.Platform is LinuxPlatform)
                {
                    burstCompiler = new BurstCompilerForLinuxWaitingForBurstRelease();
                }
                else if (config.Platform is AndroidPlatform)
                {
                    burstCompiler = new BurstCompilerForAndroid();
                    burstCompiler.EnableStaticLinkage = false;
                    burstCompiler.Link = false;
                    burstCompiler.EnableDirectExternalLinking = true;
                    if (config.NativeProgramConfiguration.ToolChain.Architecture is Arm64Architecture)
                    {
                        burstCompiler.TargetArchitecture = "ARMV8A_AARCH64";
                    }
                }
                else if (config.Platform is WebGLPlatform)
                {
                    burstCompiler = new BurstCompilerForEmscripten();
                    burstCompiler.EnableStaticLinkage = true;
                    burstCompiler.DisableVectors      = false;
                }

                // Only generate marshaling info for platforms that require marshalling (e.g. Windows DotNet)
                // but also if collection checks are enabled (as that is why we need marshalling)
                burstCompiler.EnableJobMarshalling &= config.EnableUnityCollectionsChecks;
                burstCompiler.SafetyChecks          = config.EnableUnityCollectionsChecks;
                burstCompiler.DisableWarnings       = "BC1370"; // Suppress warning for burst function throwing an exception

                var            outputDir    = $"artifacts/{game.Name}/{config.Identifier}_bursted";
                var            burstLibName = "lib_burst_generated";
                DotNetAssembly burstedGame  = setupGame;

                var burstlib = BurstCompiler.SetupBurstCompilationForAssemblies(
                    burstCompiler,
                    setupGame,
                    new NPath(outputDir).Combine("bclobj"),
                    outputDir,
                    burstLibName,
                    out burstedGame);
                if ((config.Platform is IosPlatform || config.Platform is AndroidPlatform) &&
                    config.NativeProgramConfiguration.ToolChain.DynamicLibraryFormat.Extension == "a") // static lib based toolchain
                {
                    il2CppOutputProgram.Libraries.Add(c => c.Equals(config.NativeProgramConfiguration), burstlib);
                    il2CppOutputProgram.Defines.Add(
                        c => c.Equals(config.NativeProgramConfiguration),
                        $"FORCE_PINVOKE_{burstLibName}_INTERNAL");
                }
                else if (config.Platform is WebGLPlatform)
                {
                    il2CppOutputProgram.Libraries.Add(c => c.Equals(config.NativeProgramConfiguration), burstlib);
                }
                else
                {
                    var burstDynamicLib = new NativeProgram(burstLibName);
                    burstDynamicLib.Libraries.Add(c => c.Equals(config.NativeProgramConfiguration), burstlib);
                    burstDynamicLib.Libraries.Add(
                        c => c.Equals(config.NativeProgramConfiguration),
                        gameProgram.TransitiveReferencesFor(config)
                        .Where(
                            p => p is DotsRuntimeCSharpProgram &&
                            ((DotsRuntimeCSharpProgram)p).NativeProgram != null)
                        .Select(
                            p => new NativeProgramAsLibrary(((DotsRuntimeCSharpProgram)p).NativeProgram)
                    {
                        BuildMode = NativeProgramLibraryBuildMode.Dynamic
                    }));

                    if (config.Platform is IosPlatform || config.Platform is AndroidPlatform)
                    {
                        NativeJobsPrebuiltLibrary.AddToNativeProgram(burstDynamicLib);
                    }

                    DotsRuntimeCSharpProgram.SetupDotsRuntimeNativeProgram(burstLibName, burstDynamicLib);

                    var builtBurstLib = burstDynamicLib.SetupSpecificConfiguration(
                        config.NativeProgramConfiguration,
                        config.NativeProgramConfiguration.ToolChain.DynamicLibraryFormat);
                    burstedGame = burstedGame.WithDeployables(builtBurstLib);
                }

                configToSetupGameBursted[config] = burstedGame;
            }
            else
            {
                configToSetupGameBursted[config] = setupGame;
            }
        }

        var configToSetupGameStripped = new Dictionary <DotsRuntimeCSharpProgramConfiguration, DotNetAssembly>();

        foreach (var kvp in configToSetupGameBursted)
        {
            var config    = kvp.Key;
            var setupGame = kvp.Value;

            if (config.ScriptingBackend == ScriptingBackend.TinyIl2cpp)
            {
                setupGame = Il2Cpp.UnityLinker.SetupInvocation(setupGame, $"artifacts/{game.Name}/{config.Identifier}_stripped", config.NativeProgramConfiguration);
                il2CppOutputProgram.SetupConditionalSourcesAndLibrariesForConfig(config, setupGame);
                configToSetupGameStripped[kvp.Key] = setupGame;
            }
            else
            {
                configToSetupGameStripped[kvp.Key] = kvp.Value;
            }
        }

        foreach (var kvp in configToSetupGameStripped)
        {
            var   config     = kvp.Key;
            var   setupGame  = kvp.Value;
            NPath deployPath = GameDeployDirectoryFor(gameProgram, config);

            IDeployable deployedGame;
            NPath       entryPointExecutable = null;

            if (config.ScriptingBackend == ScriptingBackend.TinyIl2cpp)
            {
                var   tinyShellFileName = "tiny_shell.html";
                NPath tinyShellPath     = new NPath(new NPath(gameProgram.FileName).FileNameWithoutExtension).Combine(config.Identifier, "WebTemplate", tinyShellFileName);
                il2CppOutputProgram.DynamicLinkerSettingsForEmscripten().Add(c => c.WithShellFile(tinyShellPath));

                var builtNativeProgram = il2CppOutputProgram.SetupSpecificConfiguration(
                    config.NativeProgramConfiguration,
                    config.NativeProgramConfiguration.ExecutableFormat
                    )
                                         .WithDeployables(setupGame.RecursiveRuntimeDependenciesIncludingSelf.SelectMany(a => a.Deployables.Where(d => !(d is DotNetAssembly) && !(d is StaticLibrary)))
                                                          .ToArray());

                if (builtNativeProgram is IPackagedAppExtension)
                {
                    (builtNativeProgram as IPackagedAppExtension).SetAppPackagingParameters(
                        gameProgram.AsmDefDescription.Name, config.DotsConfiguration);
                }

                if (config.PlatformBuildConfig is WebBuildConfig webBuildConfig)
                {
                    if (webBuildConfig.SingleFile)
                    {
                        deployedGame = new DeployableFile(GameDeployBinaryFor(gameProgram, config));
                        CopyTool.Instance().Setup(deployedGame.Path, (builtNativeProgram as EmscriptenExecutable).Path);
                    }
                    else
                    {
                        deployedGame = builtNativeProgram.DeployTo(deployPath);
                    }

                    var webTemplateFolder = webBuildConfig.WebTemplateFolder;
                    if (String.IsNullOrEmpty(webTemplateFolder))
                    {
                        webTemplateFolder = LowLevelRoot.Combine("WebSupport", "WebTemplates", "Default").ToString();
                    }
                    if (new NPath(webTemplateFolder).IsRelative)
                    {
                        webTemplateFolder = new NPath("../..").Combine(webTemplateFolder).MakeAbsolute().ToString();
                    }
                    if (!new NPath(webTemplateFolder).Combine(tinyShellFileName).FileExists())
                    {
                        throw new InvalidProgramException($"Web template folder \"{webTemplateFolder}\" doesn't contain \"{tinyShellFileName}\" file.");
                    }

                    foreach (var templateFilePath in new NPath(webTemplateFolder).Files(recurse:true))
                    {
                        string fileRelativePath = templateFilePath.ToString().Substring(webTemplateFolder.Length + 1);
                        if (fileRelativePath == tinyShellFileName)
                        {
                            NPath shellPackager = LowLevelRoot.Combine("WebSupport", "package_shell_file.js");
                            NPath tinyShellJS   = LowLevelRoot.Combine("WebSupport", "tiny_shell.js");
                            var   inputs        = new List <NPath> {
                                TinyEmscripten.NodeExe, shellPackager, templateFilePath, tinyShellJS
                            };
                            var commandLineArguments = new List <string> {
                                shellPackager.ToString(), "--outputHtml", tinyShellPath.ToString(), "--inputShellHtml", templateFilePath.ToString(), "--inputShellJs", tinyShellJS.ToString()
                            };
                            NPath exportManifest = new NPath(new NPath(gameProgram.FileName).FileNameWithoutExtension).Combine(config.Identifier, "export.manifest");
                            if (webBuildConfig.SingleFile && exportManifest.FileExists())
                            {
                                inputs.Add(exportManifest.MakeAbsolute().ReadAllLines().Select(d => new NPath(d)));
                                NPath assetRootDirectory = new NPath(new NPath(gameProgram.FileName).FileNameWithoutExtension).Combine(config.Identifier);
                                commandLineArguments.AddRange(new List <string> {
                                    "--assetRootDirectory", assetRootDirectory.ToString(), "--assetManifest", exportManifest.ToString()
                                });
                            }
                            Backend.Current.AddAction(
                                actionName: "Package Shell File",
                                targetFiles: new NPath[] { tinyShellPath },
                                inputs: inputs.ToArray(),
                                executableStringFor: TinyEmscripten.NodeExe.InQuotes(),
                                commandLineArguments: commandLineArguments.Select(d => d.InQuotes()).ToArray()
                                );
                            Backend.Current.AddDependency(deployedGame.Path, tinyShellPath);
                        }
                        else if (!templateFilePath.HasExtension("meta"))
                        {
                            var targetPath = deployPath.Combine(fileRelativePath);
                            CopyTool.Instance().Setup(targetPath, templateFilePath);
                            Backend.Current.AddDependency(deployedGame.Path, targetPath);
                        }
                    }
                }
                else
                {
                    deployedGame = builtNativeProgram.DeployTo(deployPath);
                }

                entryPointExecutable = deployedGame.Path;
                if (config.EnableManagedDebugging && !(builtNativeProgram is IPackagedAppExtension))
                {
                    Backend.Current.AddDependency(deployedGame.Path, Il2Cpp.CopyIL2CPPMetadataFile(deployPath, setupGame));
                }

                // make sure http-server gets fetched from stevedore.  this should probably go elsewhere, but this is
                // a convenient quick hack place.
                if (config.PlatformBuildConfig is WebBuildConfig)
                {
                    var httpserver = new StevedoreArtifact("http-server");
                    httpserver.GenerateUnusualPath();
                    var httpserverpath = httpserver.GetUnusualPath().Combine("bin", "http-server");
                    Backend.Current.AddDependency(deployedGame.Path, httpserverpath);
                }
            }
            else
            {
                deployedGame = setupGame.DeployTo(deployPath);

                var dotNetAssembly = (DotNetAssembly)deployedGame;

                //Usually a dotnet runtime game does not have a static void main(), and instead references another "entrypoint asmdef" that provides it.
                //This is convenient, but what makes it weird is that you have to start YourEntryPoint.exe  instead of YourGame.exe.   Until we have a better
                //solution for this, we're going to copy YourEntryPoint.exe to YourGame.exe, so that it's easier to find, and so that when it runs and you look
                //at the process name you understand what it is.
                if (deployedGame.Path.HasExtension("dll"))
                {
                    var to = deployPath.Combine(deployedGame.Path.ChangeExtension("exe").FileName);
                    // Do an explicit check for the entrypoint.exe as a program may refer to other exes as assembly references
                    var from = dotNetAssembly.RecursiveRuntimeDependenciesIncludingSelf.SingleOrDefault(a => a.Path.FileName == "Unity.Runtime.EntryPoint.exe")?.Path;
                    if (from == null)
                    {
                        throw new InvalidProgramException($"Program {dotNetAssembly.Path} is an executable-like thing, but doesn't reference anything with Main");
                    }
                    Backend.Current.AddDependency(deployedGame.Path, CopyTool.Instance().Setup(to, from));
                    entryPointExecutable = to;
                }
                else
                {
                    entryPointExecutable = deployedGame.Path;
                }
            }

            //Because we use multidag, and try to not run all the setupcode when we just want to create projectfiles, we have a bit of a challenge.
            //Projectfiles require exact start and build commands. So we need to have a cheap way to calculate those. However, it's important that they
            //exactly match the actual place where the buildprogram is going to place our files. If these don't match things break down. The checks
            //in this block, they compare the "quick way to determine where the binary will be placed, and what the start executable is",  with the
            //actual return values returned from .DeployTo(), when we do run the actual buildcode.
            NPath deployedGamePath = GameDeployBinaryFor(gameProgram, config);

            //Identifier with slash means that this is complementary target and we should skip steps which are main target specific.
            //See comment in DotsConfigs.cs DotsConfigs.MakeConfigs() method for details.
            if (config.Identifier.IndexOf('/') != -1)
            {
                continue;
            }

            if (deployedGame.Path != deployedGamePath)
            {
                throw new InvalidProgramException($"We expected deployPath to be {deployedGamePath}, but in reality it was {deployedGame.Path}");
            }
            var expectedEntryPointExecutable = EntryPointExecutableFor(gameProgram, config);
            if (entryPointExecutable != expectedEntryPointExecutable)
            {
                throw new InvalidProgramException($"We expected entryPointExecutable to be {expectedEntryPointExecutable}, but in reality it was {entryPointExecutable}");
            }

            Backend.Current.AddAliasDependency(config.Identifier, deployedGamePath);
        }

        return(gameProgram);
    }
Ejemplo n.º 17
0
        public static void Add(NativeProgram np)
        {
            var allPlatforms = new []
            {
                "Android",
                "Linux",
                "Windows",
                "OSX",
                "IOS",
                "WebGL"
            };

            var staticPlatforms = new[]
            {
                "IOS",
                "WebGL",
            };

            var allArtifact = new StevedoreArtifact("nativejobs-all-public");

            Backend.Current.Register(allArtifact);
            np.PublicIncludeDirectories.Add(allArtifact.Path.Combine("Include"));

            DotsConfiguration DotsConfig(NativeProgramConfiguration npc) => ((DotsRuntimeNativeProgramConfiguration)npc).CSharpConfig.DotsConfiguration;

            foreach (var platform in allPlatforms)
            {
                var platformIncludes = new StevedoreArtifact($"nativejobs-{platform}-public");
                var prebuiltLibName  = $"nativejobs-{platform}" + (staticPlatforms.Contains(platform) ? "-s" : "-d");
                var prebuiltLib      = new StevedoreArtifact(prebuiltLibName);
                Backend.Current.Register(platformIncludes);
                Backend.Current.Register(prebuiltLib);

                np.PublicDefines.Add(c => c.Platform.Name == platform, "BASELIB_USE_DYNAMICLIBRARY=1");
                np.PublicIncludeDirectories.Add(c => c.Platform.Name == platform, platformIncludes.Path.Combine("Platforms", platform, "Include"));

                switch (platform)
                {
                case "Windows":
                    np.Libraries.Add(c => c.Platform.Name == platform,
                                     c => new[] { new MsvcDynamicLibrary(prebuiltLib.Path.Combine("lib", platform.ToLower(), BaselibArchitectureName(c), DotsConfig(c).ToString().ToLower(), "nativejobs.dll")) });
                    break;

                case "Linux":
                case "Android":
                    np.Libraries.Add(c => c.Platform.Name == platform,
                                     c => new[] { new DynamicLibrary(prebuiltLib.Path.Combine("lib", platform.ToLower(), BaselibArchitectureName(c), DotsConfig(c).ToString().ToLower(), "libnativejobs.so")) });
                    break;

                case "OSX":
                    np.Libraries.Add(c => c.Platform.Name == platform,
                                     c => new[] { new DynamicLibrary(prebuiltLib.Path.Combine("lib", platform.ToLower(), BaselibArchitectureName(c), DotsConfig(c).ToString().ToLower(), "libnativejobs.dylib")) });
                    break;

                case "IOS":
                    // this is ugly solution, but I don't see any other way to add static librray to Deployables
                    np.Libraries.Add(c => c.Platform.Name == platform,
                                     c => new[] { new DynamicLibrary(prebuiltLib.Path.Combine("lib", platform.ToLower(), BaselibArchitectureName(c), DotsConfig(c).ToString().ToLower(), "libnativejobs.a")) });
                    break;

                case "WebGL":
                    np.Libraries.Add(c => c.Platform.Name == platform,
                                     c => new[] { new StaticLibrary(prebuiltLib.Path.Combine("lib", platform.ToLower(), BaselibArchitectureName(c), DotsConfig(c).ToString().ToLower(), "libnativejobs.bc")) });
                    break;
                }
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
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.º 20
0
    static NativeProgram CreateLibIl2CppProgram(bool useExceptions, NativeProgram boehmGcProgram = null, string libil2cppname = "libil2cpptiny")
    {
        var fileList = Distribution.GetFileList(libil2cppname).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" }
            },
            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")              } }
            }
        };

        program.Libraries.Add(BoehmGCProgram);

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

        if (libil2cppname == "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"));
            program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp"));
        }
        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.Defines.Add(c => c.ToolChain.Platform is WebGLPlatform && ManagedDebuggingIsEnabled(c),
                                "HOST_WASM=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")
            });

            var MonoSourceDir = Distribution.Path.Combine("external/mono");
            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));

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

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

        return(program);
    }