I published the bindings generator project. It is not documented but here’s a short guide. PRs for library bindings or improving the generator are welcome.
Objective: Generate bindings for the FSEvents API
The API of interest, according to Apple’s documentation, is part of the Core Services framework. It is supported on all platforms, including macOS, so generating bindings for it should be easy.
- Find the “bridgesupport” file
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Resources/BridgeSupport/FSEvents.bridgesupport
- Generate globals
mkdir -p data/FSEvents
cp /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Resources/BridgeSupport/FSEvents.bridgesupport data
dune exec bs-to-ml -- -fw FSEvents < data/FSEvents.bridgesupport > data/FSEvents/FSEvents_globals.ml
This covers the C API that cannot be introspected via the Objective-C runtime. Let’s check if the framework contains Objective-C classes.
dune exec inspect-rt -- -libs | grep FSEvents
Doesn’t look like it does. We are done. Otherwise, we would proceed with the next tool:
- Generate bindings to Objective-C classes
cd data/FSEvents && dune exec generate-ml -- -fw FSEvents -classes <FSEvents framework binary>
Libraries that are iOS-only do not provide bridgesupport files. For those, you have to jump through many hoops. Eg, you can attempt to generate a bridgesupport file manually:
gen_bridge_metadata --arm64e -C -isysroot=$(SDK_IOS) -f $(SDK_IOS)/System/Library/Frameworks/<Whatever>.framework -o data/<Whatever>.bridgesupport
That’s about it. Have fun.