Need help building Swift on Debian server


I have been trying to build Swift on my Linux Debian server. The process seems to get through fine, despite the fact that two test are failing.

I have built the platform with the following command:

./utils/build-script -R --foundation

Now, how can I use it or install it locally (for example in /usr/local ?)

When I try to run Swift, it says this is the REPL intended for compiler and stdlib. Simply trying to use print fails:

/opt/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin# ./swift
***  You are running Swift's integrated REPL,  ***
***  intended for compiler and stdlib          ***
***  development and testing purposes only.    ***
***  The full REPL is built as part of LLDB.   ***
***  Type ':help' for assistance.              ***
(swift) print("Hello")
Stack dump:                                                                                                      0.      Program arguments: /opt/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift -frontend -repl -disable-objc-interop -color-diagnostics -module-name REPL 
1.      while processing REPL source:
Illegal instruction                                                                                              

Trying to compile a basic test file fails as well:

/opt/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64# bin/swiftc test.swift
/usr/bin/ fatal error: test: open: Is a directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Any idea what I am missing ?

To do a build and install without running the tests I use:
swift/utils/build-script --preset=buildbot_linux,no_test install_destdir=~/swift-install installable_package=~/swift.tgz

which will install it into ~/swift-install and also create a tar.gz of the installation.

To run the tests as well use --preset=buildbot_linux instead.

Note these 2 commands will use the same build directory but it will be different to the one used in your original command so the first time you run it there will be a full rebuild.

1 Like

Hello Simon,

It worked like a charm. Many thanks!

For the record, I had to install Swig 2.0 instead of the Swig 3.0 package with latest Debian version, and of course install the needed dependencies. After that, with your build command all went very well.

Thanks again :slight_smile:

That's surprising, because the build instructions say apt-get install swig is enough, and Ubuntu 16.04 comes with Swig 3. We build on Ubuntu 16.04 all the time don't we?

I find it surprising as well. I had a failure at the end, with a specific message saying that Swift (or LLDB ?) is not compliant with Swig 3.0.9 and 3.0.10.

I can reinstall Swig 3 and reproduce the exact message if you need to.

Note that I tried with Swig 2, because of this comment in the Swift README:

Note: LLDB currently requires at least swig-1.3.40 but will successfully build with version 2 shipped with Ubuntu.

Maybe using Swig 3.0.8 or 3.0.12 would be ok. I could try this as well.

OK, here's what I've found out:

ubuntu:14.04 - swig 2.0.11
ubuntu:16.04 - swig 3.0.8
ubuntu:18.04 - swig 3.0.12
debian:latest - swig 3.0.10

Testing done via docker run -it <image> /bin/bash; apt-get update && apt-get install -y swig && swig -version

As your error was "a specific message saying that Swift (or LLDB ?) is not compliant with Swig 3.0.9 and 3.0.10." I think that explains it?

Can you confirm that you are able to find a version of swig 3 that works on debian:latest?

Hello Ian,

Sure, let me experiment with it. I will report ASAP.

Thanks !

1 Like

Hello Ian,

So, I made some tests and I confirms that the issue is coming from the Swig version packaged with Debian, which makes LLBD unhappy.

Swig version packaged with Debian Stretch is 3.0.10. With this version, Swift build process fails on LLDB with the following error: “Swig versions 3.0.9 and 3.0.10 are incompatible with lldb.”

It seems that Swig API changed and broke LLDB in version 3.0.9 and 3.0.10 and that newer version offers workaround: lldb/lldb.swig at master · llvm-mirror/lldb · GitHub

As a result, the compilation is working fine with Swig 3.0.12 that is packaged with Ubuntu for example. I tried installing the .deb package from Ubuntu and I could successfully build Swift.

I will report this to Debian, hoping they will update Swig, as it will make the distribution more Swift friendly as default.

Thanks - I'm glad you solved the mystery. If Debian could ship Swig 3.0.12 that would be great.