Skip to content

[CMake] Conditionalize generation of .swiftinterface files #20784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ option(SWIFT_FORCE_OPTIMIZED_TYPECHECKER "Override the optimization setting of
the type checker so that it always compiles with optimization. This eases
debugging after type checking occurs by speeding up type checking" FALSE)

option(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES
"Generate .swiftinterface files alongside .swiftmodule files"
TRUE)

#
# User-configurable Android specific options.
#
Expand Down
23 changes: 14 additions & 9 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ function(_compile_swift_files

set(module_file)
set(module_doc_file)
set(interface_file)

if(NOT SWIFTFILE_IS_MAIN)
# Determine the directory where the module file should be placed.
Expand All @@ -322,7 +323,11 @@ function(_compile_swift_files
set(sibopt_file "${module_base}.O.sib")
set(sibgen_file "${module_base}.sibgen")
set(module_doc_file "${module_base}.swiftdoc")
set(interface_file "${module_base}.swiftinterface")

if(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES)
set(interface_file "${module_base}.swiftinterface")
list(APPEND swift_flags "-emit-parseable-module-interface")
endif()

list(APPEND command_create_dirs
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
Expand All @@ -338,8 +343,13 @@ function(_compile_swift_files
endif()
endif()

set(module_outputs "${module_file}" "${module_doc_file}")
if(interface_file)
list(APPEND module_outputs "${interface_file}")
endif()

swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
FILES "${module_file}" "${module_doc_file}" "${interface_file}"
FILES ${module_outputs}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")

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

set(standard_outputs ${SWIFTFILE_OUTPUT})
set(apinotes_outputs ${apinote_files})
set(module_outputs "${module_file}" "${module_doc_file}" "${interface_file}")
set(sib_outputs "${sib_file}")
set(sibopt_outputs "${sibopt_file}")
set(sibgen_outputs "${sibgen_file}")
Expand Down Expand Up @@ -499,15 +508,11 @@ function(_compile_swift_files
add_custom_command_target(
module_dependency_target
COMMAND
"${CMAKE_COMMAND}" "-E" "remove" "-f" "${module_file}"
COMMAND
"${CMAKE_COMMAND}" "-E" "remove" "-f" "${module_doc_file}"
COMMAND
"${CMAKE_COMMAND}" "-E" "remove" "-f" "${interface_file}"
"${CMAKE_COMMAND}" "-E" "remove" "-f" ${module_outputs}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works, that is great. I recently learnt that the multi-file variant of the commands was added in CMake 3.5 for some of them :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, hm. It works on my machine™ but I'll go check before I merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was in 3.4 at least, and our current oldest supported version is 3.4.3.

COMMAND
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"
"-emit-parseable-module-interface" ${swift_flags} "@${file_path}"
${swift_flags} "@${file_path}"
${command_touch_module_outputs}
OUTPUT ${module_outputs}
DEPENDS
Expand Down
7 changes: 5 additions & 2 deletions validation-test/ParseableInterface/verify_all_overlays.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Note that this test should still "pass" when no swiftinterfaces have been
// generated.

// RUN: %empty-directory(%t)
// 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
// RUN: diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)
// 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
// RUN: test ! -e %t/failures.txt || diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)

// REQUIRES: nonexecutable_test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Note that this test should still "pass" when no swiftinterfaces have been
// generated.

// RUN: %empty-directory(%t)
// 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
// RUN: diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)
// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, this really makes the test difficult to port on windows :-(.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is kind of a mess anyway. I should probably just write a Python script. But I don't think I've made it worse of a mess than it already was.

// RUN: test ! -e %t/failures.txt || diff <(grep '%target-os:' %s) <(sort -f %t/failures.txt)

// REQUIRES: nonexecutable_test

Expand Down
7 changes: 5 additions & 2 deletions validation-test/ParseableInterface/verify_simd.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Note that this test should still "pass" when simd.swiftinterface has not been
// generated.

// RUN: %empty-directory(%t)
// 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
// 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
// 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
// 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

// REQUIRES: nonexecutable_test
// REQUIRES: objc_interop