Add platform specific generation for `SDL_main.h` and `SDL_system.h`

Doesn't compile because of duplicate `_XEvent` definitions.
Linux fails crossgen on Windows due to missing `endian.h`
This commit is contained in:
Susko3 2024-04-06 01:31:08 +02:00
parent 48c9b12f2d
commit a8553fab6e
7 changed files with 389 additions and 2 deletions

View File

@ -0,0 +1,48 @@
/*
<auto-generated/>
C# bindings for Simple DirectMedia Layer.
Original copyright notice of input files:
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace SDL
{
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern int SDL_RegisterApp([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("Uint32")] uint style, void* hInst);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern void SDL_UnregisterApp();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern void SDL_GDKSuspendComplete();
[NativeTypeName("#define main SDL_main")]
public static readonly delegate*<int, sbyte**, int> main = &SDL_main;
}
}

View File

@ -0,0 +1,101 @@
/*
<auto-generated/>
C# bindings for Simple DirectMedia Layer.
Original copyright notice of input files:
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace SDL
{
[StructLayout(LayoutKind.Explicit)]
public partial struct _XEvent
{
}
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern void* SDL_AndroidGetJNIEnv();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern void* SDL_AndroidGetActivity();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern int SDL_GetAndroidSDKVersion();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("SDL_bool")]
[SupportedOSPlatform("Android")]
public static extern int SDL_IsAndroidTV();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("SDL_bool")]
[SupportedOSPlatform("Android")]
public static extern int SDL_IsChromebook();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("SDL_bool")]
[SupportedOSPlatform("Android")]
public static extern int SDL_IsDeXMode();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern void SDL_AndroidBackButton();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[SupportedOSPlatform("Android")]
public static extern sbyte* SDL_AndroidGetInternalStoragePath();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern int SDL_AndroidGetExternalStorageState([NativeTypeName("Uint32 *")] uint* state);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[SupportedOSPlatform("Android")]
public static extern sbyte* SDL_AndroidGetExternalStoragePath();
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern int SDL_AndroidRequestPermission([NativeTypeName("const char *")] sbyte* permission, [NativeTypeName("SDL_AndroidRequestPermissionCallback")] delegate* unmanaged[Cdecl]<void*, sbyte*, int, void> cb, void* userdata);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern int SDL_AndroidShowToast([NativeTypeName("const char *")] sbyte* message, int duration, int gravity, int xoffset, int yoffset);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Android")]
public static extern int SDL_AndroidSendMessage([NativeTypeName("Uint32")] uint command, int param1);
[NativeTypeName("#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01")]
public const int SDL_ANDROID_EXTERNAL_STORAGE_READ = 0x01;
[NativeTypeName("#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02")]
public const int SDL_ANDROID_EXTERNAL_STORAGE_WRITE = 0x02;
}
}

View File

@ -0,0 +1,68 @@
/*
<auto-generated/>
C# bindings for Simple DirectMedia Layer.
Original copyright notice of input files:
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace SDL
{
[StructLayout(LayoutKind.Explicit)]
public partial struct _XEvent
{
}
public enum SDL_WinRT_Path
{
SDL_WINRT_PATH_INSTALLED_LOCATION,
SDL_WINRT_PATH_LOCAL_FOLDER,
SDL_WINRT_PATH_ROAMING_FOLDER,
SDL_WINRT_PATH_TEMP_FOLDER,
}
public enum SDL_WinRT_DeviceFamily
{
SDL_WINRT_DEVICEFAMILY_UNKNOWN,
SDL_WINRT_DEVICEFAMILY_DESKTOP,
SDL_WINRT_DEVICEFAMILY_MOBILE,
SDL_WINRT_DEVICEFAMILY_XBOX,
}
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const wchar_t *")]
[SupportedOSPlatform("Windows")]
public static extern ushort* SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("const char *")]
[SupportedOSPlatform("Windows")]
public static extern sbyte* SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern SDL_WinRT_DeviceFamily SDL_WinRTGetDeviceFamily();
}
}

View File

@ -0,0 +1,71 @@
/*
<auto-generated/>
C# bindings for Simple DirectMedia Layer.
Original copyright notice of input files:
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace SDL
{
public partial struct tagMSG
{
}
[StructLayout(LayoutKind.Explicit)]
public partial struct _XEvent
{
}
public partial struct XTaskQueueObject
{
}
public partial struct XUser
{
}
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern void SDL_SetWindowsMessageHook([NativeTypeName("SDL_WindowsMessageHook")] delegate* unmanaged[Cdecl]<void*, tagMSG*, int> callback, void* userdata);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern int SDL_Direct3D9GetAdapterIndex([NativeTypeName("SDL_DisplayID")] uint displayID);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("SDL_bool")]
[SupportedOSPlatform("Windows")]
public static extern int SDL_DXGIGetOutputInfo([NativeTypeName("SDL_DisplayID")] uint displayID, int* adapterIndex, int* outputIndex);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern int SDL_GDKGetTaskQueue([NativeTypeName("XTaskQueueHandle *")] XTaskQueueObject** outTaskQueue);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("Windows")]
public static extern int SDL_GDKGetDefaultUser([NativeTypeName("XUserHandle *")] XUser** outUserHandle);
}
}

View File

@ -0,0 +1,50 @@
/*
<auto-generated/>
C# bindings for Simple DirectMedia Layer.
Original copyright notice of input files:
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace SDL
{
[StructLayout(LayoutKind.Explicit)]
public partial struct _XEvent
{
}
public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("iOS")]
public static extern int SDL_iPhoneSetAnimationCallback(SDL_Window* window, int interval, [NativeTypeName("void (*)(void *)")] delegate* unmanaged[Cdecl]<void*, void> callback, void* callbackParam);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("iOS")]
public static extern void SDL_iPhoneSetEventPump([NativeTypeName("SDL_bool")] int enabled);
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[SupportedOSPlatform("iOS")]
public static extern void SDL_OnApplicationDidChangeStatusBarOrientation();
}
}

View File

@ -13,6 +13,7 @@ This script should be run manually.
import json
import pathlib
import re
import subprocess
import sys
@ -90,7 +91,6 @@ headers = [
add("SDL3/SDL_loadso.h"),
add("SDL3/SDL_locale.h"),
add("SDL3/SDL_log.h"),
add("SDL3/SDL_main.h"),
add("SDL3/SDL_messagebox.h"),
add("SDL3/SDL_metal.h"),
add("SDL3/SDL_misc.h"),
@ -110,7 +110,6 @@ headers = [
add("SDL3/SDL_stdinc.h"),
add("SDL3/SDL_storage.h"),
add("SDL3/SDL_surface.h"),
add("SDL3/SDL_system.h"),
add("SDL3/SDL_thread.h"),
add("SDL3/SDL_time.h"),
add("SDL3/SDL_timer.h"),
@ -194,6 +193,43 @@ def run_clangsharp(command, header: Header):
return header.output_file()
# regex for ClangSharp-generated SDL functions
generated_function_regex = re.compile(r"public static extern \w+\** (SDL_\w+)\(")
def get_generated_functions(file):
with open(file, "r", encoding="utf-8") as f:
for match in generated_function_regex.finditer(f.read()):
yield match.group(1)
def generate_platform_specific_headers(sdl_api, header: Header, platforms):
all_functions = list(all_funcs_from_header(sdl_api, header))
print(f"💠 {header} platform agnostic")
platform_agnostic_cs = run_clangsharp(base_command, header)
platform_agnostic_functions = list(get_generated_functions(platform_agnostic_cs))
output_files = [platform_agnostic_cs]
for (defines, suffix, platform_name) in platforms:
command = base_command + ["--define-macro"] + defines
if platform_agnostic_functions:
command.append("--exclude")
command.extend(platform_agnostic_functions)
if all_functions:
command.append("--with-attribute")
for f in all_functions:
command.append(f'{f["name"]}=SupportedOSPlatform("{platform_name}")')
print(f"💠 {header} for {suffix}")
header.output_suffix = suffix
output_files.append(run_clangsharp(command, header))
check_generated_functions(sdl_api, header, output_files)
def main():
sdl_api = get_sdl_api_dump()
@ -201,6 +237,19 @@ def main():
output_file = run_clangsharp(base_command, header)
check_generated_functions(sdl_api, header, [output_file])
generate_platform_specific_headers(sdl_api, add("SDL3/SDL_main.h"), [
(["SDL_PLATFORM_WIN32", "SDL_PLATFORM_WINGDK"], "Windows", "Windows"),
])
generate_platform_specific_headers(sdl_api, add("SDL3/SDL_system.h"), [
# define macro, output_suffix, [SupportedOSPlatform]
(["SDL_PLATFORM_ANDROID"], "Android", "Android"),
(["SDL_PLATFORM_IOS"], "iOS", "iOS"),
(["SDL_PLATFORM_LINUX"], "Linux", "Linux"),
(["SDL_PLATFORM_WIN32", "SDL_PLATFORM_WINGDK"], "Windows", "Windows"),
(["SDL_PLATFORM_WINRT"], "WinRT", "Windows"),
])
if __name__ == "__main__":
main()