From 710c8b87e1e88d30272682af481f3a8cff93ec43 Mon Sep 17 00:00:00 2001 From: BeanCheeseBurrito Date: Sun, 27 Oct 2024 21:28:51 -0700 Subject: [PATCH] Pass zig include headers to binding generator --- README.md | 2 -- src/Directory.Build.props | 25 +++++++++++++++ .../Flecs.NET.Bindgen.csproj | 16 ++++++++++ src/Flecs.NET.Bindgen/Program.cs | 31 +++---------------- src/Flecs.NET.Native/Flecs.NET.Native.csproj | 28 +---------------- 5 files changed, 46 insertions(+), 56 deletions(-) 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..7f634308 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -25,4 +25,29 @@ true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + $([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..9ee287e0 100644 --- a/src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj +++ b/src/Flecs.NET.Bindgen/Flecs.NET.Bindgen.csproj @@ -13,6 +13,22 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/src/Flecs.NET.Bindgen/Program.cs b/src/Flecs.NET.Bindgen/Program.cs index b5e3b15a..40371f06 100644 --- a/src/Flecs.NET.Bindgen/Program.cs +++ b/src/Flecs.NET.Bindgen/Program.cs @@ -23,7 +23,7 @@ SuppressedWarnings = { "CS8981" }, - IncludeBuiltInClangHeaders = true, + SystemIncludeDirectories = { Path.Combine(BuildConstants.ZigLibPath, "include") }, InputFile = GetFlecsHeaderPath(), OutputFile = GetBindingsOutputPath(), @@ -34,10 +34,12 @@ }; if (OperatingSystem.IsMacOS()) - bindingOptions.SystemIncludeDirectories.Add(GetMacOsHeaders()); + bindingOptions.SystemIncludeDirectories.Add(Path.Combine(BuildConstants.ZigLibPath, "libc", "include", "any-macos-any")); BindingGenerator.Generate(bindingOptions); +return; + string GetFlecsHeaderPath([CallerFilePath] string filePath = "") { return Path.GetFullPath(Path.Combine(filePath, "..", "..", "..", "submodules", "flecs", "distr", "flecs.h")); @@ -47,28 +49,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..a4d63427 100644 --- a/src/Flecs.NET.Native/Flecs.NET.Native.csproj +++ b/src/Flecs.NET.Native/Flecs.NET.Native.csproj @@ -11,7 +11,7 @@ false false false - $(NoWarn);CS2008 + $(NoWarn);CS2008;NU5128 @@ -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)