Skip to content

Commit 2dcbeb0

Browse files
committed
[interop][SwiftToCxx] do not require @_expose when generating C++ interface for a Swift module
Instead, we emit API bindings for all supported public APIs, when -enable-experimental-cxx-interop is enabled
1 parent 4c24669 commit 2dcbeb0

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

lib/PrintAsClang/PrintAsClang.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,16 @@ bool swift::printAsClangHeader(raw_ostream &os, ModuleDecl *M,
563563
ClangSyntaxPrinter(os).printIncludeForShimHeader(
564564
"_SwiftCxxInteroperability.h");
565565

566+
// Explicit @expose attribute is required only when the user specifies
567+
// -clang-header-expose-decls flag.
568+
// FIXME: should we detect any presence of @expose and require it then?
566569
bool requiresExplicitExpose =
567-
!frontendOpts.ClangHeaderExposedDecls.has_value() ||
568-
*frontendOpts.ClangHeaderExposedDecls ==
569-
FrontendOptions::ClangHeaderExposeBehavior::HasExposeAttr ||
570-
*frontendOpts.ClangHeaderExposedDecls ==
571-
FrontendOptions::ClangHeaderExposeBehavior::
572-
HasExposeAttrOrImplicitDeps;
570+
frontendOpts.ClangHeaderExposedDecls.has_value() &&
571+
(*frontendOpts.ClangHeaderExposedDecls ==
572+
FrontendOptions::ClangHeaderExposeBehavior::HasExposeAttr ||
573+
*frontendOpts.ClangHeaderExposedDecls ==
574+
FrontendOptions::ClangHeaderExposeBehavior::
575+
HasExposeAttrOrImplicitDeps);
573576
// Swift stdlib dependencies are emitted into the same header when
574577
// -clang-header-expose-decls flag is not specified, or when it allows
575578
// implicit dependency emission.

test/Interop/SwiftToCxx/functions/swift-expected-execution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -Xcc -fno-exceptions -enable-experimental-cxx-interop -emit-clang-header-path %t/functions.h
3+
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -Xcc -fno-exceptions -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr-or-stdlib -emit-clang-header-path %t/functions.h
44

55
// RUN: %target-interop-build-clangxx -c %s -I %t -fno-exceptions -o %t/swift-expected-execution.o
66
// RUN: %target-interop-build-swift %S/swift-functions-errors.swift -o %t/swift-expected-execution -Xlinker %t/swift-expected-execution.o -module-name Functions -Xfrontend -entry-point-function-name -Xfrontend swiftMain

test/Interop/SwiftToCxx/functions/swift-functions-errors-execution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -enable-experimental-cxx-interop -emit-clang-header-path %t/functions.h
3+
// RUN: %target-swift-frontend %S/swift-functions-errors.swift -typecheck -module-name Functions -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr-or-stdlib -emit-clang-header-path %t/functions.h
44

55
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-functions-errors-execution.o
66
// RUN: %target-interop-build-swift %S/swift-functions-errors.swift -o %t/swift-functions-errors-execution -Xlinker %t/swift-functions-errors-execution.o -module-name Functions -Xfrontend -entry-point-function-name -Xfrontend swiftMain

test/Interop/SwiftToCxx/functions/swift-functions-errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -enable-experimental-cxx-interop -emit-clang-header-path %t/functions.h
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr-or-stdlib -emit-clang-header-path %t/functions.h
33
// RUN: %FileCheck %s < %t/functions.h
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -Wno-unused-function)

test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -parse-as-library %platform-module-dir/Swift.swiftmodule/%module-target-triple.swiftinterface -enable-library-evolution -disable-objc-attr-requires-foundation-module -typecheck -module-name Swift -parse-stdlib -enable-experimental-cxx-interop -emit-clang-header-path %t/Swift.h -experimental-skip-all-function-bodies
2+
// RUN: %target-swift-frontend -parse-as-library %platform-module-dir/Swift.swiftmodule/%module-target-triple.swiftinterface -enable-library-evolution -disable-objc-attr-requires-foundation-module -typecheck -module-name Swift -parse-stdlib -enable-experimental-cxx-interop -clang-header-expose-decls=has-expose-attr-or-stdlib -emit-clang-header-path %t/Swift.h -experimental-skip-all-function-bodies
33
// RUN: %FileCheck %s < %t/Swift.h
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/Swift.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -Wno-unused-private-field -Wno-unused-function -Wc++98-compat-extra-semi)

0 commit comments

Comments
 (0)