Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor binding context API #36

Merged
merged 6 commits into from
Aug 4, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bindgen.NET" Version="0.1.13"/>
<PackageReference Include="Bindgen.NET" Version="0.1.14"/>
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions src/Flecs.NET.Bindgen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
DllFilePaths =
{
"flecs",
"runtimes/linux-x64/native/flecs",
"runtimes/linux-arm64/native/flecs",
"runtimes/osx-x64/native/flecs",
"runtimes/osx-arm64/native/flecs",
"libflecs",
"runtimes/linux-x64/native/libflecs",
"runtimes/linux-arm64/native/libflecs",
"runtimes/osx-x64/native/libflecs",
"runtimes/osx-arm64/native/libflecs",
"runtimes/win-x64/native/flecs",
"runtimes/win-arm64/native/flecs"
},
Expand Down
28 changes: 19 additions & 9 deletions src/Flecs.NET.Bindings/Flecs.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13801,10 +13801,11 @@ static BindgenInternal()
DllFilePaths = new System.Collections.Generic.List<string>
{
"flecs",
"runtimes/linux-x64/native/flecs",
"runtimes/linux-arm64/native/flecs",
"runtimes/osx-x64/native/flecs",
"runtimes/osx-arm64/native/flecs",
"libflecs",
"runtimes/linux-x64/native/libflecs",
"runtimes/linux-arm64/native/libflecs",
"runtimes/osx-x64/native/libflecs",
"runtimes/osx-arm64/native/libflecs",
"runtimes/win-x64/native/flecs",
"runtimes/win-arm64/native/flecs"
};
Expand Down Expand Up @@ -13858,8 +13859,8 @@ public partial class BindgenInternal

public static bool TryLoad(string path, out System.IntPtr handle)
{
#if NET5_0_OR_GREATER
return System.Runtime.InteropServices.NativeLibrary.TryLoad(path, out handle);
#if NETCOREAPP3_0_OR_GREATER
return System.Runtime.InteropServices.NativeLibrary.TryLoad(path, System.Reflection.Assembly.GetExecutingAssembly(), null, out handle);
#else
handle = System.IntPtr.Zero;
if (IsLinux)
Expand All @@ -13874,7 +13875,7 @@ public static bool TryLoad(string path, out System.IntPtr handle)

public static System.IntPtr GetExport(string symbol)
{
#if NET5_0_OR_GREATER
#if NETCOREAPP3_0_OR_GREATER
return System.Runtime.InteropServices.NativeLibrary.GetExport(LibraryHandle, symbol);
#else
if (IsLinux)
Expand Down Expand Up @@ -13919,6 +13920,14 @@ public static System.IntPtr GetExport(string symbol)

public static void ResolveLibrary()
{
System.IntPtr handle = default;
#if NETCOREAPP3_0_OR_GREATER
foreach (string dllFilePath in DllFilePaths)
{
if (TryLoad(dllFilePath, out handle))
goto Return;
}
#else
string fileExtension;
if (IsLinux)
fileExtension = ".so";
Expand All @@ -13928,12 +13937,12 @@ public static void ResolveLibrary()
fileExtension = ".dll";
else
throw new System.InvalidOperationException("Can't determine native library file extension for the current system.");
System.IntPtr handle = default;
foreach (string dllFilePath in DllFilePaths)
{
string fileName = System.IO.Path.GetFileName(dllFilePath);
string parentDir = $"{dllFilePath}/..";
string searchDir = System.IO.Path.IsPathRooted(dllFilePath) ? System.IO.Path.GetFullPath(parentDir) + "/" : System.IO.Path.GetFullPath(System.AppDomain.CurrentDomain.BaseDirectory + parentDir) + "/";
string exeDir = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!);
string searchDir = System.IO.Path.IsPathRooted(dllFilePath) ? System.IO.Path.GetFullPath(parentDir) + "/" : System.IO.Path.GetFullPath($"{exeDir}/{parentDir}") + "/";
if (TryLoad($"{searchDir}{fileName}", out handle))
goto Return;
if (TryLoad($"{searchDir}{fileName}{fileExtension}", out handle))
Expand All @@ -13951,6 +13960,7 @@ public static void ResolveLibrary()
goto Return;
}

#endif
#if NET7_0_OR_GREATER
handle = System.Runtime.InteropServices.NativeLibrary.GetMainProgramHandle();
#else
Expand Down
11 changes: 6 additions & 5 deletions src/Flecs.NET/Core/AlertBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Flecs.NET.Core.BindingContext;
using Flecs.NET.Utilities;
using static Flecs.NET.Bindings.flecs;

Expand Down Expand Up @@ -65,8 +66,8 @@ public AlertBuilder(ecs_world_t* world, string name) : this(world)

ecs_entity_desc_t desc = default;
desc.name = nativeName;
desc.sep = BindingContext.DefaultSeparator;
desc.root_sep = BindingContext.DefaultSeparator;
desc.sep = Pointers.DefaultSeparator;
desc.root_sep = Pointers.DefaultSeparator;
Desc.entity = ecs_entity_init(World, &desc);
}

Expand All @@ -87,12 +88,12 @@ public Alert Build()
{
fixed (ecs_alert_desc_t* alertDesc = &Desc)
{
BindingContext.QueryContext* queryContext = Memory.Alloc<BindingContext.QueryContext>(1);
QueryContext* queryContext = Memory.Alloc<QueryContext>(1);
queryContext[0] = QueryBuilder.Context;

alertDesc->query = QueryBuilder.Desc;
alertDesc->query.binding_ctx = queryContext;
alertDesc->query.binding_ctx_free = BindingContext.QueryContextFreePointer;
alertDesc->query.binding_ctx_free = Pointers.QueryContextFree;

Entity entity = new Entity(World, ecs_alert_init(World, alertDesc));

Expand Down Expand Up @@ -258,7 +259,7 @@ public ref AlertBuilder Member<T>(string member, string var = "")

ulong id = Type<T>.Id(World);
ulong memberId = ecs_lookup_path_w_sep(World, id, nativeMember,
BindingContext.DefaultSeparator, BindingContext.DefaultSeparator, Utils.False);
Pointers.DefaultSeparator, Pointers.DefaultSeparator, Utils.False);

AlertVar(var);

Expand Down
Loading
Loading