Exemplo n.º 1
0
        /// <summary>
        /// The API bindings generation utility that can produce scripting bindings for another languages to the native code.
        /// </summary>
        public static void GenerateBindings(BuildData buildData, Module module, ref BuildOptions moduleOptions, out BindingsResult bindings)
        {
            // Parse module (or load from cache)
            var moduleInfo = ParseModule(buildData, module, moduleOptions);

            bindings = new BindingsResult
            {
                UseBindings             = UseBindings(moduleInfo),
                GeneratedCppFilePath    = Path.Combine(moduleOptions.IntermediateFolder, module.Name + ".Bindings.Gen.cpp"),
                GeneratedCSharpFilePath = Path.Combine(moduleOptions.IntermediateFolder, module.Name + ".Bindings.Gen.cs"),
            };

            if (bindings.UseBindings)
            {
                buildData.Modules.TryGetValue(moduleInfo.Module, out var moduleBuildInfo);

                // Ensure that generated files are included into build
                if (EngineConfiguration.WithCSharp(buildData.TargetOptions) && !moduleBuildInfo.SourceFiles.Contains(bindings.GeneratedCSharpFilePath))
                {
                    moduleBuildInfo.SourceFiles.Add(bindings.GeneratedCSharpFilePath);
                }
            }

            // Skip if module is cached (no scripting API changed)
            if (moduleInfo.IsFromCache)
            {
                return;
            }

            // Initialize parsed API
            using (new ProfileEventScope("Init"))
            {
                moduleInfo.Init(buildData);
            }

            // Generate bindings for scripting
            if (bindings.UseBindings)
            {
                Log.Verbose($"Generating API bindings for {module.Name} ({moduleInfo.Name})");
                using (new ProfileEventScope("Cpp"))
                    GenerateCpp(buildData, moduleInfo, ref bindings);
                if (EngineConfiguration.WithCSharp(buildData.TargetOptions))
                {
                    using (new ProfileEventScope("CSharp"))
                        GenerateCSharp(buildData, moduleInfo, ref bindings);
                }
                GenerateBinaryModuleBindings?.Invoke(buildData, moduleInfo, ref bindings);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The API bindings generation utility that can produce scripting bindings for another languages to the native code.
        /// </summary>
        public static void GenerateBindings(BuildData buildData, Module module, ref BuildOptions moduleOptions, out BindingsResult bindings)
        {
            // Parse module (or load from cache)
            bindings = new BindingsResult
            {
                GeneratedCppFilePath    = Path.Combine(moduleOptions.IntermediateFolder, module.Name + ".Bindings.Gen.cpp"),
                GeneratedCSharpFilePath = Path.Combine(moduleOptions.IntermediateFolder, module.Name + ".Bindings.Gen.cs"),
            };
            var moduleInfo = ParseModule(buildData, module, moduleOptions);

            // Process parsed API
            foreach (var child in moduleInfo.Children)
            {
                try
                {
                    foreach (var apiTypeInfo in child.Children)
                    {
                        ProcessAndValidate(buildData, apiTypeInfo);
                    }
                }
                catch (Exception)
                {
                    if (child is FileInfo fileInfo)
                    {
                        Log.Error($"Failed to validate '{fileInfo.Name}' file to generate bindings.");
                    }
                    throw;
                }
            }

            // Generate bindings for scripting
            Log.Verbose($"Generating API bindings for {module.Name} ({moduleInfo.Name})");
            GenerateCpp(buildData, moduleInfo, ref bindings);
            GenerateCSharp(buildData, moduleInfo, ref bindings);

            // TODO: add support for extending this code and support generating bindings for other scripting languages
        }
Exemplo n.º 3
0
        /// <summary>
        /// The API bindings generation utility that can produce scripting bindings for another languages to the native code.
        /// </summary>
        public static void GenerateBindings(BuildData buildData, Module module, ref BuildOptions moduleOptions, out BindingsResult bindings)
        {
            // Parse module (or load from cache)
            var moduleInfo = ParseModule(buildData, module, moduleOptions);

            bindings = new BindingsResult
            {
                UseBindings             = UseBindings(moduleInfo),
                GeneratedCppFilePath    = Path.Combine(moduleOptions.IntermediateFolder, module.Name + ".Bindings.Gen.cpp"),
                GeneratedCSharpFilePath = Path.Combine(moduleOptions.IntermediateFolder, module.Name + ".Bindings.Gen.cs"),
            };

            if (bindings.UseBindings)
            {
                buildData.Modules.TryGetValue(moduleInfo.Module, out var moduleBuildInfo);

                // Ensure that generated files are included into build
                if (!moduleBuildInfo.SourceFiles.Contains(bindings.GeneratedCSharpFilePath))
                {
                    moduleBuildInfo.SourceFiles.Add(bindings.GeneratedCSharpFilePath);
                }
            }

            // Skip if module is cached (no scripting API changed)
            if (moduleInfo.IsFromCache)
            {
                return;
            }

            // Process parsed API
            using (new ProfileEventScope("Process"))
            {
                foreach (var child in moduleInfo.Children)
                {
                    try
                    {
                        foreach (var apiTypeInfo in child.Children)
                        {
                            ProcessAndValidate(buildData, apiTypeInfo);
                        }
                    }
                    catch (Exception)
                    {
                        if (child is FileInfo fileInfo)
                        {
                            Log.Error($"Failed to validate '{fileInfo.Name}' file to generate bindings.");
                        }
                        throw;
                    }
                }
            }

            // Generate bindings for scripting
            if (bindings.UseBindings)
            {
                Log.Verbose($"Generating API bindings for {module.Name} ({moduleInfo.Name})");
                using (new ProfileEventScope("Cpp"))
                    GenerateCpp(buildData, moduleInfo, ref bindings);
                using (new ProfileEventScope("CSharp"))
                    GenerateCSharp(buildData, moduleInfo, ref bindings);

                // TODO: add support for extending this code and support generating bindings for other scripting languages
            }
        }