Skip to content

Conversation

@szotp
Copy link

@szotp szotp commented Apr 30, 2025

Added basic support for Swift Package Manager. SPM can handle C libraries, and Swift supports binding to them, which means someone else can implement a wrapper on top of it.

I had to make some adjustments in headers:

  • Unnecessary circular dependency of display.h on gb.h
  • apu.h using GB_ENUM without including save_state.h
  • save_state.h using GB_gameboy_t without including model.h

@szotp
Copy link
Author

szotp commented May 1, 2025

I tried to run https://pub.dev/packages/ffigen and it found further errors with missing includes.

Pushed fixes for those. Maybe it would make sense to add

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

into defs.h and only include one file in other places?

@LIJI32
Copy link
Owner

LIJI32 commented May 25, 2025

I have several issues and comments:

  1. Header cleanup is good, can be merged pretty much as is.
  2. I'm rather worried about adding SPM support to the mainstream repo. I don't use Swift and I don't know how SPM works, so I couldn't possibly provide official support to it. Could this be done in a different repo with SameBoy being a subrepo?
  3. The "ideal" way of using SameBoy as a library is using make lib (potentially with CONF=release and potentially extra CFLAGS/LDFLAGS/SYSROOT for cross-compilation if needed) and using the generated a/o/dylib file together with the post-processed headers. This makes sure SameBoy is built with LTO and the optimal optimization flags, but I worry the most about having GB_INTERNAL defined globally like you do here – if I understand SPM correctly, this would expose internal APIs to the Swift side, which is quite problematic.

@LIJI32 LIJI32 force-pushed the master branch 2 times, most recently from 4873d7c to 858f003 Compare December 29, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants