diff --git a/README.md b/README.md index 8d892886..bbd1838b 100644 --- a/README.md +++ b/README.md @@ -182,8 +182,6 @@ Reference the project and import the native libraries. You should now be able to ### Running the bindings generator Low-level bindings to the flecs C API are pre-generated and included in the [Flecs.NET.Bindings](https://github.com/BeanCheeseBurrito/Flecs.NET/tree/main/src/Flecs.NET.Bindings) project by default. If needed, you can run the following command to regenerate the bindings file. -> [!NOTE] -> The binding generator needs access to system headers on MacOS. Ensure that XCode is installed. ```console dotnet run --project src/Flecs.NET.Bindgen ``` diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 1463b731..617521d3 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -25,4 +25,42 @@ true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + %3b + + + + + %3B + + + + + + $([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) + + + + + + win-x64 + win-arm64 + + + + + linux-x64 + linux-arm64 + + + + + osx-x64 + osx-arm64 + + + diff --git a/src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj b/src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj index bd7f57ef..e4d8b382 100644 --- a/src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj +++ b/src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj @@ -13,6 +13,28 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + public static class BuildConstants { public const string ZigLibPath = "$(ZigLibPath)"$(SemicolonChar) } + + + + + + diff --git a/src/Flecs.NET.Bindgen/Program.cs b/src/Flecs.NET.Bindgen/Program.cs index b5e3b15a..75dd2176 100644 --- a/src/Flecs.NET.Bindgen/Program.cs +++ b/src/Flecs.NET.Bindgen/Program.cs @@ -23,7 +23,11 @@ SuppressedWarnings = { "CS8981" }, - IncludeBuiltInClangHeaders = true, + SystemIncludeDirectories = + { + Path.Combine(BuildConstants.ZigLibPath, "include"), + Path.Combine(BuildConstants.ZigLibPath, "libc", "include", "any-macos-any") + }, InputFile = GetFlecsHeaderPath(), OutputFile = GetBindingsOutputPath(), @@ -33,11 +37,10 @@ GenerateStructEqualityFunctions = true }; -if (OperatingSystem.IsMacOS()) - bindingOptions.SystemIncludeDirectories.Add(GetMacOsHeaders()); - BindingGenerator.Generate(bindingOptions); +return; + string GetFlecsHeaderPath([CallerFilePath] string filePath = "") { return Path.GetFullPath(Path.Combine(filePath, "..", "..", "..", "submodules", "flecs", "distr", "flecs.h")); @@ -47,28 +50,3 @@ string GetBindingsOutputPath([CallerFilePath] string filePath = "") { return Path.GetFullPath(Path.Combine(filePath, "..", "..", "Flecs.NET.Bindings", "Flecs.g.cs")); } - -string GetMacOsHeaders() -{ - using Process process = new() - { - StartInfo = new ProcessStartInfo - { - FileName = "xcrun", - Arguments = "--sdk macosx --show-sdk-path", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true - } - }; - - process.Start(); - process.WaitForExit(); - - string path = process.StandardOutput.ReadToEnd().Trim(); - - if (!Directory.Exists(path)) - throw new DirectoryNotFoundException("Couldn't find system headers. Install XCode."); - - return path + "/usr/include"; -} diff --git a/src/Flecs.NET.Native/Flecs.NET.Native.csproj b/src/Flecs.NET.Native/Flecs.NET.Native.csproj index af81d4ce..10c8fe90 100644 --- a/src/Flecs.NET.Native/Flecs.NET.Native.csproj +++ b/src/Flecs.NET.Native/Flecs.NET.Native.csproj @@ -20,10 +20,6 @@ Native libraries for flecs - - $([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) - - @@ -40,28 +36,6 @@ - - - - - win-x64 - win-arm64 - - - - - linux-x64 - linux-arm64 - - - - - osx-x64 - osx-arm64 - - - - $(HostRuntime)