diff --git a/SDL3-CS.Android.slnf b/SDL3-CS.Android.slnf index 061ae2f..8bef5a4 100644 --- a/SDL3-CS.Android.slnf +++ b/SDL3-CS.Android.slnf @@ -3,6 +3,8 @@ "path": "SDL3-CS.sln", "projects": [ "SDL3-CS\\SDL3-CS.csproj", + "SDL3_ttf-CS\\SDL3-CS_ttf.csproj", + "SDL3_image-CS\\SDL3_image-CS.csproj", "SDL3-CS.SourceGeneration\\SDL3-CS.SourceGeneration.csproj", "SDL3-CS.Android\\SDL3-CS.Android.csproj", "SDL3-CS.Tests\\SDL3-CS.Tests.csproj", diff --git a/SDL3-CS.Desktop.slnf b/SDL3-CS.Desktop.slnf index dba27f4..7eb442c 100644 --- a/SDL3-CS.Desktop.slnf +++ b/SDL3-CS.Desktop.slnf @@ -3,6 +3,8 @@ "path": "SDL3-CS.sln", "projects": [ "SDL3-CS\\SDL3-CS.csproj", + "SDL3_ttf-CS\\SDL3-CS_ttf.csproj", + "SDL3_image-CS\\SDL3_image-CS.csproj", "SDL3-CS.SourceGeneration\\SDL3-CS.SourceGeneration.csproj", "SDL3-CS.Tests\\SDL3-CS.Tests.csproj", "SDL3-CS.Tests.Desktop\\SDL3-CS.Tests.Desktop.csproj" diff --git a/SDL3-CS.SourceGeneration/FriendlyOverloadGenerator.cs b/SDL3-CS.SourceGeneration/FriendlyOverloadGenerator.cs index ce1538d..a65f8e3 100644 --- a/SDL3-CS.SourceGeneration/FriendlyOverloadGenerator.cs +++ b/SDL3-CS.SourceGeneration/FriendlyOverloadGenerator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; + using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -32,9 +33,14 @@ using System; foreach (var kvp in finder.Methods) { + if (kvp.Value.Count == 0) + return; + string filename = kvp.Key; var foundMethods = kvp.Value; + string className = ClassNameFromMethod(foundMethods.First().NativeMethod); + var result = new StringBuilder(); result.Append(file_header); result.Append( @@ -42,7 +48,7 @@ using System; SyntaxFactory.IdentifierName("SDL")) .WithMembers( SyntaxFactory.SingletonList( - SyntaxFactory.ClassDeclaration("SDL3") + SyntaxFactory.ClassDeclaration(className) .WithModifiers( SyntaxFactory.TokenList( SyntaxFactory.Token(SyntaxKind.UnsafeKeyword), @@ -54,6 +60,16 @@ using System; } } + private static string ClassNameFromMethod(MethodDeclarationSyntax methodNode) + { + if (methodNode.Parent is ClassDeclarationSyntax classDeclaration) + { + return classDeclaration.Identifier.Text; + } + + return "SDL3"; // fallback! + } + private static MemberDeclarationSyntax makeFriendlyMethod(GeneratedMethod gm) { var returnType = gm.RequiredChanges.HasFlag(Changes.ChangeReturnTypeToString) diff --git a/SDL3-CS.SourceGeneration/UnfriendlyMethodFinder.cs b/SDL3-CS.SourceGeneration/UnfriendlyMethodFinder.cs index 4554ede..24eeb9f 100644 --- a/SDL3-CS.SourceGeneration/UnfriendlyMethodFinder.cs +++ b/SDL3-CS.SourceGeneration/UnfriendlyMethodFinder.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; + using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -15,33 +16,19 @@ namespace SDL.SourceGeneration { public readonly Dictionary> Methods = new Dictionary>(); + private static readonly string[] sdlPrefixes = ["SDL", "TTF", "IMG"]; + /// /// Checks whether the method is from any SDL library. - /// It identifies those by checking if the method has a DllImport attribute for a library starting with "SDL". + /// It identifies those by checking the SDL prefix in the method name. /// private static bool IsMethodFromSDL(MethodDeclarationSyntax methodNode) { - if (methodNode.AttributeLists.Count == 0) + string? libraryPrefix = methodNode.Identifier.ValueText.Split('_').FirstOrDefault(); + if (libraryPrefix == null) return false; - foreach (var attributeList in methodNode.AttributeLists) - { - foreach (var attribute in attributeList.Attributes) - { - if (attribute.Name.ToString() != "DllImport") continue; - if (attribute.ArgumentList == null || attribute.ArgumentList.Arguments.Count <= 0) continue; // this should never happen, but rather continue than throw - - var libraryNameArgument = attribute.ArgumentList.Arguments[0]; - - if (libraryNameArgument.Expression is LiteralExpressionSyntax literal && - literal.Token.ValueText.StartsWith("SDL", StringComparison.Ordinal)) - { - return true; - } - } - } - - return false; + return sdlPrefixes.Contains(libraryPrefix); } public void OnVisitSyntaxNode(SyntaxNode syntaxNode) diff --git a/SDL3-CS.iOS.slnf b/SDL3-CS.iOS.slnf index 321cc23..957e7fa 100644 --- a/SDL3-CS.iOS.slnf +++ b/SDL3-CS.iOS.slnf @@ -3,6 +3,8 @@ "path": "SDL3-CS.sln", "projects": [ "SDL3-CS\\SDL3-CS.csproj", + "SDL3_ttf-CS\\SDL3-CS_ttf.csproj", + "SDL3_image-CS\\SDL3_image-CS.csproj", "SDL3-CS.SourceGeneration\\SDL3-CS.SourceGeneration.csproj", "SDL3-CS.Tests\\SDL3-CS.Tests.csproj", "SDL3-CS.Tests.iOS\\SDL3-CS.Tests.iOS.csproj" diff --git a/SDL3-CS.sln b/SDL3-CS.sln index a7f2209..c0b2111 100644 --- a/SDL3-CS.sln +++ b/SDL3-CS.sln @@ -27,6 +27,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Tests.iOS", "SDL3-C EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL3-CS.Tests.Desktop", "SDL3-CS.Tests.Desktop\SDL3-CS.Tests.Desktop.csproj", "{7E8D719A-5B69-43B7-A9D5-385B6FE7F411}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL3_ttf-CS", "SDL3_ttf-CS\SDL3_ttf-CS.csproj", "{8E37EB82-ACC4-4656-A6E5-DB298AE72066}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL3_image-CS", "SDL3_image-CS\SDL3_image-CS.csproj", "{A0D6FC5F-BA26-4298-ABF0-234D2481E323}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +65,14 @@ Global {7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Debug|Any CPU.Build.0 = Debug|Any CPU {7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Release|Any CPU.ActiveCfg = Release|Any CPU {7E8D719A-5B69-43B7-A9D5-385B6FE7F411}.Release|Any CPU.Build.0 = Release|Any CPU + {8E37EB82-ACC4-4656-A6E5-DB298AE72066}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E37EB82-ACC4-4656-A6E5-DB298AE72066}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E37EB82-ACC4-4656-A6E5-DB298AE72066}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E37EB82-ACC4-4656-A6E5-DB298AE72066}.Release|Any CPU.Build.0 = Release|Any CPU + {A0D6FC5F-BA26-4298-ABF0-234D2481E323}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0D6FC5F-BA26-4298-ABF0-234D2481E323}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0D6FC5F-BA26-4298-ABF0-234D2481E323}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0D6FC5F-BA26-4298-ABF0-234D2481E323}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SDL3-CS/SDL3-CS.csproj b/SDL3-CS/SDL3-CS.csproj index dd15bdd..94fde2d 100644 --- a/SDL3-CS/SDL3-CS.csproj +++ b/SDL3-CS/SDL3-CS.csproj @@ -73,8 +73,8 @@ runtimes/linux-arm/native true - - runtimes/ios/native + + runtimes/ios/native/SDL3.xcframework true diff --git a/SDL3-CS/generate_bindings.py b/SDL3-CS/generate_bindings.py index 023e294..52addbf 100644 --- a/SDL3-CS/generate_bindings.py +++ b/SDL3-CS/generate_bindings.py @@ -73,22 +73,22 @@ class Header: def output_file(self): """Location of generated C# file.""" if self.output_suffix is None: - return csproj_root / f"{self.base}/ClangSharp/{self.name}.g.cs" + return repository_root / f"{self.base}-CS" / f"{self.base}/ClangSharp/{self.name}.g.cs" else: - return csproj_root / f"{self.base}/ClangSharp/{self.name}.{self.output_suffix}.g.cs" + return repository_root / f"{self.base}-CS" / f"{self.base}/ClangSharp/{self.name}.{self.output_suffix}.g.cs" def rsp_files(self): """Location of ClangSharp response files.""" - yield csproj_root / f"{self.base}/{self.name}.rsp" + yield repository_root / f"{self.base}-CS" / f"{self.base}/{self.name}.rsp" if self.output_suffix is not None: - yield csproj_root / f"{self.base}/{self.name}.{self.output_suffix}.rsp" + yield repository_root / f"{self.base}-CS" / f"{self.base}/{self.name}.{self.output_suffix}.rsp" def cs_file(self): """Location of the manually-written C# file that implements some parts of the header.""" if self.output_suffix is None: - return csproj_root / f"{self.base}/{self.name}.cs" + return repository_root / f"{self.base}-CS" / f"{self.base}/{self.name}.cs" else: - return csproj_root / f"{self.base}/{self.name}.{self.output_suffix}.cs" + return repository_root / f"{self.base}-CS" / f"{self.base}/{self.name}.{self.output_suffix}.cs" def make_header_fuzzy(s: str) -> Header: @@ -265,7 +265,6 @@ base_command = [ "--include-directory", repository_root / SDL_lib_include_root["SDL3"], "--include-directory", repository_root / SDL_lib_include_root["SDL3_image"], "--include-directory", repository_root / SDL_lib_include_root["SDL3_ttf"], - "--methodClassName", "SDL3", "--namespace", "SDL", "--remap", @@ -308,6 +307,8 @@ def run_clangsharp(command, header: Header): "--file", header.input_file(), "--output", header.output_file(), "--libraryPath", header.base, + + "--methodClassName", header.base, ] for rsp in header.rsp_files(): diff --git a/SDL3_image-CS/SDL3_image-CS.csproj b/SDL3_image-CS/SDL3_image-CS.csproj new file mode 100644 index 0000000..d594c0b --- /dev/null +++ b/SDL3_image-CS/SDL3_image-CS.csproj @@ -0,0 +1,138 @@ + + + + net8.0 + SDL + enable + true + $(NoWarn);SYSLIB1054;CA1401 + + + + ppy Pty Ltd + ppy Pty Ltd + Copyright (c) 2024 ppy Pty Ltd + ppy.SDL3_image-CS + ppy.SDL3_image-CS + Automated release. + MIT + https://github.com/ppy/SDL3-CS + https://github.com/ppy/SDL3-CS + + + + + + + + + + + all + + + + all + + + + all + + + + + + runtimes/win-x64/native + true + + + runtimes/win-arm64/native + true + + + runtimes/win-x86/native + true + + + runtimes/win-x64/native + true + + + runtimes/win-arm64/native + true + + + runtimes/win-x86/native + true + + + runtimes/win-x64/native + true + + + runtimes/win-arm64/native + true + + + runtimes/win-x86/native + true + + + runtimes/win-x64/native + true + + + runtimes/win-arm64/native + true + + + runtimes/win-x86/native + true + + + runtimes/osx-x64/native + true + + + runtimes/osx-arm64/native + true + + + runtimes/linux-x64/native + true + + + runtimes/linux-x86/native + true + + + runtimes/linux-arm64/native + true + + + runtimes/linux-arm/native + true + + + runtimes/ios/native/SDL3.xcframework + true + + + runtimes/android-arm/native + true + + + runtimes/android-arm64/native + true + + + runtimes/android-x64/native + true + + + runtimes/android-x86/native + true + + + + diff --git a/SDL3-CS/SDL3_image/ClangSharp/SDL_image.g.cs b/SDL3_image-CS/SDL3_image/ClangSharp/SDL_image.g.cs similarity index 99% rename from SDL3-CS/SDL3_image/ClangSharp/SDL_image.g.cs rename to SDL3_image-CS/SDL3_image/ClangSharp/SDL_image.g.cs index aaa6500..7be3e82 100644 --- a/SDL3-CS/SDL3_image/ClangSharp/SDL_image.g.cs +++ b/SDL3_image-CS/SDL3_image/ClangSharp/SDL_image.g.cs @@ -40,7 +40,7 @@ namespace SDL public int* delays; } - public static unsafe partial class SDL3 + public static unsafe partial class SDL3_image { [DllImport("SDL3_image", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern int IMG_Version(); diff --git a/SDL3_ttf-CS/SDL3_ttf-CS.csproj b/SDL3_ttf-CS/SDL3_ttf-CS.csproj new file mode 100644 index 0000000..0c8eec4 --- /dev/null +++ b/SDL3_ttf-CS/SDL3_ttf-CS.csproj @@ -0,0 +1,102 @@ + + + + net8.0 + SDL + enable + true + $(NoWarn);SYSLIB1054;CA1401 + + + + ppy Pty Ltd + ppy Pty Ltd + Copyright (c) 2024 ppy Pty Ltd + ppy.SDL3_ttf-CS + ppy.SDL3_ttf-CS + Automated release. + MIT + https://github.com/ppy/SDL3-CS + https://github.com/ppy/SDL3-CS + + + + + + + + + + + all + + + + all + + + + all + + + + + + runtimes/win-x64/native + true + + + runtimes/win-arm64/native + true + + + runtimes/win-x86/native + true + + + runtimes/osx-x64/native + true + + + runtimes/osx-arm64/native + true + + + runtimes/linux-x64/native + true + + + runtimes/linux-x86/native + true + + + runtimes/linux-arm64/native + true + + + runtimes/linux-arm/native + true + + + runtimes/ios/native/SDL3.xcframework + true + + + runtimes/android-arm/native + true + + + runtimes/android-arm64/native + true + + + runtimes/android-x64/native + true + + + runtimes/android-x86/native + true + + + + diff --git a/SDL3-CS/SDL3_ttf/ClangSharp/SDL_textengine.g.cs b/SDL3_ttf-CS/SDL3_ttf/ClangSharp/SDL_textengine.g.cs similarity index 100% rename from SDL3-CS/SDL3_ttf/ClangSharp/SDL_textengine.g.cs rename to SDL3_ttf-CS/SDL3_ttf/ClangSharp/SDL_textengine.g.cs diff --git a/SDL3-CS/SDL3_ttf/ClangSharp/SDL_ttf.g.cs b/SDL3_ttf-CS/SDL3_ttf/ClangSharp/SDL_ttf.g.cs similarity index 99% rename from SDL3-CS/SDL3_ttf/ClangSharp/SDL_ttf.g.cs rename to SDL3_ttf-CS/SDL3_ttf/ClangSharp/SDL_ttf.g.cs index fe13e1a..8134818 100644 --- a/SDL3-CS/SDL3_ttf/ClangSharp/SDL_ttf.g.cs +++ b/SDL3_ttf-CS/SDL3_ttf/ClangSharp/SDL_ttf.g.cs @@ -84,7 +84,7 @@ namespace SDL public SDL_Rect rect; } - public static unsafe partial class SDL3 + public static unsafe partial class SDL3_ttf { [DllImport("SDL3_ttf", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern int TTF_Version();