Ejemplo n.º 1
0
    internal NativeProgram GetOrMakeNativeProgram()
    {
        if (NativeProgram != null)
        {
            return(NativeProgram);
        }

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

        NativeProgram = new NativeProgram(libname);

        NativeProgram.DynamicLinkerSettingsForMac().Add(c => c.WithInstallName(libname + ".dylib"));
        NativeProgram.DynamicLinkerSettingsForIos().Add(c => c.WithInstallName("@executable_path/Frameworks/" + libname + ".dylib"));
        NativeProgram.IncludeDirectories.Add(BuildProgram.BeeRootValue.Combine("cppsupport/include"));

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

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

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

        NativeProgram.Defines.Add(c => c.CodeGen == CodeGen.Debug, "DEBUG=1");

        NativeProgram.Defines.Add("BINDGEM_DOTS=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)));
    }