An Example of Scripting with Swift on Linux


Swift 3.0 Linux

If you follow us on Twitter (@iachievedit) you know that we build open source Swift a lot, and for a number of different OSes and architectures. There’s no rhyme or reason as to when we decide to start building, but it’s nice to keep track of the various git revisions of the repositories that went into a given artifact.

Since we’re excited about Swift eventually displacing other scripting languages on Linux (their names rhyme with Bython and Buby), it felt like a good time to write up a script (in Swift) that did this for us.

Some notes here:

  • we’re using a subscript extension of String that will likely never be a part of the core language for reasons.
  • exec is our version of backticks (output = `ls`) in other scripting languages. We want to execute a command and read its output.
  • there’s certainly more optimization and tightening that can be done.

With that out of the way, here is swiftrevs.swift:

We use this as follows:

# swift swiftrevs.swift

This, of course, is run in a directory that has all of the various repositories required to build Swift cloned. If you’re interested in learning how to build Swift for X86 or certain ARM devices, check out our package-swift repository. It not only contains swiftrevs.swift but also a handful of scripts aimed at making building Swift (along with the REPL, Foundation, and Swift Package Manager) nearly painless.

Leave a Reply

Your email address will not be published. Required fields are marked *