Skip to content

Commit aea1ef8

Browse files
authored
Move API notes out of the arch-specific subdirectories in lib/swift/ (swiftlang#21690)
They're all the same anyway, and no longer even need to be compiled, just copied in as text. And drastically simplify how we "generate" them. Instead of attaching their build jobs to the appropriate overlays, if present, "just" have one job to copy them all and attach it to the Darwin overlay. That's what we do for the overlay shim headers, and it's good enough. (Eventually we want to get out of the business of shipping them altogether.) This does have the same flaw as the shim headers: if you /just/ change API notes, the corresponding overlay does not get rebuilt. You have to touch that too. But in practice that'll happen most of the time anyway. Part of rdar://problem/43545560
1 parent 9dd5d12 commit aea1ef8

File tree

7 files changed

+52
-108
lines changed

7 files changed

+52
-108
lines changed

CMakeLists.txt

+9-10
Original file line numberDiff line numberDiff line change
@@ -991,23 +991,14 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
991991
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
992992
endif()
993993

994-
#
995-
# Set up global CMake variables for API notes.
996-
#
997-
set(SWIFT_API_NOTES_PATH "${SWIFT_SOURCE_DIR}/apinotes")
998-
include("${SWIFT_API_NOTES_PATH}/CMakeLists.txt")
999-
if(NOT DEFINED SWIFT_API_NOTES_INPUTS)
1000-
message(FATAL_ERROR "API notes are not available in ${SWIFT_API_NOTES_PATH}")
1001-
endif()
1002-
1003994
# Add all of the subdirectories, where we actually do work.
1004995

1005996
###############
1006997
# PLEASE READ #
1007998
###############
1008999
#
10091000
# We have to include stdlib/ before tools/.
1010-
# Do not move add_subdirectory(stdlib) after add_subdirectory(tools)!
1001+
# Do not move add_subdirectory(stdlib) after add_subdirectory(tools)!
10111002
#
10121003
# We must include stdlib/ before tools/ because stdlib/CMakeLists.txt
10131004
# declares the swift-stdlib-* set of targets. These targets will then
@@ -1023,6 +1014,14 @@ endif()
10231014
# https://bugs.swift.org/browse/SR-5975
10241015
add_subdirectory(stdlib)
10251016

1017+
if(SWIFT_BUILD_SDK_OVERLAY)
1018+
list_intersect("${SWIFT_APPLE_PLATFORMS}" "${SWIFT_SDKS}"
1019+
building_darwin_sdks)
1020+
if(building_darwin_sdks)
1021+
add_subdirectory(apinotes)
1022+
endif()
1023+
endif()
1024+
10261025
add_subdirectory(include)
10271026

10281027
if(SWIFT_INCLUDE_TOOLS)

apinotes/CMakeLists.txt

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
set(SWIFT_API_NOTES_INPUTS
2-
Accelerate
3-
Dispatch
4-
ScriptingBridge
5-
os
1+
set(sources
2+
Accelerate.apinotes
3+
Dispatch.apinotes
4+
ScriptingBridge.apinotes
5+
os.apinotes
66
)
77

8-
if(NOT DEFINED SWIFT_API_NOTES_PATH)
9-
message(FATAL_ERROR "Define SWIFT_API_NOTES_PATH before including this file")
10-
endif()
8+
set(output_dir "${SWIFTLIB_DIR}/apinotes")
119

12-
foreach(module ${SWIFT_API_NOTES_INPUTS})
13-
if(NOT EXISTS "${SWIFT_API_NOTES_PATH}/${module}.apinotes")
14-
message(SEND_ERROR "Missing apinotes for ${module}")
15-
endif()
10+
set(inputs)
11+
set(outputs)
12+
foreach(input ${sources})
13+
list(APPEND inputs "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
14+
list(APPEND outputs "${output_dir}/${input}")
1615
endforeach()
1716

18-
file(GLOB SWIFT_API_NOTES_INPUT_FILES "${SWIFT_API_NOTES_PATH}/*.apinotes")
19-
foreach(file ${SWIFT_API_NOTES_INPUT_FILES})
20-
get_filename_component(name "${file}" NAME_WE)
21-
if(NOT "${name}" IN_LIST SWIFT_API_NOTES_INPUTS)
22-
message(SEND_ERROR "Found apinotes for ${name}; please add to CMakeLists.txt")
23-
endif()
24-
endforeach()
17+
add_custom_command(
18+
OUTPUT "${output_dir}"
19+
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${output_dir}")
20+
add_custom_command(
21+
OUTPUT ${outputs}
22+
DEPENDS ${inputs} "${output_dir}"
23+
COMMAND
24+
"${CMAKE_COMMAND}" "-E" "copy_if_different" ${inputs} "${output_dir}/")
25+
26+
add_custom_target("copy_apinotes"
27+
DEPENDS "${outputs}" "${output_dir}"
28+
COMMENT "Copying API notes to ${output_dir}"
29+
SOURCES "${sources}")
30+
31+
swift_install_in_component(sdk-overlay
32+
FILES ${sources}
33+
DESTINATION "lib/swift/apinotes")

cmake/modules/AddSwift.cmake

-28
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ endfunction()
606606
# [C_COMPILE_FLAGS flag1...]
607607
# [SWIFT_COMPILE_FLAGS flag1...]
608608
# [LINK_FLAGS flag1...]
609-
# [API_NOTES_NON_OVERLAY]
610609
# [FILE_DEPENDS target1 ...]
611610
# [DONT_EMBED_BITCODE]
612611
# [IS_STDLIB]
@@ -661,9 +660,6 @@ endfunction()
661660
# LINK_FLAGS
662661
# Extra linker flags.
663662
#
664-
# API_NOTES_NON_OVERLAY
665-
# Generate API notes for non-overlayed modules with this target.
666-
#
667663
# FILE_DEPENDS
668664
# Additional files this library depends on.
669665
#
@@ -686,7 +682,6 @@ endfunction()
686682
# Sources to add into this library
687683
function(_add_swift_library_single target name)
688684
set(SWIFTLIB_SINGLE_options
689-
API_NOTES_NON_OVERLAY
690685
DONT_EMBED_BITCODE
691686
FORCE_BUILD_OPTIMIZED
692687
IS_SDK_OVERLAY
@@ -805,22 +800,6 @@ function(_add_swift_library_single target name)
805800
SWIFTLIB_SINGLE_SOURCES
806801
"${SWIFTLIB_SINGLE_ARCHITECTURE}")
807802

808-
# Figure out whether and which API notes to create.
809-
set(SWIFTLIB_SINGLE_API_NOTES)
810-
if(SWIFTLIB_SINGLE_API_NOTES_NON_OVERLAY)
811-
# Adopt all of the non-overlay API notes.
812-
foreach(framework_name ${SWIFT_API_NOTES_INPUTS})
813-
if (${framework_name} STREQUAL "WatchKit" AND
814-
${SWIFTLIB_SINGLE_SDK} STREQUAL "OSX")
815-
# HACK: don't build WatchKit API notes for OS X.
816-
else()
817-
# Always build the "non-overlay" apinotes to keep them in sync
818-
# rdar://40496966
819-
list(APPEND SWIFTLIB_SINGLE_API_NOTES "${framework_name}")
820-
endif()
821-
endforeach()
822-
endif()
823-
824803
# Remove the "swift" prefix from the name to determine the module name.
825804
if(SWIFTLIB_IS_STDLIB_CORE)
826805
set(module_name "Swift")
@@ -870,7 +849,6 @@ function(_add_swift_library_single target name)
870849
${SWIFTLIB_SINGLE_INTERFACE_LINK_LIBRARIES}
871850
SDK ${SWIFTLIB_SINGLE_SDK}
872851
ARCHITECTURE ${SWIFTLIB_SINGLE_ARCHITECTURE}
873-
API_NOTES ${SWIFTLIB_SINGLE_API_NOTES}
874852
MODULE_NAME ${module_name}
875853
COMPILE_FLAGS ${SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS}
876854
${SWIFTLIB_SINGLE_IS_STDLIB_keyword}
@@ -1471,7 +1449,6 @@ endfunction()
14711449
# [SWIFT_COMPILE_FLAGS flag1...]
14721450
# [LINK_FLAGS flag1...]
14731451
# [DONT_EMBED_BITCODE]
1474-
# [API_NOTES_NON_OVERLAY]
14751452
# [INSTALL]
14761453
# [IS_STDLIB]
14771454
# [IS_STDLIB_CORE]
@@ -1550,9 +1527,6 @@ endfunction()
15501527
# LINK_FLAGS
15511528
# Extra linker flags.
15521529
#
1553-
# API_NOTES_NON_OVERLAY
1554-
# Generate API notes for non-overlayed modules with this target.
1555-
#
15561530
# DONT_EMBED_BITCODE
15571531
# Don't embed LLVM bitcode in this target, even if it is enabled globally.
15581532
#
@@ -1589,7 +1563,6 @@ endfunction()
15891563
# Sources to add into this library.
15901564
function(add_swift_target_library name)
15911565
set(SWIFTLIB_options
1592-
API_NOTES_NON_OVERLAY
15931566
DONT_EMBED_BITCODE
15941567
FORCE_BUILD_OPTIMIZED
15951568
HAS_SWIFT_CONTENT
@@ -1904,7 +1877,6 @@ function(add_swift_target_library name)
19041877
INCORPORATE_OBJECT_LIBRARIES ${SWIFTLIB_INCORPORATE_OBJECT_LIBRARIES}
19051878
INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY ${SWIFTLIB_INCORPORATE_OBJECT_LIBRARIES_SHARED_ONLY}
19061879
${SWIFTLIB_DONT_EMBED_BITCODE_keyword}
1907-
${SWIFTLIB_API_NOTES_NON_OVERLAY_keyword}
19081880
${SWIFTLIB_IS_STDLIB_keyword}
19091881
${SWIFTLIB_IS_STDLIB_CORE_keyword}
19101882
${SWIFTLIB_IS_SDK_OVERLAY_keyword}

cmake/modules/SwiftSource.cmake

+4-46
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function(handle_swift_sources
1717
cmake_parse_arguments(SWIFTSOURCES
1818
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
1919
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT"
20-
"DEPENDS;API_NOTES;COMPILE_FLAGS;MODULE_NAME"
20+
"DEPENDS;COMPILE_FLAGS;MODULE_NAME"
2121
${ARGN})
2222
translate_flag(${SWIFTSOURCES_IS_MAIN} "IS_MAIN" IS_MAIN_arg)
2323
translate_flag(${SWIFTSOURCES_IS_STDLIB} "IS_STDLIB" IS_STDLIB_arg)
@@ -90,7 +90,6 @@ function(handle_swift_sources
9090
FLAGS ${swift_compile_flags}
9191
SDK ${SWIFTSOURCES_SDK}
9292
ARCHITECTURE ${SWIFTSOURCES_ARCHITECTURE}
93-
API_NOTES ${SWIFTSOURCES_API_NOTES}
9493
MODULE_NAME ${SWIFTSOURCES_MODULE_NAME}
9594
${IS_MAIN_arg}
9695
${IS_STDLIB_arg}
@@ -159,7 +158,7 @@ function(_compile_swift_files
159158
cmake_parse_arguments(SWIFTFILE
160159
"IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
161160
"OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT"
162-
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;API_NOTES;OPT_FLAGS;MODULE_DIR"
161+
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;OPT_FLAGS;MODULE_DIR"
163162
${ARGN})
164163

165164
# Check arguments.
@@ -360,28 +359,6 @@ function(_compile_swift_files
360359
set(swift_compiler_tool_dep "swift")
361360
endif()
362361

363-
# Generate API notes if requested.
364-
set(command_create_apinotes)
365-
set(depends_create_apinotes)
366-
set(apinote_files)
367-
368-
foreach(apinote_module ${SWIFTFILE_API_NOTES})
369-
set(apinote_file "${module_dir}/${apinote_module}.apinotes")
370-
set(apinote_input_file
371-
"${SWIFT_API_NOTES_PATH}/${apinote_module}.apinotes")
372-
373-
list(APPEND command_create_apinotes
374-
COMMAND
375-
"${CMAKE_COMMAND}" "-E" "copy_if_different"
376-
"${apinote_input_file}" "${apinote_file}")
377-
list(APPEND depends_create_apinotes "${apinote_input_file}")
378-
379-
list(APPEND apinote_files "${apinote_file}")
380-
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
381-
FILES ${apinote_file}
382-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
383-
endforeach()
384-
385362
# If there are more than one output files, we assume that they are specified
386363
# otherwise e.g. with an output file map.
387364
set(output_option)
@@ -405,7 +382,6 @@ function(_compile_swift_files
405382
endif()
406383

407384
set(standard_outputs ${SWIFTFILE_OUTPUT})
408-
set(apinotes_outputs ${apinote_files})
409385
set(sib_outputs "${sib_file}")
410386
set(sibopt_outputs "${sibopt_file}")
411387
set(sibgen_outputs "${sibgen_file}")
@@ -425,8 +401,6 @@ function(_compile_swift_files
425401
# always gets updated.
426402
set(command_touch_standard_outputs
427403
COMMAND "${CMAKE_COMMAND}" -E touch ${standard_outputs})
428-
set(command_touch_apinotes_outputs
429-
COMMAND "${CMAKE_COMMAND}" -E touch ${apinotes_outputs})
430404
set(command_touch_module_outputs
431405
COMMAND "${CMAKE_COMMAND}" -E touch ${module_outputs})
432406
set(command_touch_sib_outputs
@@ -445,22 +419,6 @@ function(_compile_swift_files
445419
OUTPUT ${obj_dirs}
446420
COMMENT "Generating obj dirs for ${first_output}")
447421

448-
# Generate the api notes if we need them.
449-
if (apinotes_outputs)
450-
add_custom_command_target(
451-
api_notes_dependency_target
452-
# Create API notes before compiling, because this will affect the APIs
453-
# the overlay sees.
454-
${command_create_apinotes}
455-
${command_touch_apinotes_outputs}
456-
COMMAND ""
457-
OUTPUT ${apinotes_outputs}
458-
DEPENDS
459-
${depends_create_apinotes}
460-
${obj_dirs_dependency_target}
461-
COMMENT "Copying API notes for ${first_output}")
462-
endif()
463-
464422
# Then we can compile both the object files and the swiftmodule files
465423
# in parallel in this target for the object file, and ...
466424

@@ -484,7 +442,7 @@ function(_compile_swift_files
484442
DEPENDS
485443
${swift_compiler_tool_dep}
486444
${file_path} ${source_files} ${SWIFTFILE_DEPENDS}
487-
${swift_ide_test_dependency} ${api_notes_dependency_target}
445+
${swift_ide_test_dependency}
488446
${obj_dirs_dependency_target}
489447
COMMENT "Compiling ${first_output}")
490448
set("${dependency_target_out_var_name}" "${dependency_target}" PARENT_SCOPE)
@@ -518,7 +476,7 @@ function(_compile_swift_files
518476
DEPENDS
519477
${swift_compiler_tool_dep}
520478
${source_files} ${SWIFTFILE_DEPENDS}
521-
${swift_ide_test_dependency} ${api_notes_dependency_target}
479+
${swift_ide_test_dependency}
522480
${obj_dirs_dependency_target}
523481
COMMENT "Generating ${module_file}")
524482
set("${dependency_module_target_out_var_name}" "${module_dependency_target}" PARENT_SCOPE)

lib/ClangImporter/ClangImporter.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,12 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
612612

613613
// Enable API notes alongside headers/in frameworks.
614614
invocationArgStrs.push_back("-fapinotes-modules");
615-
invocationArgStrs.push_back("-iapinotes-modules");
616-
invocationArgStrs.push_back(searchPathOpts.RuntimeLibraryImportPath);
617615
invocationArgStrs.push_back("-fapinotes-swift-version=" +
618-
languageVersion.asAPINotesVersionString());
616+
languageVersion.asAPINotesVersionString());
617+
invocationArgStrs.push_back("-iapinotes-modules");
618+
invocationArgStrs.push_back((llvm::Twine(searchPathOpts.RuntimeResourcePath) +
619+
llvm::sys::path::get_separator() +
620+
"apinotes").str());
619621
}
620622

621623
static void

stdlib/public/Platform/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
1414
SWIFT_COMPILE_FLAGS -Xfrontend -disable-objc-attr-requires-foundation-module "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
1515
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
1616
TARGET_SDKS ALL_APPLE_PLATFORMS
17-
API_NOTES_NON_OVERLAY)
17+
18+
# This is overly conservative, but we have so few API notes files that
19+
# haven't migrated to the Swift repo that it's probably fine in practice.
20+
DEPENDS copy_apinotes)
1821

1922
add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
2023
Glibc.swift.gyb

stdlib/public/SwiftShims/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ foreach(input ${sources})
6464
COMMAND
6565
"${CMAKE_COMMAND}" "-E" "copy_if_different"
6666
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
67-
"${output_dir}/${input}")
67+
"${output_dir}/${input}"
68+
COMMENT "Copying ${input} to ${output_dir}")
6869
list(APPEND outputs "${output_dir}/${input}")
6970
endforeach()
7071
# Put the output dir itself last so that it isn't considered the primary output.

0 commit comments

Comments
 (0)