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
This will produce a regular executable binary, but notice that it's very small in size and that it also *does not actually depend on the Swift runtime in the OS* (all Embedded Swift binaries carry their runtime+stdlib dependencies within):
22
+
This will produce a regular executable binary, and we can execute it right away:
23
+
24
+
```shell
25
+
$ ./HelloEmbedded
26
+
Hello, Embedded Swift 😊
27
+
```
28
+
Hooray! Our first *host-side* Embedded Swift program is working!
29
+
30
+
## Details
31
+
32
+
Looking closer, this binary *does not actually depend on the Swift runtime in the OS* (all Embedded Swift binaries carry their runtime+stdlib dependencies within), but it is still a *dynamically-linked executable*, so it's not fully standalone in the embedded sense:
23
33
24
34
```shell
25
-
$ ls -al
26
-
-rwxr-xr-x 1 kuba staff 18K May 16 17:19 HelloEmbedded*
27
-
-rw-r--r-- 1 kuba staff 59B May 16 17:16 HelloEmbedded.swift
28
35
$ otool -L HelloEmbedded
29
36
HelloEmbedded:
30
-
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1000.0.0)
37
+
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1000.0.0)
31
38
```
32
39
33
-
Let's run it:
40
+
However, the singular object file that was used to build this executable was produced by the compiler in the same fashion that a real embedded build would. If we ask the compiler and linker to minimize the size of the outputs and to remove any unused code, we can observe that the binary has no dependencies other than `putchar` from `libSystem` and that the machine code section is very small (176 bytes in the `__text` section):
Copy file name to clipboardExpand all lines: Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md
-28Lines changed: 0 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,31 +76,3 @@ It's very common to integrate with existing SDKs in embedded development. This t
76
76
Most embedded SDKs provide a build system integration, commonly with CMake, Make, or their own custom build scripts. At the most basic level, it's always possible to manually call the compiler (`swiftc`) as described above from any build system. This will produce a .o file for the entire Swift module, and then a .o file can typically be directly used in the build system.
77
77
78
78
For details and concrete examples of how to integrate with more common platforms, SDKs and build systems, see <doc:IntegratingWithPlatforms>.
79
-
80
-
### Building a macOS Embedded Swift program:
81
-
82
-
It's also possible to build in Embedded Swift mode for regular non-embedded operating systems, like macOS. This is very useful for testing purposes, or if you just want to observe and experiment with Embedded Swift. A simple source code like this:
83
-
84
-
```swift
85
-
print("Hello, embedded world!")
86
-
```
87
-
88
-
...can be compiled using the `-enable-experimental-feature Embedded` flag (the implicit `-target` matches the host OS):
Note that the resulting executable is still a *dynamically-linked executable*, so it's not fully standalone in the embedded sense. Namely is still uses `putchar` from Libsystem. But the singular object file that was used to build this executable was produced by the compiler in the same fashion that a real embedded build would. If we ask the compiler and linker to minimize the size of the outputs and to remove any unused code, we can observe that the binary has no other dependencies other than `putchar` and that the machine code section is very small (172 bytes in the `__text` section):
0 commit comments