Skip to content

Commit 20b2aa8

Browse files
jrose-appleDavide Italiano
authored and
Davide Italiano
committed
[CMake] Stop compiling API notes files to a binary format (#19205)
Clang's been able to read the textual format for a long time, and indeed that's what's used in the SDK. This isn't even really a performance win because the information is cached in PCMs. rdar://problem/34293901
1 parent df1b3c9 commit 20b2aa8

File tree

2 files changed

+8
-74
lines changed

2 files changed

+8
-74
lines changed

apinotes/README.md

+4-67
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,12 @@ original Objective-C headers. This semantic information can then be
66
used by the Swift compiler when importing the corresponding Objective-C
77
module to provide a better mapping of Objective-C APIs into Swift.
88

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
9+
API notes are organized into a set of `.apinotes` files. Each `.apinotes` file
10+
contains annotations for a single Objective-C module, written in YAML (FIXME:
11+
to be) described in the Clang repository. These YAML sources are lazily loaded
12+
by the Swift compiler when it imports the corresponding framework, also
1413
described below.
1514

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-
macOS | `$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-
### macOS
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 x86_64-apple-ios7.0 -o $SWIFT_EXEC/lib/swift/iphonesimulator/$MODULE.apinotesc $MODULE.apinotes
70-
```
71-
7215
To add API notes for a system module `$MODULE` that does not have them yet,
7316
create a new source file `$MODULE.apinotes` and update CMakeLists.txt.
7417
Updated API notes will be found by the build system during the next build.
75-
76-
Note that Swift provides decompilation of binary API notes files via
77-
the `-apinotes -binary-to-yaml` option, which allows one to inspect
78-
the information the compiler is using internally. The order of the
79-
entities in the original YAML input is not preserved, so all entities
80-
in the resulting YAML output are sorted alphabetically.

cmake/modules/SwiftSource.cmake

+4-7
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,14 @@ function(_compile_swift_files
351351
set(apinote_files)
352352

353353
foreach(apinote_module ${SWIFTFILE_API_NOTES})
354-
set(apinote_file "${module_dir}/${apinote_module}.apinotesc")
354+
set(apinote_file "${module_dir}/${apinote_module}.apinotes")
355355
set(apinote_input_file
356356
"${SWIFT_API_NOTES_PATH}/${apinote_module}.apinotes")
357357

358358
list(APPEND command_create_apinotes
359359
COMMAND
360-
"${swift_compiler_tool}" "-apinotes" "-yaml-to-binary"
361-
"-o" "${apinote_file}"
362-
"-target" "${SWIFT_SDK_${SWIFTFILE_SDK}_ARCH_${SWIFTFILE_ARCHITECTURE}_TRIPLE}"
363-
"${apinote_input_file}")
360+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
361+
"${apinote_input_file}" "${apinote_file}")
364362
list(APPEND depends_create_apinotes "${apinote_input_file}")
365363

366364
list(APPEND apinote_files "${apinote_file}")
@@ -444,10 +442,9 @@ function(_compile_swift_files
444442
COMMAND ""
445443
OUTPUT ${apinotes_outputs}
446444
DEPENDS
447-
${swift_compiler_tool_dep}
448445
${depends_create_apinotes}
449446
${obj_dirs_dependency_target}
450-
COMMENT "Generating API notes ${first_output}")
447+
COMMENT "Copying API notes for ${first_output}")
451448
endif()
452449

453450
# Then we can compile both the object files and the swiftmodule files

0 commit comments

Comments
 (0)