示例#1
0
 public void SetupConditionalSourcesAndLibrariesForConfig(DotsRuntimeCSharpProgramConfiguration config, DotNetAssembly setupGame)
 {
     NPath[] il2cppGeneratedFiles = SetupInvocation(setupGame);
     //todo: stop comparing identifier.
     Sources.Add(npc => ((DotsRuntimeNativeProgramConfiguration)npc).CSharpConfig == config, il2cppGeneratedFiles);
     Libraries.Add(npc => ((DotsRuntimeNativeProgramConfiguration)npc).CSharpConfig == config, setupGame.RecursiveRuntimeDependenciesIncludingSelf.SelectMany(r => r.Deployables.OfType <StaticLibrary>()));
 }
示例#2
0
 public static DotNetAssembly SetupInvocation(
     DotNetAssembly inputAssembly,
     DotsRuntimeCSharpProgramConfiguration dotsConfig)
 {
     return(inputAssembly.ApplyDotNetAssembliesPostProcessor($"artifacts/{inputAssembly.Path.FileNameWithoutExtension}/{dotsConfig.Identifier}/post_typereg/",
                                                             (inputAssemblies, targetDirectory) => AddActions(dotsConfig, inputAssemblies, targetDirectory)));
 }
示例#3
0
    private static NPath GameDeployBinaryFor(AsmDefCSharpProgram game, DotsRuntimeCSharpProgramConfiguration config)
    {
        var fileName = config.ScriptingBackend == ScriptingBackend.Dotnet ?
                       game.FileName
            : new NPath(game.AsmDefDescription.Name.Replace(".", "-")).ChangeExtension(config.NativeProgramConfiguration.ExecutableFormat.Extension);

        return(GameDeployDirectoryFor(game, config).Combine(fileName));
    }
示例#4
0
    private static NPath EntryPointExecutableFor(AsmDefCSharpProgram gameProgram, DotsRuntimeCSharpProgramConfiguration config)
    {
        if (gameProgram.FileName.EndsWith(".exe") || config.ScriptingBackend != ScriptingBackend.Dotnet)
        {
            return(GameDeployBinaryFor(gameProgram, config));
        }

        return(GameDeployDirectoryFor(gameProgram, config).Combine(new NPath(gameProgram.FileName).FileNameWithoutExtension + ".exe"));
    }
示例#5
0
 private static NPath GameDeployDirectoryFor(AsmDefCSharpProgram game, DotsRuntimeCSharpProgramConfiguration config)
 {
     if (config.FinalOutputDirectory != null)
     {
         return(new NPath("../..").Combine(config.FinalOutputDirectory));
     }
     else
     {
         return($"../../Builds/{config.Identifier}");
     }
 }
示例#6
0
    private static StartInfo StartInfoFor(DotsRuntimeCSharpProgramConfiguration config, NPath deployedGamePath)
    {
        if (config.Platform is WebGLPlatform)
        {
            return(new BrowserStartInfo(new Uri(deployedGamePath.MakeAbsolute().ToString(SlashMode.Native)).AbsoluteUri));
        }

        return(new ExecutableStartInfo(new Shell.ExecuteArgs()
        {
            Executable = deployedGamePath, WorkingDirectory = deployedGamePath.Parent
        }, true));
    }
示例#7
0
    private static NPath GameDeployBinaryFor(AsmDefCSharpProgram game, DotsRuntimeCSharpProgramConfiguration config)
    {
        var ext = config.NativeProgramConfiguration.ExecutableFormat.Extension;

        if (!ext.StartsWith(".") && !String.IsNullOrEmpty(ext))
        {
            ext = "." + ext;
        }
        var fileName = config.ScriptingBackend == ScriptingBackend.Dotnet ?
                       game.FileName
            : new NPath(game.AsmDefDescription.Name) + ext;

        return(GameDeployDirectoryFor(game, config).Combine(fileName));
    }
示例#8
0
    static void SetupTestForConfig(string name, AsmDefCSharpProgram testProgram, DotsRuntimeCSharpProgramConfiguration config)
    {
        var builtTest           = testProgram.SetupSpecificConfiguration(config);
        var postILProcessedTest = ILPostProcessorTool.SetupInvocation(builtTest, config, testProgram.Defines.For(config).ToArray());
        var postTypeRegGenTest  = TypeRegistrationTool.SetupInvocation(postILProcessedTest, config);

        NPath deployDirectory = GameDeployDirectoryFor(testProgram, config);
        var   deployed        = postTypeRegGenTest.DeployTo(deployDirectory);

        testProgram.ProjectFile.OutputPath.Add(c => c == config, deployDirectory);
        testProgram.ProjectFile.BuildCommand.Add(c => c == config, new BeeBuildCommand(deployed.Path.ToString(), false, false).ToExecuteArgs());

        Backend.Current.AddAliasDependency($"{name.ToLower()}-{ config.Identifier}", deployed.Path);
        Backend.Current.AddAliasDependency("tests", deployed.Path);
    }
示例#9
0
    static bool CanSkipSetupOf(string programName, DotsRuntimeCSharpProgramConfiguration config)
    {
        /* This is disabled for now (11/12/2019) because we have a theory that because there will be very few
         * bee targets overall, we don't need to optimize project files as much as we used to.
         * But we should re-enable this check if we see project files taking too long to generate.
         */
        /*if (IsRequestedTargetExactlyProjectFiles())
         *  return true;*/

        if (!IsRequestedTargetExactlySingleAppSingleConfig())
        {
            return(false);
        }

        return(config.Identifier != StandaloneBeeDriver.GetCommandLineTargets().Single());
    }
示例#10
0
        public void SetupConditionalSourcesAndLibrariesForConfig(DotsRuntimeCSharpProgramConfiguration config, DotNetAssembly setupGame)
        {
            NPath[] il2cppGeneratedFiles = SetupInvocation(setupGame, config).ResolveWithFileSystem();

            //todo: stop comparing identifier.
            Sources.Add(npc => ((DotsRuntimeNativeProgramConfiguration)npc).CSharpConfig == config, il2cppGeneratedFiles);
            var staticLibs = setupGame.RecursiveRuntimeDependenciesIncludingSelf.SelectMany(r => r.Deployables.OfType <StaticLibrary>());

            Libraries.Add(npc => ((DotsRuntimeNativeProgramConfiguration)npc).CSharpConfig == config, staticLibs);

            // force pinvoke internal for static libraries
            staticLibs.ForEach(l => Defines.Add(npc => ((DotsRuntimeNativeProgramConfiguration)npc).CSharpConfig == config, PinvokeInternalDefineFor(l)));

            if (config.EnableManagedDebugging)
            {
                SupportFiles.Add(c => c == config.NativeProgramConfiguration, new DeployableFile(Il2CppTargetDirForAssembly(setupGame).Combine(metadataFilePath), new NPath(metadataFilePath)));
            }
        }
示例#11
0
    private static StartInfo StartInfoFor(DotsRuntimeCSharpProgramConfiguration config, IDeployable deployedGame)
    {
        var exe = deployedGame.Path;

        if (deployedGame is DotNetAssembly dotNetGame)
        {
            exe = dotNetGame.Path.ChangeExtension("exe");
        }

        if (config.Platform is WebGLPlatform)
        {
            return(new BrowserStartInfo(new Uri(deployedGame.Path.MakeAbsolute().ToString(SlashMode.Native)).AbsoluteUri));
        }

        return(new ExecutableStartInfo(new Shell.ExecuteArgs()
        {
            Executable = exe, WorkingDirectory = exe.Parent
        }, true));
    }
示例#12
0
    public void SetupInvocation(DotNetAssembly inputProgram, DotsRuntimeCSharpProgramConfiguration config)
    {
        var result = BindGemOutputFor(inputProgram, config);

        if (result == null)
        {
            return;
        }

        var assembly = inputProgram;

        var args = new List <string>
        {
            "-v",
            "-dots",
            assembly.RuntimeDependencies.Select(rd => $"-r {rd.Path.InQuotes()}"),
            assembly.RuntimeDependencies.Select(r => BindGemOutputFor(r, config)).ExcludeNulls().Select(bo => $"-cppInclude {bo.Header}"),
            $"-define_guard BUILD_{assembly.Path.FileName.ToUpper().Replace(".", "_")}",
            assembly.Path.InQuotes(),
            "-o",
            result.Cpp.Parent.Combine(result.Cpp.FileNameWithoutExtension).InQuotes()
        };

        var program = new DotNetRunnableProgram(BuiltBindGemProgram);

        var inputs = new List <NPath>
        {
            BuiltBindGemProgram.Path,
            assembly.RecursiveRuntimeDependenciesIncludingSelf.Select(d => d.Path)
        };

        // Note: the MakeAbsolute() below also takes care of changing slashes on Windows,
        // because Windows really hates forward slashes when used as an executable path
        // to cmd.exe
        Backend.Current.AddAction(
            actionName: "BindGem",
            targetFiles: result.Files,
            inputs: inputs.ToArray(),
            executableStringFor: program.InvocationString,
            commandLineArguments: args.ToArray(),
            supportResponseFile: false
            );
    }
示例#13
0
    static bool CanSkipSetupOf(string programName, DotsRuntimeCSharpProgramConfiguration config)
    {
        /* This is disabled for now (11/12/2019) because we have a theory that because there will be very few
         * bee targets overall, we don't need to optimize project files as much as we used to.
         * But we should re-enable this check if we see project files taking too long to generate.
         */
        /*if (IsRequestedTargetExactlyProjectFiles())
         *  return true;*/

        if (!IsRequestedTargetExactlySingleAppSingleConfig())
        {
            return(false);
        }

        //If there is complementary target its config identifier is generated from main target identifier by adding slash symbol
        //and complementary target name. So only part before slash should be compared with target from command line.
        //See comment in DotsConfigs.cs, DotsConfigs.MakeConfigs() method for details
        var slash      = config.Identifier.IndexOf('/');
        var identifier = slash == -1 ? config.Identifier : config.Identifier.Substring(0, slash);

        return(identifier != StandaloneBeeDriver.GetCommandLineTargets().Single());
    }
示例#14
0
    public override DotsRuntimeCSharpProgramConfiguration CustomizeConfigForSettings(DotsRuntimeCSharpProgramConfiguration config, FriendlyJObject settings)
    {
        var executableFormat = GetExecutableFormatForConfig(DotsConfigs.DotsConfigForSettings(settings, out _),
                                                            SupportsManagedDebugging && config.EnableManagedDebugging)
                               .WithLinkerSetting <EmscriptenDynamicLinker>(e => e
                                                                            .WithCustomFlags_workaround(new[] { "-s", "TOTAL_STACK=" + (settings.GetString("WasmStackSize") ?? "512KB") })
                                                                            .WithCustomFlags_workaround(new[] { "-s", "TOTAL_MEMORY=" + (settings.GetString("WasmMemorySize") ?? "128MB") })
                                                                            .WithCustomFlags_workaround(new[] { "-s", "ALLOW_MEMORY_GROWTH=" + (settings.GetBool("AllowWasmMemoryGrowth")?"1":"0") })
                                                                            .WithCustomFlags_workaround(new[] { "-s", "MINIFY_HTML=" + (settings.GetBool("MinifyHTMLFile")?"1":"0") })
                                                                            .WithCustomFlags_workaround(settings.GetBool("MinifyOutputWithClosure") ? new[] {
            "--closure-args", "\"--platform native --externs " + BuildProgram.BeeRoot.Combine("closure_externs.js").ToString() + "\"",
            "--closure", "1", "-s", "CLOSURE_WARNINGS=warn"
        } : new[] { "" })
                                                                            .WithCustomFlags_workaround(new[] { settings.GetBool("EmbedCpuProfiler")?"--cpuprofiler":"" })
                                                                            .WithCustomFlags_workaround(new[] { settings.GetBool("EmbedMemoryProfiler")?"--memoryprofiler":"" })
                                                                            .WithCustomFlags_workaround(new[] { settings.GetBool("IncludeSymbolsForBrowserCallstacks")?"--profiling-funcs":"" })
                                                                            .WithCustomFlags_workaround(new[] { "-s", "ASSERTIONS=" + (settings.GetBool("EmitRuntimeAllocationDebugChecks")?"2":(settings.GetBool("EmitRuntimeMemoryDebugChecks")?"1":"0")) })
                                                                            .WithCustomFlags_workaround(new[] { "-s", "SAFE_HEAP=" + (settings.GetBool("EmitRuntimeMemoryDebugChecks")?"1":"0") })
                                                                            .WithSingleFile(settings.GetBool("SingleFile"))
                                                                            // Specify extra EmscriptenCmdLine overrides last so they can override previous settings.
                                                                            .WithCustomFlags_workaround(new[] { settings.GetString("EmscriptenCmdLine") ?? "" })
                                                                            );

        config.NativeProgramConfiguration = new DotsRuntimeNativeProgramConfiguration(
            config.NativeProgramConfiguration.CodeGen,
            config.NativeProgramConfiguration.ToolChain,
            config.Identifier,
            config,
            executableFormat: executableFormat);
        config.PlatformBuildConfig = new WebBuildConfig
        {
            SingleFile        = settings.GetBool("SingleFile"),
            WebTemplateFolder = settings.GetString("WebTemplateFolder"),
        };
        return(config);
    }
示例#15
0
    private static void AddActions(DotsRuntimeCSharpProgramConfiguration dotsConfig, DotNetAssembly[] inputAssemblies, NPath targetDirectory)
    {
        var args = new List <string>
        {
            targetDirectory.MakeAbsolute().QuoteForProcessStart(),
            dotsConfig.NativeProgramConfiguration.ToolChain.Architecture.Bits.ToString(),
            dotsConfig.ScriptingBackend == ScriptingBackend.Dotnet ? "DOTSDotNet" : "DOTSNative",
            dotsConfig.Identifier.Contains("release") ? "release" : "debug", // We check for 'release' so we can generate 'debug' info for both debug and develop configs
            inputAssemblies.OrderByDependencies().Select(p => p.Path.MakeAbsolute().QuoteForProcessStart())
        }.ToArray();

        var inputFiles = inputAssemblies.SelectMany(InputPathsFor)
                         .Concat(new[] { _typeRegRunnableProgram.Value.Path }).ToArray();
        var targetFiles = inputAssemblies.SelectMany(i => TargetPathsFor(targetDirectory, i))
                          .Where(p => p.FileName != "Unity.Entities.StaticTypeRegistry.pdb")
                          .ToArray();

        Backend.Current.AddAction("TypeRegGen",
                                  targetFiles,
                                  inputFiles,
                                  _typeRegRunnableProgram.Value.InvocationString,
                                  args,
                                  allowedOutputSubstrings: new[] { "Static Type Registry Generation Time:" });
    }
 public DotsRuntimeNativeProgramConfiguration(CodeGen codeGen, ToolChain toolChain, string identifier, DotsRuntimeCSharpProgramConfiguration cSharpConfig, NativeProgramFormat executableFormat = null) : base(codeGen, toolChain, false)
 {
     Identifier        = identifier;
     CSharpConfig      = cSharpConfig;
     _executableFormat = executableFormat;
 }
示例#17
0
    public static NPath[] SetupInvocation(DotNetAssembly inputAssembly, DotsRuntimeCSharpProgramConfiguration config)
    {
        var profile               = "unitytiny";
        var il2CppTargetDir       = Il2CppTargetDirForAssembly(inputAssembly);
        var enableDevelopmentMode =
            config.EnableUnityCollectionsChecks || config.DotsConfiguration != DotsConfiguration.Release;

        var args = new List <string>()
        {
            "--convert-to-cpp",

            //  "--directory", $"{InputAssembly.Path.Parent}",
            "--generatedcppdir",
            $"{il2CppTargetDir}",

            // Make settings out of these
            $"--dotnetprofile={profile}", // Resolve from DotNetAssembly
            "--libil2cpp-static",
            "--emit-null-checks=0",
            "--enable-array-bounds-check=0",
            //"--enable-stacktrace=1"
            //"--profiler-report",
            //"--enable-stats",
        };

        if (config.EnableManagedDebugging)
        {
            args.Add("--enable-debugger");
            // When the debugger is enabled, the develop and release configurations take a very long
            // time to build, because the debugger code generation injects lots of code. Limit the
            // assemblies that we generate debug information for so that build times will be reasonable.
            if (config.Platform is WebGLPlatform ||
                config.DotsConfiguration == DotsConfiguration.Develop ||
                config.DotsConfiguration == DotsConfiguration.Release)
            {
                foreach (var assembly in inputAssembly.RecursiveRuntimeDependenciesIncludingSelf.Where(r => r is DotNetAssembly))
                {
                    if (!assembly.Path.FileName.StartsWith("Unity.") && assembly.Path.FileName != "mscorlib.dll" &&
                        assembly.Path.FileName != "netstandard.dll" && assembly.Path.FileName != "UnsafeUtility.dll")
                    {
                        args.Add($"--debug-assembly-name={assembly.Path.FileName}");
                    }
                }

                args.Add("--debug-assembly-name=Unity.Entities.dll");
            }
        }

        if (enableDevelopmentMode)
        {
            args.Add("--development-mode");
        }

        var iarrdis = MoveExeToFront(inputAssembly.RecursiveRuntimeDependenciesIncludingSelf);

        args.AddRange(
            iarrdis.SelectMany(a =>
                               new[] { "--assembly", a.Path.ToString() }));

        args.Add($"--entry-assembly-name={inputAssembly.Path.FileNameWithoutExtension}");

        var il2cppInputs = Distribution.GetFileList("build/deploy/net471").ResolveWithFileSystem()
                           .Concat(iarrdis.SelectMany(a => a.Paths.ResolveWithFileSystem()))
                           .Concat(new[] { Distribution.Path.Combine("libil2cpptiny", "libil2cpptiny.icalls") }.ResolveWithFileSystem());

        if (new NPath(Il2CppRunnableProgram).Parent.Exists())
        {
            il2cppInputs = il2cppInputs.Concat(new NPath(Il2CppRunnableProgram).Parent.Files().ResolveWithFileSystem());
        }

        Backend.Current.AddAction(
            "Il2Cpp",
            targetFiles: new NPath[] {},
            inputs: il2cppInputs.ToArray(),
            Il2CppRunnableProgram.ToString(),
            args.ToArray(),
            targetDirectories: new NPath[] { il2CppTargetDir });

        if (il2CppTargetDir.DirectoryExists())
        {
            var il2cppOutputFiles = il2CppTargetDir.Files();
            if (il2cppOutputFiles.Length != 0)
            {
                return(il2cppOutputFiles);
            }
        }

        return(new NPath[] { il2CppTargetDir.Combine("dummy.cpp") });
    }
示例#18
0
 static BindGemResult BindGemOutputFor(DotNetAssembly assembly, DotsRuntimeCSharpProgramConfiguration config) => SupportsBindgem(assembly.Path.FileName) ? MakeBindGemResultFor(assembly.Path.FileName, config) : null;
示例#19
0
    public static NPath[] SetupInvocation(DotNetAssembly inputAssembly, DotsRuntimeCSharpProgramConfiguration config)
    {
        var profile         = "unitytiny";
        var il2CppTargetDir = Il2CppTargetDirForAssembly(inputAssembly);

        var args = new List <string>()
        {
            "--convert-to-cpp",
            "--disable-cpp-chunks",

            //  "--directory", $"{InputAssembly.Path.Parent}",
            "--generatedcppdir",
            $"{il2CppTargetDir}",

            // Make settings out of these
            $"--dotnetprofile={profile}", // Resolve from DotNetAssembly
            "--libil2cpp-static",
            "--emit-null-checks=0",
            "--enable-array-bounds-check=0",
            "--enable-predictable-output",
            //"--enable-stacktrace=1"
            //"--profiler-report",
            //"--enable-stats",
        };

        if (config.EnableManagedDebugging)
        {
            args.Add("--enable-debugger");
        }

        if (config.EnableUnityCollectionsChecks)
        {
            args.Add("--development-mode");
        }

        var iarrdis = MoveExeToFront(inputAssembly.RecursiveRuntimeDependenciesIncludingSelf);

        args.AddRange(
            iarrdis.SelectMany(a =>
                               new[] { "--assembly", a.Path.ToString() }));

        var sharedFileNames = new List <string>
        {
            // static files
            //"Il2CppComCallableWrappers.cpp",
            //"Il2CppProjectedComCallableWrapperMethods.cpp",
            "driver.cpp",
            "GenericMethods.cpp",
            "Generics.cpp",
            "Il2CppGenericComDefinitions.cpp",
            "ReversePInvokeWrappers.cpp",
        };

        var nonDebuggerExtraFileNames = new[]
        {
            "TinyTypes.cpp",
            "StaticConstructors.cpp",
            "StringLiterals.cpp",
            "StaticInitialization.cpp"
        };

        var debuggerExtraFileNames = new[]
        {
            "Il2CppGenericClassTable.c",
            "Il2CppGenericInstDefinitions.c",
            "Il2CppGenericMethodDefinitions.c",
            "Il2CppGenericMethodTable.c",
            "Il2CppMetadataRegistration.c",
            "Il2CppMetadataUsage.c",
            "Il2CppTypeDefinitions.c",
            "Il2CppAttributes.cpp",
            "Il2CppCodeRegistration.cpp",
            "Il2CppCompilerCalculateTypeValues.cpp",
            "Il2CppCompilerCalculateTypeValuesTable.cpp",
            "Il2CppGenericMethodPointerTable.cpp",
            "Il2CppInteropDataTable.cpp",
            "Il2CppInvokerTable.cpp",
            "Il2CppReversePInvokeWrapperTable.cpp",
            "UnresolvedVirtualCallStubs.cpp",
        };

        IEnumerable <string> il2cppOutputFileNames = sharedFileNames;


        if (config.EnableManagedDebugging)
        {
            il2cppOutputFileNames = il2cppOutputFileNames.Concat(debuggerExtraFileNames);
            il2cppOutputFileNames = il2cppOutputFileNames.Concat(iarrdis.Select(asm => asm.Path.FileNameWithoutExtension + "_Debugger.c"));
            il2cppOutputFileNames = il2cppOutputFileNames.Concat(iarrdis.Select(asm => asm.Path.FileNameWithoutExtension + "_Codegen.c"));
        }
        else
        {
            il2cppOutputFileNames = il2cppOutputFileNames.Concat(nonDebuggerExtraFileNames);
        }

        var il2cppOutputFiles = il2cppOutputFileNames.Concat(iarrdis.Select(asm => asm.Path.FileNameWithoutExtension + ".cpp"))
                                .Select(il2CppTargetDir.Combine).ToArray();

        var il2cppInputs = Distribution.GetFileList("build")
                           .Concat(iarrdis.SelectMany(a => a.Paths))
                           .Concat(new[] { Distribution.Path.Combine("libil2cpptiny", "libil2cpptiny.icalls") })
                           .Concat(new[] { Il2CppDependencies.GetFileList().First() });

        var finalOutputFiles = il2cppOutputFiles;

        if (config.EnableManagedDebugging)
        {
            finalOutputFiles = finalOutputFiles.Concat(new[] { il2CppTargetDir.Combine("Data/Metadata/global-metadata.dat") }).ToArray();
        }

        Backend.Current.AddAction(
            "Il2Cpp",
            targetFiles: finalOutputFiles,
            inputs: il2cppInputs.ToArray(),
            Il2CppRunnableProgram.InvocationString,
            args.ToArray());

        return(il2cppOutputFiles);
    }
示例#20
0
 public virtual DotsRuntimeCSharpProgramConfiguration CustomizeConfigForSettings(DotsRuntimeCSharpProgramConfiguration config, FriendlyJObject settings) => config;