Skip to content

Commit 0127c47

Browse files
authored
Merge pull request #60708 from a4z/doc/CxxInteropGettingStarted1
Adopt Cxx header/implementation in example
2 parents ae9f355 + f96bfb2 commit 0127c47

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

docs/CppInteroperability/GettingStartedWithC++Interop.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Getting started with C++ Interoperability
1+
# Getting started with C++ Interoperability
22

33
This document is designed to get you started with bidirectional API-level interoperability between Swift and C++.
44

@@ -32,10 +32,10 @@ module Cxx {
3232
- In your xcode project, follow the steps [Creating a Module to contain your C++ source code](#creating-a-module-to-contain-your-c-source-code) in your project directory
3333

3434
Add the C++ module to the include path and enable C++ interop:
35-
- Navigate to your project directory
35+
- Navigate to your project directory
3636
- In `Project` navigate to `Build Settings` -> `Swift Compiler`
3737
- Under `Custom Flags` -> `Other Swift Flags` add`-enable-experimental-cxx-interop`
38-
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/Cxx`). Repeat this step in `Other Swift Flags`
38+
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/Cxx`). Repeat this step in `Other Swift Flags`
3939

4040
```
4141
//Add to Other Swift Flags and Import Paths respectively
@@ -64,18 +64,19 @@ struct ContentView: View {
6464
#ifndef Cxx_hpp
6565
#define Cxx_hpp
6666
67-
int cxxFunction(int n) {
68-
return n;
69-
}
67+
int cxxFunction(int n);
68+
7069
#endif
7170
```
7271

7372
```
7473
//In Cxx.cpp
7574
7675
#include "Cxx.hpp"
77-
int cxxFunction(int n);
7876
77+
int cxxFunction(int n) {
78+
return n;
79+
}
7980
8081
```
8182

@@ -134,7 +135,7 @@ let package = Package(
134135
import Cxx
135136
136137
public struct CxxInterop {
137-
138+
138139
public func callCxxFunction(n: Int32) -> Int32 {
139140
return cxxFunction(n: n)
140141
}
@@ -152,7 +153,7 @@ After creating your project follow the steps [Creating a Module to contain your
152153
- In`add_library` invoke `cxx-support` with the path to the C++ implementation file
153154
- Add the `target_include_directories` with `cxx-support` and path to the C++ Module `${CMAKE_SOURCE_DIR}/Sources/Cxx`
154155
- Add the `add_executable` to the specific files/directory you would like to generate source, with`SHELL:-enable-experimental-cxx-interop`.
155-
- In the example below we will be following the file structure used in [Creating a Swift Package](#Creating-a-Swift-Package)
156+
- In the example below we will be following the file structure used in [Creating a Swift Package](#Creating-a-Swift-Package)
156157

157158
```
158159
//In CMakeLists.txt
@@ -199,7 +200,7 @@ CxxInterop.main()
199200

200201
- In your project's directory, run `cmake` to generate the systems build files
201202

202-
- To generate an Xcode project run `cmake -GXcode`
203+
- To generate an Xcode project run `cmake -GXcode`
203204
- To generate with Ninja run `cmake -GNinja`
204205

205206
- For more information on `cmake` see the 'GettingStarted' documentation: (https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md)

0 commit comments

Comments
 (0)