# Feasibility of Swift for Arduino

**URL:** <https://forums.swift.org/t/feasibility-of-swift-for-arduino/94>\
**Category:** Compiler\
**Tags:** arduino\
**Created:** [December 4, 2015, 1:37pm UTC](https://forums.swift.org/t/feasibility-of-swift-for-arduino/94 "2015-12-04T13:37:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthijs\_Hollemans](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Matthijs\_Hollemans](https://forums.swift.org/u/Matthijs_Hollemans)\
**Post date:** [December 4, 2015, 1:37pm UTC](https://forums.swift.org/t/feasibility-of-swift-for-arduino/94/1 "2015-12-04T13:37:57Z")

</div>

Hi all,

Just out of curiosity, how feasible would it be to get swiftc working as a cross-compiler for Arduino microcontrollers?

Currently the Arduino is programmed in C/C++ and seeing as Swift is positioned as a replacement for those languages, I’m wondering if it could live up to this task already.

Obviously, the low-end Arduinos use an 8-bit CPU and an LLVM code generator for this CPU is required. But my main concern is the requirements of the Swift runtime. An Arduino Uno only has 32 kB of working memory. How much of that would be taken up by the Swift runtime?

Any insights would be appreciated!

-Matthijs

---

<div class="post-metadata">

**Author:** ![gribozavr](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@gribozavr](https://forums.swift.org/u/gribozavr)\
**Post date:** [December 4, 2015, 5:26pm UTC](https://forums.swift.org/t/feasibility-of-swift-for-arduino/94/2 "2015-12-04T17:26:30Z")

</div>

The runtime and the standard library currently take much more than 32  
kB. Also, the runtime and the standard library in many places rely on  
having an OS providing a POSIX API. I'm also unsure about the state  
of the LLVM backend for ATmega. I'm not saying that running on a  
small 8-bit microcontroller is completely infeasible, but it will  
certainly require a major engineering effort across the whole stack,  
starting from LLVM.

Dmitri

> **···**
>
> On Fri, Dec 4, 2015 at 5:37 AM, Matthijs Hollemans \<mail@hollance.com\> wrote:
> 
> > Hi all,
> > 
> > Just out of curiosity, how feasible would it be to get swiftc working as a cross-compiler for Arduino microcontrollers?
> > 
> > Currently the Arduino is programmed in C/C++ and seeing as Swift is positioned as a replacement for those languages, I’m wondering if it could live up to this task already.
> > 
> > Obviously, the low-end Arduinos use an 8-bit CPU and an LLVM code generator for this CPU is required. But my main concern is the requirements of the Swift runtime. An Arduino Uno only has 32 kB of working memory. How much of that would be taken up by the Swift runtime?
> 
> --  
> main(i,j){for(i=2;;i++){for(j=2;j\<i;j++){if(!(i%j)){j=0;break;}}if  
> (j){printf("%d\n",i);}}} /\*Dmitri Gribenko \<gribozavr@gmail.com\>\*/

---

<div class="post-metadata">

**Author:** ![Steven\_Hepting](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/steven_hepting/32/5160_2.png) [@Steven\_Hepting](https://forums.swift.org/u/Steven_Hepting)\
**Post date:** [December 4, 2015, 7:17pm UTC](https://forums.swift.org/t/feasibility-of-swift-for-arduino/94/3 "2015-12-04T19:17:35Z")

</div>

Matthijs, perhaps another option for Microcontroller work with Swift would  
be the Raspberry Pi. It runs a full version of Linux and has the $5  
Raspberry Pi Zero option now.

I'd love to hear of any progress on that front.

> **···**
>
> On Fri, Dec 4, 2015 at 9:26 AM, Dmitri Gribenko \<gribozavr@gmail.com\> wrote:
> 
> > On Fri, Dec 4, 2015 at 5:37 AM, Matthijs Hollemans \<mail@hollance.com\> \> wrote:  
> > \> Hi all,  
> > \>  
> > \> Just out of curiosity, how feasible would it be to get swiftc working as  
> > a cross-compiler for Arduino microcontrollers?  
> > \>  
> > \> Currently the Arduino is programmed in C/C++ and seeing as Swift is  
> > positioned as a replacement for those languages, I’m wondering if it could  
> > live up to this task already.  
> > \>  
> > \> Obviously, the low-end Arduinos use an 8-bit CPU and an LLVM code  
> > generator for this CPU is required. But my main concern is the requirements  
> > of the Swift runtime. An Arduino Uno only has 32 kB of working memory. How  
> > much of that would be taken up by the Swift runtime?
> > 
> > The runtime and the standard library currently take much more than 32  
> > kB. Also, the runtime and the standard library in many places rely on  
> > having an OS providing a POSIX API. I'm also unsure about the state  
> > of the LLVM backend for ATmega. I'm not saying that running on a  
> > small 8-bit microcontroller is completely infeasible, but it will  
> > certainly require a major engineering effort across the whole stack,  
> > starting from LLVM.
> > 
> > Dmitri
> > 
> > --  
> > main(i,j){for(i=2;;i++){for(j=2;j\<i;j++){if(!(i%j)){j=0;break;}}if  
> > (j){printf("%d\n",i);}}} /\*Dmitri Gribenko \<gribozavr@gmail.com\>\*/  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-dev mailing list  
> > swift-dev@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-dev](https://lists.swift.org/mailman/listinfo/swift-dev)
> 
> --  
> Steven Hepting  
> iOS Developer

---

<div class="post-metadata">

**Author:** ![gribozavr](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@gribozavr](https://forums.swift.org/u/gribozavr)\
**Post date:** [December 4, 2015, 7:23pm UTC](https://forums.swift.org/t/feasibility-of-swift-for-arduino/94/4 "2015-12-04T19:23:39Z")

</div>

We don't have plans on working on that now, but we have an issue in  
the bug tracker for the Raspberry Pi port:  
[[SR-40] Port Swift to Linux on Raspberry Pi · Issue #5337 · apple/swift-package-manager · GitHub](https://bugs.swift.org/browse/SR-40) . Feel free to subscribe!

Dmitri

> **···**
>
> On Fri, Dec 4, 2015 at 11:17 AM, Steven Hepting \<shepting@twitter.com\> wrote:
> 
> > Matthijs, perhaps another option for Microcontroller work with Swift would  
> > be the Raspberry Pi. It runs a full version of Linux and has the $5  
> > Raspberry Pi Zero option now.
> > 
> > I'd love to hear of any progress on that front.
> 
> --  
> main(i,j){for(i=2;;i++){for(j=2;j\<i;j++){if(!(i%j)){j=0;break;}}if  
> (j){printf("%d\n",i);}}} /\*Dmitri Gribenko \<gribozavr@gmail.com\>\*/
