dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
150 stars 42 forks source link

Can't access AVFoundation `NSValue` extensions #1478

Open stuartmorgan opened 1 month ago

stuartmorgan commented 1 month ago

AVFoundation has a header AVTime.h, which contains the following extension:

@interface NSValue (NSValueAVFoundationExtensions)

+ (NSValue *)valueWithCMTime:(CMTime)time API_AVAILABLE(macos(10.7), ios(4.0), tvos(9.0), watchos(1.0));
@property (readonly) CMTime CMTimeValue API_AVAILABLE(macos(10.7), ios(4.0), tvos(9.0), watchos(1.0));

+ (NSValue *)valueWithCMTimeRange:(CMTimeRange)timeRange API_AVAILABLE(macos(10.7), ios(4.0), tvos(9.0), watchos(1.0));
@property (readonly) CMTimeRange CMTimeRangeValue API_AVAILABLE(macos(10.7), ios(4.0), tvos(9.0), watchos(1.0));

+ (NSValue *)valueWithCMTimeMapping:(CMTimeMapping)timeMapping API_AVAILABLE(macos(10.7), ios(4.0), tvos(9.0), watchos(1.0));
@property (readonly) CMTimeMapping CMTimeMappingValue API_AVAILABLE(macos(10.7), ios(4.0), tvos(9.0), watchos(1.0));

@end

I can't get ffigen to give me access to those, which is problematic since I am trying to convert code that uses CMTimeValue. I'm assuming the problem is that NSValue is part of objective_c, and so ffigen is skipping it?

I think the desired behavior here would be that extensions on objective_c-provided types would be created as Dart extensions in my ffi_bindings.dart (although I'm not sure if there's an easy way for the tool to determine which extensions are new, vs. part of objective_c).

liamappelbe commented 1 month ago

As part of the category overhaul, experiment with code genning them as extension methods instead of inserting them into the class.

If that doesn't work (eg blocked by semantic differences between ObjC categories and Dart extension methods), we'll just have to add NSValueAVFoundationExtensions, and any other categories users request, to package:objective_c.