Skip to content

Commit 0d65e88

Browse files
authored
Merge pull request swiftlang#41794 from hyp/cxx-multilang-substitute
[cxx-interop][test] add %check-interop-cxx-header-in-clang test command substitution to parse and validate generated C++ header in multiple C++ language modes
2 parents cfe0b97 + 2c2fa56 commit 0d65e88

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

test/Interop/SwiftToCxx/functions/cdecl.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend %s -typecheck -module-name CdeclFunctions -emit-cxx-header-path %t/empty.h
3-
// RUN: %FileCheck %s < %t/empty.h
2+
// RUN: %target-swift-frontend %s -typecheck -module-name CdeclFunctions -emit-cxx-header-path %t/cdecl.h
3+
// RUN: %FileCheck %s < %t/cdecl.h
44

5-
// RUN: %check-cxx-header-in-clang -std=c++14 %t/empty.h
6-
// RUN: %check-cxx-header-in-clang -std=c++17 %t/empty.h
5+
// RUN: %check-interop-cxx-header-in-clang(%t/cdecl.h)
76

87
// CHECK-LABEL: namespace CdeclFunctions {
98

test/Interop/SwiftToCxx/functions/function-availability.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -emit-cxx-header-path %t/functions.h
33
// RUN: %FileCheck %s < %t/functions.h
44

5-
// RUN: %check-cxx-header-in-clang -std=c++14 %t/functions.h
6-
// RUN: %check-cxx-header-in-clang -std=c++17 %t/functions.h
5+
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
76

87
// CHECK-LABEL: namespace Functions {
98

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -emit-cxx-header-path %t/functions.h
33
// RUN: %FileCheck %s < %t/functions.h
44

5-
// RUN: %check-cxx-header-in-clang -std=c++14 %t/functions.h
6-
// RUN: %check-cxx-header-in-clang -std=c++17 %t/functions.h
5+
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
76

87
// CHECK-LABEL: namespace Functions {
98

test/Interop/SwiftToCxx/module/module-to-namespace.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck -module-name Test -emit-cxx-header-path %t/empty.h
33
// RUN: %FileCheck %s < %t/empty.h
44

5-
// RUN: %check-cxx-header-in-clang -std=c++14 %t/empty.h
6-
// RUN: %check-cxx-header-in-clang -std=c++17 %t/empty.h
5+
// RUN: %check-interop-cxx-header-in-clang(%t/empty.h)
76

87
// CHECK-LABEL: namespace Test {
98
// CHECK: } // namespace Test

test/Interop/lit.local.cfg

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@ def get_target_os():
66
(run_cpu, run_vendor, run_os, run_version) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups()
77
return run_os
88

9-
libc_opt = ''
109
clang_opt = ''
1110

1211
if get_target_os() in ['windows-msvc']:
1312
config.substitutions.insert(0, ('%target-abi', 'WIN'))
14-
#libc_opt = '-libc MT '
13+
# Clang should build object files with link settings equivalent to -libc MD
14+
# when building for the MSVC target.
1515
clang_opt = '-D_MT -D_DLL -Xclang --dependent-lib=msvcrt -Xclang --dependent-lib=oldnames '
1616
else:
1717
# FIXME(compnerd) do all the targets we currently support use SysV ABI?
1818
config.substitutions.insert(0, ('%target-abi', 'SYSV'))
1919

20-
config.substitutions.insert(0, ('%target-interop-build-swift', '%target-build-swift -Xfrontend -enable-cxx-interop ' + libc_opt))
20+
# Enable C++ interop when compiling Swift sources.
21+
config.substitutions.insert(0, ('%target-interop-build-swift',
22+
'%target-build-swift -Xfrontend -enable-cxx-interop '))
23+
# Build C++ files with matching link settings, if required by the target.
2124
config.substitutions.insert(0, ('%target-interop-build-clangxx', '%target-clangxx ' + clang_opt))
25+
26+
# Test parsing of the generated C++ header in different C++ language modes.
27+
config.substitutions.insert(0, ('%check-interop-cxx-header-in-clang\(([^)]+)\)',
28+
SubstituteCaptures(r'%check-cxx-header-in-clang -std=c++14 \1 && '
29+
r'%check-cxx-header-in-clang -std=c++17 \1 && '
30+
r'%check-cxx-header-in-clang -std=c++20 \1')))

0 commit comments

Comments
 (0)