File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
test/Interop/CxxToSwiftToCxx Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ // RUN: %empty-directory(%t)
2+ // RUN: split-file %s %t
3+
4+ // 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 -emit-clang-header-path %t/Swift.h -experimental-skip-all-function-bodies
5+ // RUN: %target-swift-frontend -typecheck %t/use-cxx-types.swift -typecheck -module-name UseCxx -emit-clang-header-path %t/UseCxx.h -I %t -enable-experimental-cxx-interop -clang-header-expose-decls=all-public
6+
7+ // RUN: %target-interop-build-clangxx -std=c++20 -c %t/use-swift-cxx-types.cpp -I %t -o %t/swift-cxx-execution.o -g
8+ // RUN: %target-interop-build-swift %t/use-cxx-types.swift -o %t/swift-cxx-execution -Xlinker %t/swift-cxx-execution.o -module-name UseCxx -Xfrontend -entry-point-function-name -Xfrontend swiftMain -I %t -g
9+
10+ // RUN: %target-codesign %t/swift-cxx-execution
11+ // RUN: %target-run %t/swift-cxx-execution
12+
13+ // REQUIRES: executable_test
14+
15+ // --- header.h
16+ enum class SomeEnum {
17+ first,
18+ second
19+ };
20+
21+ // --- module.modulemap
22+ module CxxTest {
23+ header " header.h"
24+ requires cplusplus
25+ }
26+
27+ // --- use-cxx-types.swift
28+ import CxxTest
29+
30+ public class SomethingSwift {
31+ public var someEnum: SomeEnum { get { return .first } }
32+ public init () {}
33+ }
34+
35+ // --- use-swift-cxx-types.cpp
36+
37+ #include " header.h"
38+ #include " Swift.h"
39+ #include " UseCxx.h"
40+ #include < assert.h>
41+
42+ class SomethingCxx {
43+ public:
44+ SomethingCxx (UseCxx::SomethingSwift swiftPart): _swiftPart(swiftPart) { }
45+
46+ SomeEnum getSomeEnum () { return _swiftPart.getSomeEnum (); }
47+
48+ private:
49+ UseCxx::SomethingSwift _swiftPart;
50+ };
51+
52+ int main () {
53+ auto sp = UseCxx::SomethingSwift::init ();
54+ auto sc = SomethingCxx (sp);
55+ auto e = sc.getSomeEnum ();
56+ assert (e == SomeEnum::first);
57+ return 0 ;
58+ }
You can’t perform that action at this time.
0 commit comments