Skip to content

Commit 2c6cc4a

Browse files
authored
Merge pull request #72186 from apple/egorzhdan/swift-bridging-modulemap
[cxx-interop] Refer to `SwiftBridging` module from `usr/include/module.modulemap`
2 parents c0c24c1 + d494632 commit 2c6cc4a

File tree

8 files changed

+55
-37
lines changed

8 files changed

+55
-37
lines changed

lib/ClangImporter/CMakeLists.txt

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,5 @@ add_dependencies(swiftClangImporter
4545
set_swift_llvm_is_available(swiftClangImporter)
4646

4747
if(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER)
48-
# Mark - copy "bridging" (support header) into the local include directory and
49-
# install it into the compiler toolchain.
50-
set(SWIFTINC_DIR
51-
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/swift")
52-
53-
add_custom_command(
54-
OUTPUT "${SWIFTINC_DIR}/bridging"
55-
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/bridging"
56-
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/bridging" "${SWIFTINC_DIR}")
57-
58-
add_custom_target("copy_cxxInterop_support_header"
59-
DEPENDS "${SWIFTINC_DIR}/bridging"
60-
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")
61-
62-
swift_install_in_component(FILES
63-
"${CMAKE_CURRENT_SOURCE_DIR}/bridging"
64-
"${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap"
65-
DESTINATION "include/swift"
66-
COMPONENT compiler)
67-
68-
add_dependencies(swiftClangImporter
69-
"copy_cxxInterop_support_header")
48+
add_subdirectory(SwiftBridging)
7049
endif()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Mark - copy "bridging" (support header) into the local include directory and
2+
# install it into the compiler toolchain.
3+
set(SWIFTINC_DIR
4+
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/swift")
5+
6+
add_custom_command(
7+
OUTPUT "${SWIFTINC_DIR}/bridging"
8+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/swift/bridging"
9+
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/swift/bridging" "${SWIFTINC_DIR}")
10+
11+
add_custom_target("copy_cxxInterop_support_header"
12+
DEPENDS "${SWIFTINC_DIR}/bridging"
13+
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")
14+
15+
swift_install_in_component(FILES
16+
"${CMAKE_CURRENT_SOURCE_DIR}/swift/bridging"
17+
"${CMAKE_CURRENT_SOURCE_DIR}/swift/bridging.modulemap"
18+
DESTINATION "include/swift"
19+
COMPONENT compiler)
20+
swift_install_in_component(FILES
21+
"${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap"
22+
DESTINATION "include"
23+
COMPONENT compiler)
24+
25+
add_dependencies(swiftClangImporter
26+
"copy_cxxInterop_support_header")

lib/ClangImporter/module.modulemap renamed to lib/ClangImporter/SwiftBridging/module.modulemap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
module SwiftBridging {
14-
header "bridging"
15-
16-
export *
17-
}
13+
extern module SwiftBridging "swift/bridging.modulemap"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===------------------ module.modulemap - C++ and Swift module -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
module SwiftBridging {
14+
header "bridging"
15+
16+
export *
17+
}

test/Interop/Cxx/class/Inputs/mutable-members.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Note: in actuality, this will be included
66
// as <swift/bridging>, but in this test we include
77
// it directly.
8-
#include "bridging"
8+
#include "swift/bridging"
99
#else
1010
#define SWIFT_MUTATING
1111
#endif

test/Interop/Cxx/class/mutable-members-with-mutating-annotation-module-interface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-ide-test -print-module -module-to-print=MutableMembers -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -Xcc -DUSE_MUTATING -I %swift_src_root/lib/ClangImporter | %FileCheck %s
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=MutableMembers -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -Xcc -DUSE_MUTATING -I %swift_src_root/lib/ClangImporter/SwiftBridging | %FileCheck %s
22

33
// CHECK: struct HasPublicMutableMember {
44
// CHECK: mutating func foo() -> Int32

test/Interop/Cxx/ergonomics/swift-bridging-annotations.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
// RUN: %target-swift-frontend %t/SwiftMod.swift -module-name SwiftMod -emit-module -o %t/SwiftMod.swiftmodule -I %t -enable-experimental-cxx-interop -Xcc -DFIRSTPASS
66

7-
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
7+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter/SwiftBridging -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
88

9-
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter -source-filename=x -enable-experimental-cxx-interop -Xcc -DINCMOD | %FileCheck %s
9+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter/SwiftBridging -source-filename=x -enable-experimental-cxx-interop -Xcc -DINCMOD | %FileCheck %s
1010

11-
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter -source-filename=x -cxx-interoperability-mode=swift-6 -Xcc -DINCMOD | %FileCheck --check-prefixes=CHECK,CHECKLATEST %s
12-
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter -source-filename=x -cxx-interoperability-mode=upcoming-swift -Xcc -DINCMOD | %FileCheck --check-prefixes=CHECK,CHECKLATEST %s
11+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter/SwiftBridging -source-filename=x -cxx-interoperability-mode=swift-6 -Xcc -DINCMOD | %FileCheck --check-prefixes=CHECK,CHECKLATEST %s
12+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftMod -module-to-print=CxxModule -I %t -I %t/Inputs -I %swift_src_root/lib/ClangImporter/SwiftBridging -source-filename=x -cxx-interoperability-mode=upcoming-swift -Xcc -DINCMOD | %FileCheck --check-prefixes=CHECK,CHECKLATEST %s
1313

1414
// Test through the use of the bridging header
15-
// RUN: %target-swift-frontend -emit-ir -I %t -import-objc-header %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter -enable-experimental-cxx-interop -DBRIDGING_HEADER_TEST -disable-availability-checking %t/SwiftMod.swift
15+
// RUN: %target-swift-frontend -emit-ir -I %t -import-objc-header %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter/SwiftBridging -enable-experimental-cxx-interop -DBRIDGING_HEADER_TEST -disable-availability-checking %t/SwiftMod.swift
1616

1717
// Precompile the bridging header and test the use of that.
18-
// RUN: %target-swift-frontend -emit-pch -I %t -pch-output-dir %t/pch %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter -enable-experimental-cxx-interop
19-
// RUN: %target-swift-frontend -emit-ir -I %t -pch-output-dir %t/pch -import-objc-header %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter -enable-experimental-cxx-interop -DBRIDGING_HEADER_TEST -disable-availability-checking %t/SwiftMod.swift
18+
// RUN: %target-swift-frontend -emit-pch -I %t -pch-output-dir %t/pch %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter/SwiftBridging -enable-experimental-cxx-interop
19+
// RUN: %target-swift-frontend -emit-ir -I %t -pch-output-dir %t/pch -import-objc-header %t/Inputs/header.h -I %swift_src_root/lib/ClangImporter/SwiftBridging -enable-experimental-cxx-interop -DBRIDGING_HEADER_TEST -disable-availability-checking %t/SwiftMod.swift
2020

2121

2222
//--- SwiftMod.swift
@@ -42,7 +42,7 @@ module CxxModule {
4242
// as <swift/bridging>, but in this test we include
4343
// it directly.
4444
#ifndef INCMOD
45-
#include "bridging"
45+
#include "swift/bridging"
4646
#else
4747
#pragma clang module import SwiftBridging
4848
#endif

0 commit comments

Comments
 (0)