|
| 1 | +# API Notes README |
| 2 | + |
| 3 | +API notes provide a mechanism by which Objective-C APIs can be |
| 4 | +annotated with additional semantic information not present within the |
| 5 | +original Objective-C headers. This semantic information can then be |
| 6 | +used by the Swift compiler when importing the corresponding Objective-C |
| 7 | +module to provide a better mapping of Objective-C APIs into Swift. |
| 8 | + |
| 9 | +API notes are organized into a set of `.apinotes` files. Each |
| 10 | +`.apinotes` file contains annotations for a single Objective-C module, |
| 11 | +written in YAML (FIXME: to be) described below. These YAML sources |
| 12 | +must be manually compiled into a binary representation (`.apinotesc`) |
| 13 | +that the Swift compiler will lazily load when it builds code, also |
| 14 | +described below. |
| 15 | + |
| 16 | +# API Notes YAML Format |
| 17 | + |
| 18 | +TBD... |
| 19 | + |
| 20 | +# Compiling API notes |
| 21 | + |
| 22 | +The Swift compiler lazily loads API notes from compiled API notes |
| 23 | +files (`.apinotesc` files) and uses these annotations to affect the |
| 24 | +Swift signatures of imported Objective-C APIs. Compiled API notes |
| 25 | +files reside in the Swift module directory, i.e., the same directory |
| 26 | +where the `.swiftmodule` file would reside for the Swift overlay of |
| 27 | +that module. For system modules, the path depends on the platform |
| 28 | +and architecture |
| 29 | + |
| 30 | +Platform | Path |
| 31 | +:------------- | :------------- |
| 32 | + OSX | `$SWIFT_EXEC/lib/swift/macosx/` |
| 33 | + iOS (32-bit) | `$SWIFT_EXEC/lib/swift/iphoneos/32` |
| 34 | + iOS (64-bit) | `$SWIFT_EXEC/lib/swift/iphoneos` |
| 35 | + iOS Simulator (32-bit) | `$SWIFT_EXEC/lib/swift/iphonesimulator/32` |
| 36 | + iOS Simulator (64-bit) | `$SWIFT_EXEC/lib/swift/iphonesimulator` |
| 37 | + |
| 38 | +where `$SWIFT_EXEC/bin/swift` is the path to the Swift compiler |
| 39 | +executable. |
| 40 | + |
| 41 | +When updating API notes for a system module, recompile the API notes |
| 42 | +and place the result in the appropriate directories listed above. The |
| 43 | +Swift compiler itself need not be recompiled except in rare cases |
| 44 | +where the changes affect how the SDK overlays are built. To recompile |
| 45 | +API notes for a given module `$MODULE` and place them into their |
| 46 | + |
| 47 | +### OSX |
| 48 | +``` |
| 49 | +xcrun swift -apinotes -yaml-to-binary -target x86_64-apple-macosx10.10 -o $SWIFT_EXEC/lib/swift/macosx/$MODULE.apinotesc $MODULE.apinotes |
| 50 | +``` |
| 51 | + |
| 52 | +### iOS (32-bit) |
| 53 | +``` |
| 54 | +xcrun swift -apinotes -yaml-to-binary -target armv7-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphoneos/32/$MODULE.apinotesc $MODULE.apinotes |
| 55 | +``` |
| 56 | + |
| 57 | +### iOS (64-bit) |
| 58 | +``` |
| 59 | +xcrun swift -apinotes -yaml-to-binary -target arm64-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphoneos/$MODULE.apinotesc $MODULE.apinotes |
| 60 | +``` |
| 61 | + |
| 62 | +### iOS Simulator (32-bit) |
| 63 | +``` |
| 64 | +xcrun swift -apinotes -yaml-to-binary -target i386-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphonesimulator/32/$MODULE.apinotesc $MODULE.apinotes |
| 65 | +``` |
| 66 | + |
| 67 | +### iOS Simulator (64-bit) |
| 68 | +``` |
| 69 | +xcrun swift -apinotes -yaml-to-binary -target x64_64-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphonesimulator/$MODULE.apinotesc $MODULE.apinotes |
| 70 | +``` |
| 71 | + |
| 72 | +To add API notes for a system module `$MODULE` that does not have them yet, |
| 73 | +create a new source file `$MODULE.apinotes`. Newly-added API notes will require |
| 74 | +re-running CMake. Updated API notes will be found by the build system during |
| 75 | +the next build. |
| 76 | + |
| 77 | +Note that Swift provides decompilation of binary API notes files via |
| 78 | +the `-apinotes -binary-to-yaml` option, which allows one to inspect |
| 79 | +the information the compiler is using internally. The order of the |
| 80 | +entities in the original YAML input is not preserved, so all entities |
| 81 | +in the resulting YAML output are sorted alphabetically. |
0 commit comments