Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion Generator/workflow.yml → .cosy/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
version: "1.0"

env:
# Global environment vars if needed
Workspace: "./.CosyCache/Workspace"

targets:
clone-repos:
steps:
- name: Make temp dir
uses: core:mkdir@v1
with:
path: ${{ env.Workspace }}
- name: Clone Hexa.NET.ImGui
run: git clone --recursive https://github.com/HexaEngine/Hexa.NET.ImGui.git
- name: Clone cimgui
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,7 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd

token.txt
token.txt

# Cosy CI/CD workflows tool
.CosyCache/
6 changes: 3 additions & 3 deletions Examples/ExampleAndroid/ExampleAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-android</TargetFramework>
<TargetFramework>net9.0-android</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.7.0.4" />
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.15.0.1" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.7.1.1" />
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.17.0" />
<PackageReference Include="Hexa.NET.ImGui.Widgets" Version="1.1.18" />
</ItemGroup>

Expand Down
3 changes: 1 addition & 2 deletions Generator/Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HexaGen.Legacy" Version="1.0.7" />
<PackageReference Include="HexaGen" Version="1.1.23.3" />
<PackageReference Include="HexaGen.BuildSystems" Version="0.0.1-alpha" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 5 additions & 8 deletions Generator/ImGuiCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Generator
{
using CppAst;
using HexaGen;
using HexaGen.Batteries.Legacy.Steps;
using HexaGen.Core.CSharp;
using HexaGen.CppAst.Model.Metadata;
using HexaGen.FunctionGeneration;
using HexaGen.FunctionGeneration.ParameterWriters;
using HexaGen.GenerationSteps;
using System.Collections.Generic;

public class ImGuiCodeGenerator : CsCodeGenerator
Expand All @@ -23,13 +23,9 @@ protected override void OnConfigureGenerator()
protected override void OnPostConfigure(CsCodeGeneratorConfig config)
{
config.LogLevel = HexaGen.Core.Logging.LogSeverity.Error;
config.Defines.Add("IMGUI_USE_WCHAR32");
config.Defines.Add("IMGUI_ENABLE_FREETYPE");
config.Defines.Add("CIMGUI_DEFINE_ENUMS_AND_STRUCTS");
LogLevel = HexaGen.Core.Logging.LogSeverity.Error;

Environment.SetEnvironmentVariable("VCINSTALLDIR", @"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532");
Environment.SetEnvironmentVariable("VCToolsInstallDir", @"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\");
//Environment.SetEnvironmentVariable("VCINSTALLDIR", @"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532");
//Environment.SetEnvironmentVariable("VCToolsInstallDir", @"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\");
}

public override bool GenerateCore(CppCompilation compilation, List<string> headerFiles, string outputPath, List<string>? allowedHeaders = null)
Expand All @@ -45,6 +41,7 @@ public ImGuiFunctionGenerator(CsCodeGeneratorConfig config) : base(config)
AddRule(new FunctionGenRuleRef());
AddRule(new FunctionGenRuleSpan());
AddRule(new FunctionGenRuleString());
AddRule(new FunctionGenRuleArray(config));
AddStep(new ImGuiDefaultValueStep());
AddStep(new ImGuiReturnVariationStep());
AddStep(new StringReturnGenStep());
Expand Down
7 changes: 5 additions & 2 deletions Generator/ImGuiDefinitionsPatch.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Generator
{
using CppAst;
using HexaGen;
using HexaGen.Core.Mapping;
using HexaGen.CppAst.Model.Metadata;
using HexaGen.Patching;
using Microsoft.CodeAnalysis;

public enum InternalsGenerationType
{
Expand All @@ -23,12 +24,14 @@ public ImGuiDefinitionsPatch(InternalsGenerationType generationType)
this.generationType = generationType;
}

protected override void PatchCompilation(CsCodeGeneratorConfig settings, CppCompilation compilation)
protected override void PatchCompilation(CsCodeGeneratorConfig settings, ParseResult result)
{
if (settings.LibName == "cimgui_impl")
{
return;
}
var compilation = result.Compilation;

ImguiDefinitions imguiDefinitions = new();
imguiDefinitions.LoadFrom(settings.LibName);

Expand Down
2 changes: 1 addition & 1 deletion Generator/ImGuiPostPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Apply(PatchContext context, CsCodeGeneratorMetadata metadat
}

Generate(metadata, CImGuiHeader, CImGuiInternalsConfig, ImGuiInternalsOutputPath, InternalsGenerationType.OnlyInternals, out var internalsMetadata);
metadata.Merge(internalsMetadata, true);
metadata.Merge(internalsMetadata, new HexaGen.Metadata.MergeOptions() { MergeFunctionTable = true });
File.Delete(Path.Combine(ImGuiOutputPath, "FunctionTable.cs")); // Delete base.
File.Delete(Path.Combine(ImGuiInternalsOutputPath, "FunctionTable.cs")); // Delete intermediate.

Expand Down
3 changes: 1 addition & 2 deletions Generator/ImGuiPrePatch.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace Generator
{
using CppAst;
using HexaGen;
using HexaGen.Patching;
using System.Collections.Generic;

public class ImGuiPrePatch : PrePatch
{
public override void Apply(PatchContext context, CsCodeGeneratorConfig config, List<string> files, CppCompilation compilation)
public override void Apply(PatchContext context, CsCodeGeneratorConfig config, List<string> files, ParseResult result)
{
if (config.LibName != "cimgui")
{
Expand Down
3 changes: 1 addition & 2 deletions Generator/ImGuizmoPrePatch.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace Generator
{
using CppAst;
using HexaGen;
using HexaGen.Core.Mapping;
using HexaGen.Patching;

public class ImGuizmoPrePatch : PrePatch
{
protected override void PatchCompilation(CsCodeGeneratorConfig settings, CppCompilation compilation)
protected override void PatchCompilation(CsCodeGeneratorConfig settings, ParseResult parseResult)
{
if (settings.LibName != "cimguizmo")
{
Expand Down
6 changes: 3 additions & 3 deletions Generator/ImVectorPatch.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace Generator
{
using CppAst;
using HexaGen;
using HexaGen.CppAst.Model.Declarations;
using HexaGen.Patching;
using System.Collections.Generic;

public class ImVectorPatch : PrePatch
{
public override void Apply(PatchContext context, CsCodeGeneratorConfig settings, List<string> files, CppCompilation compilation)
public override void Apply(PatchContext context, CsCodeGeneratorConfig settings, List<string> files, ParseResult result)
{
base.Apply(context, settings, files, compilation);
base.Apply(context, settings, files, result);
}

protected override void PatchClass(CsCodeGeneratorConfig settings, CppClass cppClass)
Expand Down
14 changes: 8 additions & 6 deletions Generator/ManualFunctionGenRuleSpan.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
namespace Generator
{
using CppAst;
using HexaGen;
using HexaGen.Core.CSharp;
using HexaGen.Core.Mapping;
using HexaGen.CppAst.Model.Declarations;
using HexaGen.CppAst.Model.Types;
using HexaGen.FunctionGeneration;

public class ManualFunctionGenRuleSpan : FunctionGenRule
{
public override CsParameterInfo CreateParameter(CppParameter cppParameter, string csParamName, CppPrimitiveKind kind, Direction direction, CsCodeGeneratorConfig settings, IList<CppParameter> cppParameters, CsParameterInfo[] csParameterList, int paramIndex, CsFunctionVariation variation)
public override CsParameterInfo CreateParameter(CppParameter cppParameter, ParameterMapping? mapping, string csParamName, CppPrimitiveKind kind, Direction direction, CsCodeGeneratorConfig settings, IList<CppParameter> cppParameters, CsParameterInfo[] csParameters, int paramIndex, CsFunctionVariation variation)
{
if (cppParameter.Type is CppArrayType arrayType)
{
if (arrayType.Size > 0)
{
return new(csParamName, cppParameter.Type, new($"ReadOnlySpan<{settings.GetCsTypeName(arrayType.ElementType, false)}>", kind), direction);
return new(csParamName, cppParameter.Type, new($"ReadOnlySpan<{settings.GetCsTypeName(arrayType.ElementType)}>", kind), direction);
}
}
else if (cppParameter.Type.IsString())
else if (cppParameter.Type.IsString(settings, out var stringKind))
{
switch (kind)
switch (stringKind)
{
case CppPrimitiveKind.Char:
if (direction == Direction.InOut || direction == Direction.Out) break;
Expand All @@ -30,7 +32,7 @@ public override CsParameterInfo CreateParameter(CppParameter cppParameter, strin
}
}

return CreateDefaultWrapperParameter(cppParameter, csParamName, kind, direction, settings);
return CreateDefaultWrapperParameter(cppParameter, mapping, csParamName, kind, direction, settings);
}
}
}
5 changes: 5 additions & 0 deletions Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Generator.Targets;
using HexaGen.BuildSystems;

var start = DateTime.Now;
var builder =
BuildSystemBuilder.Create()
.WithArgs(args)
Expand All @@ -14,6 +15,10 @@

var context = builder.Build();
context.Execute();
var end = DateTime.Now;
var duration = end - start;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Generation completed in {duration.TotalSeconds:F2} seconds.");

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("All done! Have fun!");
Expand Down
2 changes: 1 addition & 1 deletion Generator/Targets/ImGuiBackendsTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void GenerateBackend(string[] headers, string configPath, string
.GetMetadata(out metadata)
.GetConfig(out var config);

lib?.Merge(metadata, true);
lib?.Merge(metadata, new() { MergeFunctionTable = true });

string destPath = Path.Combine(originalOutput, "FunctionTable.cs");
File.Move(Path.Combine(output, "FunctionTable.cs"), destPath, true);
Expand Down
22 changes: 12 additions & 10 deletions Generator/config.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Usings": [ "System.Numerics" ],
"Defines": [ "CIMGUI_VARGS0=1" ],
"Defines": [ "CIMGUI_VARGS0=1", "IMGUI_USE_WCHAR32=1", "IMGUI_ENABLE_FREETYPE=1", "CIMGUI_DEFINE_ENUMS_AND_STRUCTS=1" ],
"ImportType": "FunctionTable",
"EnableExperimentalOptions": true,
"GenerateConstructorsForStructs": true,
Expand Down Expand Up @@ -32,24 +32,24 @@
],
"ArrayMappings": [
{
"Primitive": 11,
"Primitive": "Float",
"Size": 4,
"Name": "ref Vector4"
"Name": "Vector4"
},
{
"Primitive": 11,
"Primitive": "Float",
"Size": 3,
"Name": "ref Vector3"
"Name": "Vector3"
},
{
"Primitive": 11,
"Primitive": "Float",
"Size": 2,
"Name": "ref Vector2"
"Name": "Vector2"
},
{
"Primitive": 11,
"Primitive": "Float",
"Size": 16,
"Name": "ref Matrix4x4"
"Name": "Matrix4x4"
}
],
"TypeMappings": {
Expand Down Expand Up @@ -80,6 +80,8 @@
"ImGuiSelectionUserData": "long",
"ImStbTexteditState": "STBTexteditState",
"stbrp_node_im": "StbrpNode",
"va_list": "nuint"
"va_list": "nuint",
"ImTextureID": "ImTextureID",
"ImFileHandle": "ImFileHandle"
}
}
Loading