Skip to content

Commit 0149129

Browse files
authored
[CMake] Stop compiling API notes files to a binary format (swiftlang#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 004d0b9 commit 0149129

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
@@ -354,16 +354,14 @@ function(_compile_swift_files
354354
set(apinote_files)
355355

356356
foreach(apinote_module ${SWIFTFILE_API_NOTES})
357-
set(apinote_file "${module_dir}/${apinote_module}.apinotesc")
357+
set(apinote_file "${module_dir}/${apinote_module}.apinotes")
358358
set(apinote_input_file
359359
"${SWIFT_API_NOTES_PATH}/${apinote_module}.apinotes")
360360

361361
list(APPEND command_create_apinotes
362362
COMMAND
363-
"${swift_compiler_tool}" "-apinotes" "-yaml-to-binary"
364-
"-o" "${apinote_file}"
365-
"-target" "${SWIFT_SDK_${SWIFTFILE_SDK}_ARCH_${SWIFTFILE_ARCHITECTURE}_TRIPLE}"
366-
"${apinote_input_file}")
363+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
364+
"${apinote_input_file}" "${apinote_file}")
367365
list(APPEND depends_create_apinotes "${apinote_input_file}")
368366

369367
list(APPEND apinote_files "${apinote_file}")
@@ -447,10 +445,9 @@ function(_compile_swift_files
447445
COMMAND ""
448446
OUTPUT ${apinotes_outputs}
449447
DEPENDS
450-
${swift_compiler_tool_dep}
451448
${depends_create_apinotes}
452449
${obj_dirs_dependency_target}
453-
COMMENT "Generating API notes ${first_output}")
450+
COMMENT "Copying API notes for ${first_output}")
454451
endif()
455452

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

0 commit comments

Comments
 (0)