Skip to content

Commit 63b2a88

Browse files
authored
[ffigen] Fix usrTypeMappings field of Config factory constructor (#2014)
1 parent a74e5a2 commit 63b2a88

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

pkgs/ffigen/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 18.0.0-dev
2+
3+
- Add variable substitutions that can be used in the `headers.entry-points` to
4+
locate Apple APIs: `$XCODE`, `$IOS_SDK`, and `$MACOS_SDK`.
5+
- __Breaking change__: Change the `usrTypeMappings` field of `Config`'s factory
6+
constructor from a `List<ImportedType>` to a `Map<String, ImportedType>`.
7+
18
## 17.0.0
29

310
- Use package:objective_c 6.0.0

pkgs/ffigen/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -1139,3 +1139,25 @@ The property filtering rules live in the same `objc-interfaces.member-filter`
11391139
option as the methods. There is no distinction between methods and properties in
11401140
the filters. The protocol filtering rules live in
11411141
`objc-protocols.member-filter`.
1142+
1143+
### How do I generate bindings for Apple APIs?
1144+
1145+
It can be tricky to locate header files containing Apple's ObjC frameworks, and
1146+
the paths can vary between computers depending on which version of Xcode you are
1147+
using and where it is installed. So ffigen provides the following variable
1148+
substitutions that can be used in the `headers.entry-points` list:
1149+
1150+
- `$XCODE`: Replaced with the result of `xcode-select -p`, which is the
1151+
directory where Xcode's APIs are installed.
1152+
- `$IOS_SDK`: Replaced with `xcrun --show-sdk-path --sdk iphoneos`, which is the
1153+
directory within `$XCODE` where the iOS SDK is installed.
1154+
- `$MACOS_SDK`: Replaced with `xcrun --show-sdk-path --sdk macosx`, which is the
1155+
directory within `$XCODE` where the macOS SDK is installed.
1156+
1157+
For example:
1158+
1159+
```Yaml
1160+
headers:
1161+
entry-points:
1162+
- '$MACOS_SDK/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h'
1163+
```

pkgs/ffigen/lib/src/config_provider/config.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ abstract interface class Config {
224224
bool sort = false,
225225
bool useSupportedTypedefs = true,
226226
List<LibraryImport> libraryImports = const <LibraryImport>[],
227-
List<ImportedType> usrTypeMappings = const <ImportedType>[],
227+
Map<String, ImportedType> usrTypeMappings = const <String, ImportedType>{},
228228
List<ImportedType> typedefTypeMappings = const <ImportedType>[],
229229
List<ImportedType> structTypeMappings = const <ImportedType>[],
230230
List<ImportedType> unionTypeMappings = const <ImportedType>[],
@@ -285,9 +285,7 @@ abstract interface class Config {
285285
libraryImports: Map<String, LibraryImport>.fromEntries(
286286
libraryImports.map((import) =>
287287
MapEntry<String, LibraryImport>(import.name, import))),
288-
usrTypeMappings: Map<String, ImportedType>.fromEntries(
289-
usrTypeMappings.map((import) =>
290-
MapEntry<String, ImportedType>(import.nativeType, import))),
288+
usrTypeMappings: usrTypeMappings,
291289
typedefTypeMappings: Map<String, ImportedType>.fromEntries(
292290
typedefTypeMappings.map((import) =>
293291
MapEntry<String, ImportedType>(import.nativeType, import))),

pkgs/ffigen/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# BSD-style license that can be found in the LICENSE file.
44

55
name: ffigen
6-
version: 17.0.0
6+
version: 18.0.0-dev
77
description: >
88
Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift
99
files.

0 commit comments

Comments
 (0)