
Swift on Raspberry Pi - ingve
https://blog.lickability.com/swift-on-raspberry-pi-e44c79fc32f3
======
ivl
I don't want to be negative about this article, but reading over it left me
with a little bit of disappointment.

I was hoping for an in depth dive into how Swift performed on a RPi compared
to other languages (say, C relative to Swift on x86, then the same for ARM),
and a little on how well Swift interacts with the Pi's hardware. But it was
just a quick guide on setting up a Pi, installing Swift, and making a quick
'Hello, World' program. The only lines of interest came at the very end:

> Now that Swift is installed, there’s so much more that you can do. To
> control hardware — like LEDs, motors, and relays — you can use the help of a
> library for hardware projects on Linux/ARM boards called SwiftyGPIO. Have
> fun experimenting with Swift on the Raspberry Pi!

That said, SwiftyGPIO looks like a fun little library that I think I'm going
to look into more and play around with.

~~~
elpakal
"In-depth" wasn't mentioned anywhere in the title though. The author also
defines hardware vs software... Clearly an introduction, and props to him for
trying.

------
oflannabhra
This is a decent guide, but if you are interested in Swift on ARM in general,
the crux is uraimo's Swift on ARM project [0], which is a huge resource for
the community.

[0] -
[https://github.com/uraimo/buildSwiftOnARM](https://github.com/uraimo/buildSwiftOnARM)

~~~
rvz
> ...but if you are interested in Swift on ARM in general...

I kind of was expecting this to be bare-metal Swift running on ARM with a
Raspberry Pi, when I read both the OP's title and your comment. But I was
disappointed to see that this was running on Linux. From the README.md...

> Scripts to clone, configure, patch and build Swift 5.0.2 on Linux ARM
> devices.

Hopefully in the future, Swift would support bare-metal environments just like
how Rust and Zig does.

~~~
erichocean
Bare metal is almost entirely unnecessary in 2019, because you can configure
Linux to only occupy one core for all of its processes and threads. The other
cores you can assign to your own apps and they will never be schedule off of
that core—zero context switching overhead.

And you can still SSH into your "bare metal" box, run gdb, etc. Best of both
worlds.

~~~
rvz
> Bare metal is almost entirely unnecessary in 2019, because you can configure
> Linux to only occupy one core for all of its processes and threads.

Configuring the Linux kernel just to meet the requirements for bare-metal
applications might work for some use-cases but not for security and safety-
critical applications.

For instance, the IoT industry still suffers from typical security issues in
the drivers and firmware due to these Linux/Busybox vulnerabilities in the
system. There are alternatives that use safer languages or formal verification
that are more secure than configuring Linux for IoT or bare metal development,
like TockOS [0] (using Rust) or seL4 microkernel (a formally verified
microkernel).

So, is bare metal almost entirely unnecessary in 2019? Security wise, I'd much
rather use safer languages like Rust for bare metal in 2019, than to use
Linux/Busybox for this use-case.

[0] - [https://www.tockos.org/](https://www.tockos.org/)

------
saagarjha
> We use apt by typing apt-get in the terminal

You can also use apt.

~~~
snazz
And the apt command is much nicer anyway, with a proper progress bar and a
unification of all the apt-* commands.

------
chadlavi
> The official programming language of Raspberry Pi is Python.

Huh? In what way exactly?

~~~
y4mi
There are some sources for that, like engaget for example.

There are also a few shortcuts on the desktop if you install it with the
gui... But yeah, it's ultimately a Debian deviate, so anyone with any
experience will be able to use it however he wants

> _Raspbian comes preloaded with Python, the official programming language of
> the Raspberry Pi and IDLE 3, a Python Integrated Development Environment._

~~~
chadlavi
I guess it was surprising to me because I don't know anyone who's ever used
their pi for python stuff. I mostly use them for networking, though.

------
valerij
> [apt] is kind of like the App Store for applications and packages on linux
> machines.

i died a little inside

~~~
beatgammit
Yup, but unfortunately, it's the most relatable way to explain it. Yes,
package managers were around long before any of these "app stores", but most
people are unaware of that fact. It's the main feature that attracted me to
Linux when I started using it, and the main pain point when trying to use
something else.

------
leshow
Is arm an officially supported compiler target or is this just someone's port
of swift to arm?

~~~
oscargrouch
Swift is built on top of LLVM, the same way C,C++ and Rust are. Also note that
the language was created by the original creator of LLVM.

So you can use any backend LLVM does.. theres a little runtime friction in
porting a small Swift runtime to the target (but you would only need to worry
about that, if its not a popular LLVM backend).

But given Apple is a first class consumer of Swift, arm is definetely a
strategic backend for Swift, given it needs to run on iOS.

(its a little alpha i guess, but you can even compile your Swift code to run
on WASM nowadays)

~~~
leshow
I don't think it's that simple. AVR was merged into LLVM, but I think you'd be
hard pressed to get either rust or swift running on it right now.

> So you can use any backend LLVM does.. theres a little runtime friction in
> porting a small Swift runtime to the target

More than a little friction, I would think.

I actually 'trust' the support if the language declares that they are going to
support it. For example, Rust has said they will support the wasm target as
first class.

------
rishav_sharan
But not on windows. Apple's prioritisation of compiler targets makes me sad.

~~~
beatgammit
It's a _lot_ easier to support Linux than Windows since it's so similar to
macOS, and they're already supporting ARM, so it really just comes down to OS
features they need to support. Windows is just so different from everything
else.

That being said, I'm sure it already works through WSL (Windows Subsystem for
Linux), so if Windows is your only platform, you can still probably play with
it.

