Additional Linux Distributions

@svanimpe installing clang and libicu-dev will result in installing all the same packages, and the new list is actually more accurate. I understand your concern that the new apt-get install command is longer in form, but it will actually install less packages. As mentioned above I share you desire to pair down this list further and see Swift distributed as a formal package in the upstream repositories

1 Like

@SusanCheng does your program need zlib-devel, or do you see Swift toolchain requiring it? I am aware many applications need it, but IIRC Swift itself does not.

PS, it may be a good idea to include zlib-devel, I am just wondering where you see the error.

Yes, my library requires zlib-devel. I got the missing header file error when I try to build with centos docker image.

I just added the zlib-devel to the build script to pass ci.

makes sense, the issue with including dependencies that are not strictly required by Swift itself is that its a slippery slope, this is especially true when building Docker images since we want to maintain them as small as possible

4 Likes

The latest nightly docker images now has git installed.

Swift is in the official Fedora/RH 8/CentOS repos. I've been working on making a formal Ubuntu package as well; I was sidetracked because of packaging issues with Fedora, but now that is taken care of I am picking up where I left off on Ubuntu.

11 Likes

This is fantastic news. Are you able you utilize the tarball from swift.org or do you build Swift yourself for Fedora/RH 8/CentOS

1 Like

Fedora has a requirement that everything be built from source, so it takes awhile to build the package. :slight_smile:

If you're interested, all the files I use to package Swift for Fedora/RH/CentOS are available here. The "Makefile" that drives creating the package is the spec file.

2 Likes

thanks for sharing this @Ron_Olson, very helpful. there are fews areas I think we could work towards:

  1. make sure we use the minimal set of dependencies to do the Swift build from source. you can find what we came up with in the new Docker area, e.g. https://github.com/apple/swift-docker/blob/master/swift-ci/master/centos/8/Dockerfile
  2. minimize the amount of patches you need to do on top of the source so it builds out-of-the box. @drexin done a bunch of changes to that end for the new distros, would be interesting to see what you still need to patch on-top to make Fedora/RH build and work together to eliminate that.
  3. have tests run and pass.
1 Like

Yep, I'm basing my Dockerfile on the CentOS one. The patches I use are a consequence of Fedora moving very aggressively to the latest-n-greatest kernels, packages, etc. which acts as a good bellwether of what is going to eventually come to all Linux distros and where possible I submit PRs (e.g. this one) but those typically come too late for the coming Swift release; while they're merged in master, I have to keep my patch around to the next release where I can remove it. Also in the case of building for Linux on the s390x architecture, I needed a patch that I didn't submit a PR for as I saw in master the code had been refactored completely.

Another area where Fedora is very aggressive is in the move to Python 3; I know @drexin, et al. have been moving aggressively in this area and it really shows in the nightly builds I do from master as well as the latest 5.3 snapshot, so I'm definitely looking forward to retiring all my Python 3 patches. :slight_smile:

2 Likes

In case you are interested: https://swift.apt.compnerd.org/apt is an apt repository which contains a dpkg from the hourly builds from master.

The build rules are at https://github.com/compnerd/swift-build and the builds occur at https://dev.azure.com/compnerd/swift-build/_build?definitionId=14.

6 Likes

Awesome! Thanks Saleem for the info!

Is there a place I can see the script that builds the tool chains? I guess it must be somewhere on the ci server, but I haven't figure out how to see that.

just opened a PR with this info. still needs to be reviewed, but potentially helpful: add guide for adding ci dockerfiles to support more distributions by tomerd · Pull Request #171 · apple/swift-docker · GitHub

1 Like

In addition to the slim images mentioned above which we publish for ubuntu (CentOS and Amazon Linux 2 dont need anything on top of the distro for running swift programs), another option that folks could find interesting is Google's distroless. I did a small experiment today:

FROM swiftlang/swift:nightly-bionic as build

# build a test application, real world examples would add the actual source instead
RUN mkdir /workspace
WORKDIR /workspace
RUN swift package init --name test --type executable
RUN echo "import Foundation\n \
\n \
let dateFormatter = DateFormatter()\n \
dateFormatter.dateFormat = \"yyyy-MM-dd HH:mm:ss Z\"\n \
dateFormatter.timeZone = TimeZone(abbreviation: \"PST\")\n \
\n \
print(\"Hello, world!\")\n \
print(\"The time is \(dateFormatter.string(from: Date()))\")\n \
" > Sources/test/main.swift
RUN swift build -c release

# copy executables and dependencies on top of the base image
FROM gcr.io/distroless/cc-debian10
COPY --from=build /workspace/.build/release /
COPY --from=build /usr/lib/swift/linux/lib*so* /

# set the entry point (application name)
CMD ["/test"]

and the results:

❯ docker build . -t swift-distroless-test
Sending build context to Docker daemon   2.56kB
...
Successfully built 101536fea410
Successfully tagged swift-distroless-test:latest

❯ docker run swift-distroless-test
Hello, world!
The time is 2020-05-09 14:21:36 -0700

Note the above this uses gcr.io/distroless/cc-debian10 as the runtime image which should work for Swift programs that do not use FoundationNetworking or FoundationXML. In order to provide a more complete support we (the community) could put in a PR into distroless to introduce a base image for Swift that includes libcurl and libxml which are required for FoundationNetworking or `FoundationXML respectively.

3 Likes

Thank you for the information, can any of you please reply to my query.

Can we use the script to install swift on linux? like: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

sudo echo "deb [ trusted=yes ] https://swift.apt.compnerd.org/apt /" > /etc/apt/sources.list.d/swift.list
sudo apt update
sudo apt install swift-toolchain

worked for me but swift fails with:

<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-linux-gnu'

Also I guess "swift package init" is not yet supported?

You might be interested in this: Introducing swiftbox 0.10 with CentOS(RHEL) and Amazon Linux support

regards,

Lars

Oh, the layout is similar to that on Windows, so you will need the -sdk flags.

I think that s-p-m builds are integrated into the packaging, help to add that is welcome :)