←back to thread

612 points dayanruben | 5 comments | | HN request time: 0.001s | source
Show context
sgt ◴[] No.42899856[source]
Is Swift actually serious about embedded?
replies(6): >>42899910 #>>42899953 #>>42900093 #>>42900473 #>>42901728 #>>42905236 #
timsneath ◴[] No.42899910[source]
Of course! Tons of examples here: https://github.com/apple/swift-embedded-examples

At WWDC24, we shared a session on embedded Swift, which is available on YouTube: https://www.youtube.com/watch?v=LqxbsADqDI4

More documentation on embedded Swift tooling here: https://github.com/swiftlang/swift/blob/main/docs/EmbeddedSw...

(Disclosure: I work at Apple.)

replies(5): >>42900254 #>>42900260 #>>42900653 #>>42901449 #>>42901605 #
1. sgt ◴[] No.42900260[source]
Swift is unbelievably cool but I wonder about using Swift for an embedded project as opposed to just C or with FreeRTOS for a more capable system. Is interoperability possible - as in FreeRTOS+swift?
replies(3): >>42900529 #>>42900551 #>>42900720 #
2. pjmlp ◴[] No.42900529[source]
Why should it not, one of the design goals of Swift as C, Objective-C and C++ replacement was painless interop with those languages.

Thus it is more an issue of Swift embedded toolchain being able to be used alongside FreeRTOS on the specific hardware target.

replies(1): >>42902182 #
3. aseipp ◴[] No.42900551[source]
For the most part, yes, it should be very achievable. Embedded Swift basically just produces an object file that looks like any object file from a C compiler. The objects mostly rely on very basic primitives like malloc/memcpy so it's pretty freestanding (you can turn off allocations, too). It also has very good support for importing C headers into Swift code so you can interop easily.

Probably the biggest roadbump for something like FreeRTOS is the asynchronous support though. Embedded Swift's async support is still extremely rudimentary and I didn't find much about how to extend it/attach it to other control loops. I think it only supports single-threaded execution right now as well.

4. robterrell ◴[] No.42900720[source]
If you look at the blinking LED sample, it's pulling in the freertos header:

  #include "freertos/FreeRTOS.h"
So presumably yes?
5. josteink ◴[] No.42902182[source]
> Why should it not, one of the design goals of Swift as C, Objective-C and C++ replacement was painless interop with those languages.

This is actually a very good quality. I'm exploiting that for all it's worth in a job project where I'm gradually (file by file) converting a legacy codebase from Objective-C to Swift.

Providing an exit-strategy for Objective-C is good enough reason for me to at least have a basic working knowledge of the language.