Skip to content

Commit db7529f

Browse files
authored
Merge pull request #20784 from jrose-apple/generated-nine-out-of-ten
[CMake] Conditionalize generation of .swiftinterface files
2 parents 4d9f8ba + 022fe5d commit db7529f

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ option(SWIFT_FORCE_OPTIMIZED_TYPECHECKER "Override the optimization setting of
176176
the type checker so that it always compiles with optimization. This eases
177177
debugging after type checking occurs by speeding up type checking" FALSE)
178178

179+
option(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES
180+
"Generate .swiftinterface files alongside .swiftmodule files"
181+
TRUE)
182+
179183
#
180184
# User-configurable Android specific options.
181185
#

cmake/modules/SwiftSource.cmake

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ function(_compile_swift_files
303303

304304
set(module_file)
305305
set(module_doc_file)
306+
set(interface_file)
306307

307308
if(NOT SWIFTFILE_IS_MAIN)
308309
# Determine the directory where the module file should be placed.
@@ -322,7 +323,11 @@ function(_compile_swift_files
322323
set(sibopt_file "${module_base}.O.sib")
323324
set(sibgen_file "${module_base}.sibgen")
324325
set(module_doc_file "${module_base}.swiftdoc")
325-
set(interface_file "${module_base}.swiftinterface")
326+
327+
if(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES)
328+
set(interface_file "${module_base}.swiftinterface")
329+
list(APPEND swift_flags "-emit-parseable-module-interface")
330+
endif()
326331

327332
list(APPEND command_create_dirs
328333
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
@@ -338,8 +343,13 @@ function(_compile_swift_files
338343
endif()
339344
endif()
340345

346+
set(module_outputs "${module_file}" "${module_doc_file}")
347+
if(interface_file)
348+
list(APPEND module_outputs "${interface_file}")
349+
endif()
350+
341351
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
342-
FILES "${module_file}" "${module_doc_file}" "${interface_file}"
352+
FILES ${module_outputs}
343353
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
344354

345355
set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")
@@ -396,7 +406,6 @@ function(_compile_swift_files
396406

397407
set(standard_outputs ${SWIFTFILE_OUTPUT})
398408
set(apinotes_outputs ${apinote_files})
399-
set(module_outputs "${module_file}" "${module_doc_file}" "${interface_file}")
400409
set(sib_outputs "${sib_file}")
401410
set(sibopt_outputs "${sibopt_file}")
402411
set(sibgen_outputs "${sibgen_file}")
@@ -499,15 +508,11 @@ function(_compile_swift_files
499508
add_custom_command_target(
500509
module_dependency_target
501510
COMMAND
502-
"${CMAKE_COMMAND}" "-E" "remove" "-f" "${module_file}"
503-
COMMAND
504-
"${CMAKE_COMMAND}" "-E" "remove" "-f" "${module_doc_file}"
505-
COMMAND
506-
"${CMAKE_COMMAND}" "-E" "remove" "-f" "${interface_file}"
511+
"${CMAKE_COMMAND}" "-E" "remove" "-f" ${module_outputs}
507512
COMMAND
508513
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
509514
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"
510-
"-emit-parseable-module-interface" ${swift_flags} "@${file_path}"
515+
${swift_flags} "@${file_path}"
511516
${command_touch_module_outputs}
512517
OUTPUT ${module_outputs}
513518
DEPENDS

validation-test/ParseableInterface/verify_all_overlays.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Note that this test should still "pass" when no swiftinterfaces have been
2+
// generated.
3+
14
// RUN: %empty-directory(%t)
2-
// RUN: for x in %platform-sdk-overlay-dir/*.swiftinterface; do [[ $(basename "$x") = Swift.swiftinterface || $(basename "$x") = simd.swiftinterface || $(basename "$x") = SwiftLang.swiftinterface ]] && continue; %target-swift-frontend "$x" -emit-module -o %t/$(basename "$x" .swiftinterface).swiftmodule -disable-objc-attr-requires-foundation-module -enable-resilience -Fsystem %sdk/System/Library/PrivateFrameworks/ -swift-version 4 || echo '%target-os:' $(basename "$x") >> %t/failures.txt; done
3-
// RUN: diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)
5+
// RUN: for x in %platform-sdk-overlay-dir/*.swiftinterface; do [[ $(basename "$x") = Swift.swiftinterface || $(basename "$x") = simd.swiftinterface || $(basename "$x") = SwiftLang.swiftinterface || $(basename "$x") = '*.swiftinterface' ]] && continue; %target-swift-frontend "$x" -emit-module -o %t/$(basename "$x" .swiftinterface).swiftmodule -disable-objc-attr-requires-foundation-module -enable-resilience -Fsystem %sdk/System/Library/PrivateFrameworks/ -swift-version 4 || echo '%target-os:' $(basename "$x") >> %t/failures.txt; done
6+
// RUN: test ! -e %t/failures.txt || diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)
47

58
// REQUIRES: nonexecutable_test
69

validation-test/ParseableInterface/verify_all_overlays_O.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Note that this test should still "pass" when no swiftinterfaces have been
2+
// generated.
3+
14
// RUN: %empty-directory(%t)
2-
// RUN: for x in %platform-sdk-overlay-dir/*.swiftinterface; do [[ $(basename "$x") = Swift.swiftinterface || $(basename "$x") = simd.swiftinterface || $(basename "$x") = SwiftLang.swiftinterface ]] && continue; %target-swift-frontend "$x" -emit-module -o %t/$(basename "$x" .swiftinterface).swiftmodule -disable-objc-attr-requires-foundation-module -enable-resilience -Fsystem %sdk/System/Library/PrivateFrameworks/ -swift-version 4 -O || echo '%target-os:' $(basename "$x") >> %t/failures.txt; done
3-
// RUN: diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)
5+
// RUN: for x in %platform-sdk-overlay-dir/*.swiftinterface; do [[ $(basename "$x") = Swift.swiftinterface || $(basename "$x") = simd.swiftinterface || $(basename "$x") = SwiftLang.swiftinterface || $(basename "$x") = '*.swiftinterface' ]] && continue; %target-swift-frontend "$x" -emit-module -o %t/$(basename "$x" .swiftinterface).swiftmodule -disable-objc-attr-requires-foundation-module -enable-resilience -Fsystem %sdk/System/Library/PrivateFrameworks/ -swift-version 4 -O || echo '%target-os:' $(basename "$x") >> %t/failures.txt; done
6+
// RUN: test ! -e %t/failures.txt || diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)
47

58
// REQUIRES: nonexecutable_test
69

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Note that this test should still "pass" when simd.swiftinterface has not been
2+
// generated.
3+
14
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend %platform-sdk-overlay-dir/simd.swiftinterface -emit-module -o %t/simd.swiftmodule -enable-resilience -parse-stdlib -import-module Swift -swift-version 4
3-
// RUN: %target-swift-frontend %platform-sdk-overlay-dir/simd.swiftinterface -emit-module -o %t/simd.swiftmodule -enable-resilience -parse-stdlib -import-module Swift -swift-version 4 -O
5+
// RUN: test ! -e %platform-sdk-overlay-dir/simd.swiftinterface || %target-swift-frontend %platform-sdk-overlay-dir/simd.swiftinterface -emit-module -o %t/simd.swiftmodule -enable-resilience -parse-stdlib -import-module Swift -swift-version 4
6+
// RUN: test ! -e %platform-sdk-overlay-dir/simd.swiftinterface || %target-swift-frontend %platform-sdk-overlay-dir/simd.swiftinterface -emit-module -o %t/simd.swiftmodule -enable-resilience -parse-stdlib -import-module Swift -swift-version 4 -O
47

58
// REQUIRES: nonexecutable_test
69
// REQUIRES: objc_interop

0 commit comments

Comments
 (0)