You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/EmbeddedSwift/Documentation.docc/SDKSupport/IntegrateWithZephyr.md
+39-13Lines changed: 39 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -31,26 +31,27 @@ Refer to the [Zephyr Releases](https://docs.zephyrproject.org/latest/releases/in
31
31
32
32
## Project Setup
33
33
34
-
Once Zephyr is setup, the next step is to setup a project with a bridging header, `CMakeLists.txt`, `Main.swift`, and `prj.conf`:
34
+
Once Zephyr is setup, the next step is to setup a project with the following files included:
35
35
36
36
```plain
37
-
SwiftZephyrProject/BridgingHeader.h
37
+
SwiftZephyrProject/src/BridgingHeader.h
38
+
SwiftZephyrProject/src/Main.swift
39
+
SwiftZephyrProject/src/Stubs.c
38
40
SwiftZephyrProject/CMakeLists.txt
39
-
SwiftZephyrProject/Main.swift
40
41
SwiftZephyrProject/prj.conf
41
42
```
42
43
43
-
These are the minimum required files in order to build a Zephyr project. For example, `prj.conf` is required even if it is empty, or the project will not build.
44
+
These are the minimum required files in order to build a Zephyr project. By convention, source files should be placed in the src/ subdirectory, but this is not a hard requirement. Also, `prj.conf` is required even if it is empty, or the project will not build.
44
45
45
-
Inside of `BridgingHeader.h`, add the following content as a minimum:
46
+
Inside of `src/BridgingHeader.h`, add the following content as a minimum:
46
47
47
48
```c
48
49
#pragma once
49
50
50
51
#include<autoconf.h>
51
52
```
52
53
53
-
The `Main.swift` file must contain a `static func main()` as follows:
54
+
The `src/Main.swift` file must contain a `static func main()` as follows:
54
55
55
56
```swift
56
57
@main
@@ -61,6 +62,30 @@ struct Main {
61
62
}
62
63
```
63
64
65
+
Since Embedded Swift requires posix_memalign to be defined, add the following to `src/Stubs.c` to define it:
The `CMakeLists.txt` setup is more involved and complex since target, compilation flags, and library linking must be specified for Swift. First, some initial setup and flags:
@@ -69,20 +94,19 @@ The `CMakeLists.txt` setup is more involved and complex since target, compilatio
# Create a new project called "SwiftZephyrProject" and enable "Swift" as a supported language
80
101
project(SwiftZephyrProject Swift)
81
102
```
82
103
83
-
The following flags have been curated to work well with `armv7em-none-none-eabi` target with `swiftc`. Some flags may need to change depending on the chosen target:
104
+
The following flags have been curated to work well with the `armv7em-none-none-eabi` target with `swiftc`. Some flags may need to change depending on the chosen target:
84
105
85
106
```cmake
107
+
# Use the armv7em-none-none-eabi target triple for Swift
0 commit comments