-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create language binding generation tools for SDL3 #6
Comments
Hello, I would like to present for this bounty as part-time. Introduction Back in 2020/2021 I was trying to create C# bindings for a specific C library called My findings have been put into the following projects as tools with a lot of learnings and documentation:
I have tried using the tooling on various C libraries with early limited testing success including: You can find an example of the generated bindings from https://github.com/bottlenoselabs/SDL-cs/blob/main/src/cs/production/SDL/Generated/SDL.gen.cs. This file gets updated by using Github Actions pipelines via Dependabot to open a new PR when upstream has been updated. Problems As others have described in the linked SDL GitHub issue, using The best outcome is that changes are made upstream to SDL to accommodate making bindgen friendly. Worse case is that some workarounds would be done for the purposes of generating C# bindings which would be unique to to FNA. The good news is that Questions
Proposed Deadline I would be working on this part-time. Two Weeks of March 18th to March 31st
Week of April 1st to April 7th
|
This bit from the README should be able to answer both:
The rest sounds okay, so will mark as In Progress. |
I'm interested in taking on this. I've recently been experimenting with generating SDL3 bindings from header files. I've used a combination of
I have some questions about the C# side of things:
I'm also happy to help with creating demo SDL3 applications to check that the generated bindings are simple to use and correct. |
Note that @lithiumtoast may have already started, so definitely coordinate with them if you both want to work on this at the same time. To answer the questions (all of which are good!):
|
I'm not sure I understand what you mean by this. Even if the code is generated, VS2010 will still have to compile it. Unless you mean that there'll be two versions of each function, one for .NET 4.0 compatibility, and one using modern syntax and features. And preprocessor directives could be used to compile only the function relevant for the tooling used. |
Hey @Susko3, if you want to share this bounty that's OK with me. It would be great to get some help.
|
Posting here with an update. I re-wrote and renamed CAstFfi to https://github.com/bottlenoselabs/c2ffi. I did this while setting up end-to-end tests for GitHub Actions making sure everything works correctly (so far) for all desktop platforms (Windows, macOS, Ubuntu) when using My plan is to update |
Hello, I have things ready for some feedback. Apologies about being the timeline being a bit later then what I mentioned earlier. You can find the generated C# code here from the latest SDL At this time it doesn't include I'll get us started:
|
Aside from the "nuget or not" question, it would be ideal from a security/supply-chain perspective if the NuGet is one that's built and distributed by the SDL organization and not an unknown third party.
If you're not aware, you can use the |
Will definitely do a deep dive tomorrow, but to answer what I can ASAP...
Yep, we'll be using the main branch until SDL4 starts.
I'd say remove them if possible; we were able to do all our bindings without dependencies up until now so it should be possible to keep that going.
Sam/Ryan might consider something like SDL_math.h, stdint, etc, but worst case we can ignore this header and generate the allocator functions ourselves.
This is fine with me - as long as the code using the functions isn't any different it's okay for the generated stuff to do more optimal things internally (we have a handful of these in SDL2.cs). If it's the case that it would break ABI to have two different versions, the ABI should prefer the old way over the new way (someone making their own bindings with this generator could optimize for themselves if they wanted to though!).
Will take a look soon! |
Yup, I am doing that in a supporting assembly attributes file to the main generated C# file Speaking of which. The usage of
This could be a good example of using another C# file with |
Update: April 29th 2024 https://github.com/lithiumtoast/SDL-cs
Remaining work:
|
Update: May 8th 2024 Apologies for the delay as I caught COVID and was not functioning most of the time. https://github.com/lithiumtoast/SDL-cs
Remaining work:
|
A bit late to the party but here's my attempt repo, which uses Python with tree sitter to parse the sources and generate the bindings. Currently it needs libsdl-org/SDL#9907 to work properly or else in/out parameters cannot be distinguished properly. I tried to stay as close as I could to the design of SDL2# and use old C# features as well, but I don't have an old compiler to find the minimum C# version needed. Feel free to ask about any questions/concerns related to the code. Update: Here's some sample code that shows how to use the generated API: gist |
SDL_GPU's public interface is starting to slow down, so I'm going to try and put some time into this before we fully freeze - @lithiumtoast, is it possible for GitHub Actions to do a daily run that pulls the latest |
Yeah I can see what I can do this weekend. |
This ended up getting stomped on a bit by a new generator by @thatcosmonaut and @cryy22 - it uses an ffi.json but it otherwise is an all-new generator: https://github.com/flibitijibibo/SDL3-CS/tree/main/GenerateBindings It includes a lot of additional annotations to deal with ref/out, and falls back with a warning like SDL3_FNAPlatform is in progress over here: FNA-XNA/FNA#494 There's still work to be done but we're getting close! |
Introductory Information:
SDL3 is the upcoming major release of SDL that breaks the ABI for the first time in over 10 years, in favor of dramatically improving and redesigning core APIs. It is currently being used by Source 2 internally, but will likely be adopted very quickly by the countless projects currently using SDL2, including FNA.
SDL2# is the C# binding for SDL2, originally built for FNA shortly before SDL 2.0 was officially tagged. The binding has been handwritten and hand-maintained for the entirety of its lifespan. This worked well for most of that time, but in recent years it's gotten increasingly difficult to keep up with upstream SDL changes.
The Project:
Since many different languages want to have SDL bindings, there is now a proposal for SDL3 to maintain machine-readable API files that can easily generate bindings for numerous languages:
libsdl-org/SDL#6337
This bounty specifically targets C#; the goal is to make machine readable definitions and then make a program that generates SDL3.cs, which should look and feel exactly like SDL2#.
The machine-readable files will be hosted in the SDL repo; ideally we'll be able to use the SDL headers directly, but if we have to generate something similar to dynapi that should be fine too.
The C# generator script and the generated bindings will be hosted in the FNA repository directly, with SDL itself being the new submodule rather than a new SDL3-CS repo.
Prerequisites:
Experience with scripting and working with both C headers and machine-readable data formats will help a lot; the language isn't locked down but existing scripts for SDL use Python and Perl. Knowing C# will probably help but is not as important as the other prerequisites.
Example Games:
XNA/FNA games will be making use of this by generating SDL3 bindings that look and act similar to SDL2#, and will be the basis for the SDL3_FNAPlatform, which will live side-by-side with SDL2_FNAPlatform for maximum compatibility with the existing catalog of games.
How Much Can flibit Help?
I'm not great with automated bindings generation, but having worked on SDL2# for a decade I should be able to explain any possible quirks that C# (for example) might have that will affect the API definitions. There are others working on other languages that will probably want to test and give feedback as well.
Budget/Timeline
If done as a part-time gig, I would expect this to take about a month, with the majority of the work being at the first and last steps (the first being getting something generated at all, and the last being upstreaming it for SDL 3.0). There is $4000 USD allocated for this project.
The text was updated successfully, but these errors were encountered: