Creating an Arduino-like environment, but in Swift


(Rick M) #1

I’m not sure if this is the right category for this question; if not, please let me know which is better and I’ll move the topic over there.

I’d like to build a simple IDE for doing embedded development. To that end I want to link against Swift libraries for compilation and linking. I realize that the Swift runtime demands a lot from a processor and OS, and may not be suitable for Atmel-class MCUs (not to mention a lack of code generation), but should work well on larger ARM cores.

I’d like to find ways to restrict some language features (say, removing Dispatch Queues) as necessary to allow the resulting programs to fit in smaller processors or environments without threading. But I think most ARM cores can support threading and dispatch, so then it’s a question of trimming the standard library.

The result eventually has to be a “raw” binary, where the first compiled instruction is the first byte in the file. In the past when I tried to do this with clang it was surprisingly hard to get the linker to handle it. I don’t know if that’s easier today or not, but I’d like to resume these efforts with Swift in mind.

I’ll take care of providing a suitable runtime environment (ie OS) for these processors, so that’s not really my concern right now. But I do want to enable the end user to fill out a couple of methods (e.g. setup() and loop()), using a high-level abstraction of the available hardware that I will provide, and let them click a button that compiles everything, bundles it, downloads it to the target, and runs it.

Is there any sample code or documentation for invoking the Swift libraries (something akin to the Kaleidoscope example in llvm)? Thanks!


(Andy Frew) #2

Hello...adding bits and pieces will probably seem fine as long as you have the correct image of the code in your head. But as soon as something doesn't work as expected the mental image will be derailed and figuring out the problem becomes a nightmare - literally - late nights, too much coffee and no progress. More bits are added to try to monitor the progress through the code. And those bits themselves start to cause confusion.

one-stop pcb


(Joe Groff) #3

@carlos42421 has been doing work in this direction. You might look into his previous threads.


(Carl Peto) #4

Thanks for the mention @Joe_Groff... @JetForMe take a look over my threads to get some inspiration and ideas. The basic swift stdlib I put together is horribly hacky but might put you on the right road. I suspect you might end up doing some of the same work yourself. I really just wanted support for the absolute basics, Integers, Booleans, Pointers, Optionals... that sort of thing, so I made a uSwift.swift file and copied in the bits I needed. Because my interest is in targeting the AVR processor, I put in a lot of things you wouldn't want like hard coded 16 bit pointer types and the like but it should give you some insights into what you need. Hope it helps. Also check out "Swift for Arduino", see if it gives you some ideas! Cheers, Carl.


(Rick M) #5

Nice! Thanks for the pointers. I've put this particular project aside, but I still have plans for slightly larger processors (ARM devices with enough resources to use GCD), and still want to create a nice turn-key environment for developing in Swift for them. Maybe someday…