Commit Graph

51 Commits

Author SHA1 Message Date
Susko3 f6ba38cb90 Add string-friendly overload for `SDL_SetClipboardData`
`string[]` marshalling is horrible to implement manually, so I'm using `LibraryImport`.
2024-04-23 14:45:12 +02:00
Dan Balasescu f862cb535d Add desktop tests project
The primary purpose of this is to split out the handling of the native
libs. This is a consequence of using ProjectReference, and resolves the
following issues:

1. When compiling for iOS, it really doesn't like multiple files being
   included in the same output path. Example: all Windows SDL.dll files
   placed as SDL.dll in the output path.
2. Even if (1) was somehow resolved, the iOS build also doesn't like the
   linux-specific .so files being included.
3. As a consequence of (1), it's likely that the project already doesn't
   work on some configurations. For example, because win-x86 is
   specified as the last item, it will likely take precedence over all
   other versions.
4. It looks like `RuntimeIdentifier` is not project-transitive, against
   my expectations. I really want the project to both select the correct
   single native lib for the current platform, and also support
   compiling with a RID (`dotnet build -r ...`).

So now we only copy the correct lib to the output path, and don't do it
while packaging (not required).
2024-04-20 19:30:24 +09:00
Susko3 c27b7b770f Regenerate SDL3 bindings
Includes changes up to commit:
a2eb2697a3

70ce808c09
is manually excluded to keep SDL_Keycode sane.
2024-04-17 18:37:09 +02:00
Susko3 7be592a9c1 Inline `ensureTrailingNull()` 2024-04-17 13:37:11 +02:00
Susko3 1cb22f0e73 Make `Utf8String.Raw` internal 2024-04-17 13:24:26 +02:00
Susko3 567e6e4f7c Use Utf8String directly in `fixed` statement 2024-04-17 13:24:23 +02:00
Dan Balasescu 7b5e406c81 Fix inspections 2024-04-17 12:08:38 +09:00
Susko3 498a714965 Remove unnecessary `UTF8GetBytes()` helper 2024-04-16 13:01:13 +02:00
Susko3 439f85de53 Add `Utf8String`, sourcegen and tests 2024-04-16 12:59:17 +02:00
Susko3 a37167744f Add helper for making null-terminated byte arrays 2024-04-15 20:27:41 +02:00
Susko3 120eb3d181 Migrate custom patch to friendly overloads
Some changes are still required.
2024-04-15 19:40:55 +02:00
Susko3 9e9350323e Regenerate patch to resolve conflicts and include `base-commit`
Path formatted with
```sh
git format-patch --base HEAD^ HEAD^
```
2024-04-15 19:37:06 +02:00
Susko3 1cf170b72e Update bindings to SDL commit 0429f5d6a36fc35b551bcc2acd4a40c2db6dab82 2024-04-15 19:37:01 +02:00
Dean Herbert 31ada83091 Merge pull request #2 from smoogipoo/add-native-build-workflow 2024-04-07 15:52:31 +08:00
Dan Balasescu 5a14fe0b28 Fix native library path 2024-04-07 15:22:10 +09:00
Dan Balasescu 657e22bb00 Move NuGet config to final csproj 2024-04-07 15:17:29 +09:00
Dan Balasescu 7021e3b3ef Include native artifacts in package 2024-04-07 14:46:27 +09:00
Dan Balasescu a4519330e5 Refactorings + auto styling 2024-04-07 12:47:29 +09:00
Susko3 d919dacea8 Add [MustDisposeResource] annoations to array helpers 2024-04-06 15:37:29 +02:00
Susko3 a19e75b298 Change SDL sources to use more proper types
This helps consumers avoid having to do ugly casts
as was previously done in `SDL_quit.cs`.

It's very important that the underlying type doesn't change
as that might break ABI compat.
2024-04-06 14:43:18 +02:00
Susko3 95056ef317 Add friendly `string?` overloads to C `(const) char *` functions
This is done by adding a `Unsafe_` prefix to `(const) char *` (C# `byte*`) functions.
I am using `string?` instead of `ReadOnlyMemory<byte>?` because the returned pointer can
get invalidated and cause memory-safety issues.

The returned pointer is automatically freed if the return type is `char *`.
I've checked that the documentation for all functions (except in SDL_stdinc.h)
requires calling `SDL_free()` on the pointer.
2024-04-06 14:36:36 +02:00
Susko3 bad4e097ae Add source generator for `ReadOnlySpan<byte>` overloads of C `const char *` functions 2024-04-06 14:24:33 +02:00
Susko3 a8f1d7f1ba Add memory safe IDisposable overloads to array-returning functions
This could be done with a source generator, but this is simpler.
2024-04-06 14:20:08 +02:00
Susko3 f3d13fe6dc Add C# type-friendly properties/getters to some structs 2024-04-06 14:12:44 +02:00
Susko3 8a2f47fd97 Add `PtrToStringUTF8()` for `byte *` 2024-04-06 14:08:42 +02:00
Susko3 8624db0eae Add `void *` overload for `SDL_free()`
Useful as any pointer type can implicitly covert to void *.
2024-04-06 14:07:38 +02:00
Susko3 77ab7fed42 Manually implement macro functions
All of these get "Function like macro definition records are not supported: [...] Generated bindings may be incomplete."
warnings when running ClangSharp.
2024-04-06 14:05:52 +02:00
Susko3 182482217d Move `SDL_Keycode` typdef to global python script to avoid duplicate definition 2024-04-06 13:47:08 +02:00
Susko3 7d9502ee82 Remap `SDL_KeyCode` enum to `SDL_Keycode` typedef
This doesn't compile because of duplicate `SDL_Keycode` definition
2024-04-06 13:45:49 +02:00
Susko3 7b8ea9767f Manually implement endianness-specific audio formats 2024-04-06 13:42:10 +02:00
Susko3 c9c9782e48 Define `SDL_FUNCTION_POINTER_IS_VOID_POINTER` 2024-04-06 13:38:13 +02:00
Susko3 d2bc4e7605 Manually define broken constants 2024-04-06 13:33:00 +02:00
Susko3 a4ecfd1c75 Fix invalid `int` -> `SDL_bool` conversion by manually changing SDL headers 2024-04-06 13:33:00 +02:00
Susko3 556c6cd1a3 Add C# enum "typedefs" for C typedefs
This doesn't compile as ClangSharp fails to emit `unchecked`
in `SDL_pen.g.cs` and `SDL_touch.g.cs`.
And `(SDL_bool)` casts in `SDL_rect.g.cs`.
2024-04-06 13:32:55 +02:00
Susko3 0b0906bfea Add `[Flags]` attribute to mask/flags enums 2024-04-06 12:58:35 +02:00
Susko3 0196aeb249 Add [UnsupportedOSPlatform("windows")] to `SDL_CreateThread()` functions
See commit: 72353a8ab9
2024-04-06 12:54:12 +02:00
Susko3 e5f25b9957 Don't log potential typedef remappings
Produces a lot of noise about unused remappings (as we're processing a header at a time).
All remappings (except `SDL_JoystickGUID`) have been added.

`SDL_JoystickGUID` is a remapping of a struct, so it's harded to do programatically.
2024-04-06 12:37:14 +02:00
Susko3 03613e6a4e Remap C `void *` to C# `IntPtr` 2024-04-06 12:34:11 +02:00
Susko3 61d2486e4f Map C `char` to C# `byte` instead of `sbyte`
This matches .NET's UTF-8 `ReadOnlySpan<byte>` (see `SDL_hints.g.cs`).
2024-04-06 12:31:32 +02:00
Susko3 b904699261 Remap `wchar_t *` to `IntPtr`
These map to 16-bit `ushort` on windows, but are 32-bit on Unix.
2024-04-06 12:28:16 +02:00
Susko3 8d1a377e72 Add recommended remapping for `SDL_hidapi.h` 2024-04-06 12:22:50 +02:00
Susko3 2788460013 Exclude `SDL_main()` from DllImport as it isn't exported by SDL3.dll 2024-04-06 01:59:38 +02:00
Susko3 5cf5bb69d7 Add custom definition for win32 MSG struct
The win32 types are kinda cursed, but it makes it easy to copy&paste and check.
2024-04-06 01:42:45 +02:00
Susko3 a123a3c904 Fix missing <endian.h> when cross-compiling on windows
This works because SDL checks <endian.h> iff SDL_BYTEORDER isn't defined.
6ad390fc50/include/SDL3/SDL_endian.h (L58-L60)
2024-04-06 01:37:05 +02:00
Susko3 b01fa42bff Fix duplicate `XEvent` struct definitions 2024-04-06 01:34:10 +02:00
Susko3 a8553fab6e 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`
2024-04-06 01:31:16 +02:00
Susko3 48c9b12f2d Add simple check for generated functions
There are warnings for platform-specific functions.
2024-04-06 01:17:00 +02:00
Susko3 4f065d18f7 Fix errors in `SDL_stdinc.g.cs` with define magic 2024-04-06 01:00:29 +02:00
Susko3 3cff0fd872 Fix errors in `SDL_pixels.g.cs` by specifying enum types 2024-04-06 01:00:29 +02:00
Susko3 5d61c2483e Undefine _WIN32 to generate only platform-agnostic APIs
Probably needs similar undefines on Linux and macOS.

Notice that the signatures of `SDL_CreateThread` and `SDL_CreateThreadWithStackSize`
have changed.
2024-04-06 01:00:29 +02:00