• Introducing Swift 3.0
  • Originally written by Joe
  • The Nuggets translation Project
  • Translator: joyking7
  • Proofread by CoderBOBO Shenxn

If you’re looking for an Ubuntu package for Swift 2.2, check out our bootstrap here.

Swift, 3.0

Swift 2.2 has been moved from the Master branch to swift-2.2. Since then, the Master branch of the repository has been used for version 3.0 development. The way Swift source code is fully cloned and compiled has changed a lot. Instead of cloning warehouse by warehouse, you can now do this:

mkdir swift-build
cd swift-build
git clone https://github.com/apple/swift.git 
./swift/utils/update-checkout --clone
Copy the code

The update-checkout script in the Swift repository helps you clone the repositories needed to compile swift code and package them into a.tar.gz zip file.

Using “Build and Package” as the default, we not only compiled all the target files we needed, but also packaged them into a.tar.gz zip file without any problems. To do this, use the package.sh script (available in the package-swift library) :

#! /bin/bash pushd `dirname $0` > /dev/null WHERE_I_AM=`pwd` popd > /dev/null INSTALL_DIR=${WHERE_I_AM}/install PACKAGE=${WHERE_I_AM}/swift.tar.gz LSB_RELEASE=`lsb_release -rs | tr -d .` rm -rf $INSTALL_DIR $PACKAGE ./swift/utils/build-script --preset=buildbot_linux_${LSB_RELEASE} install_destdir=${INSTALL_DIR} inCopy the code

The key thing in this script is to check for the Ubuntu version (lsb_release-rs) and use the buildbot_linux_${lsb_release} default to compile and PACKAGE everything into the ${PACKAGE}.tar.gz file.

apt-get

It’s a wise choice to download.tar.gz from Apple. It is better to use apt-get on Ubuntu distributions. To make compiling Swift code on Linux easier, we have provided you with an Ubuntu repository containing the latest Swift packages.

Currently we offer both swift-3.0 and Swift-2.2 packages, but they are not compatible. For example, both versions install Swift into the /usr/bin directory. We plan to install the two versions separately in different locations, but it may take until mid-2016 to fix this.

There are limitations and constraints, but let’s start by looking at how to install Swift 3.0!

1. Add a repository key

wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -
Copy the code

2. Add a specific repository tosources.list

Ubuntu 14.04

echo "deb http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list
Copy the code

Ubuntu 15.10

echo "deb http://iachievedit-repos.s3.amazonaws.com/ wily main" | sudo tee --append /etc/apt/sources.list
Copy the code

3. Runapt-get update

sudo apt-get update
Copy the code

4. Install swift – 3.0!

Apt - get the install swift - 3.0Copy the code

5. Give it a try

git clone https://github.com/apple/example-package-dealer
cd example-packager-dealer
swift build
Compiling Swift Module 'FisherYates' (1 sources)
Linking Library:  .build/debug/FisherYates.a
Compiling Swift Module 'PlayingCard' (3 sources)
Linking Library:  .build/debug/PlayingCard.a
Compiling Swift Module 'DeckOfPlayingCards' (1 sources)
Linking Library:  .build/debug/DeckOfPlayingCards.a
Compiling Swift Module 'Dealer' (1 sources)
Linking Executable:  .build/debug/Dealer
Copy the code

3.0 running Swift!

.build/debug/Dealer
Copy the code

FAQ

Q. Does Apple officially compile these binaries?

A. No, I compiled them on my personal server, which you can refer to here

Q. How to find the modified version of Git in a compilation project?

A. You can use the apt-cache show swift-3.0 command to check this information. Such as:

# apt-cache show swift-3.0 Package: swift-3.0 Status: install OK installed Priority: optional Section: development Installed-Size: 281773 Maintainer: iachievedit ([email protected]) Architecture: amd64 Version: 1:3. 0 0 ubuntu2 Depends: clang (& gt; = 3.6), libicu-dev Conflicts: swift-2.2 Description: Open Source Swift This is a packaged version of Open Source Swift 3.0 built from the following Git Revisions of the Apple Github repositories: Clang: c18bb21a04 LLVM: 0d07a5d3d5 Swift: 8aa4dadf92 Foundation: dc4fa2d80b Description-md5: 08508c39657c159d064917af87d8d411 Homepage: http://dev.iachieved.it/iachievedit/swiftCopy the code

The original tree is not affected each time it is compiled.

Q. Do you test binaries before uploading them?

A. Swift tests the resulting binaries when it compiles, and then I’ll do some basic tests and use it to compile my own application, but there are no comprehensive test cases at this time.

Q. Do you compile regularly on schedule?

A. Not really, although I’d like to try to keep up with Apple officials. My idea, however, was just to experiment so THAT I could write Swift on Linux.

Q. Where will all content be installed?

**A.** Everything will be placed in /usr, just like clang/GCC was installed.

Q. What is the meaning of package version numbers?

A. That’s what I had in mind from the very beginning. I think we need A proper package version number. Ubuntu2 ~trusty1 ubuntu2~trusty1

  • 3.0 refers to the packaged Swift version.
  • -0ubuntu2 indicates the second packaged version of Ubuntu. 0 indicates that there is no dependent Debian package on it.
  • ~trusty1 indicates that this package is intended for Trusty Tahr.

Wily’s package version number doesn’t include anything like ~ Wiley1, because it automatically updates swift-3.0 packages correctly after upgrading from Trusty to Wiley.

I think that’s right, but if you have other ideas, you can email [email protected].

How does it work?

I set up a Debian package repository on Amazon S3 with these great guides. I tried to set up a PPA distribution platform on top of it, but to be honest, it was a pain to deal with so much metadata just to release a simple Package. I knew it was necessary to set up a distribution warehouse, but I was overdoing it. But those who develop FPM have some suggestions for this as well.

Scripts that are packaged to compile content and upload to the repository can be found on Github. To learn Swift 3.0, see the SWIFt-3.0 branch.